vendor/assets/js/foundation.drilldown.js.es6 in foundation-rails-6.2.3.0 vs vendor/assets/js/foundation.drilldown.js.es6 in foundation-rails-6.2.4.0
- old
+ new
@@ -69,11 +69,11 @@
var $link = $(this);
var $sub = $link.parent();
if(_this.options.parentLink){
$link.clone().prependTo($sub.children('[data-submenu]')).wrap('<li class="is-submenu-parent-item is-submenu-item is-drilldown-submenu-item" role="menu-item"></li>');
}
- $link.data('savedHref', $link.attr('href')).removeAttr('href');
+ $link.data('savedHref', $link.attr('href')).removeAttr('href').attr('tabindex', 0);
$link.children('[data-submenu]')
.attr({
'aria-hidden': true,
'tabindex': 0,
'role': 'menu'
@@ -186,17 +186,18 @@
$element.parent('li').parent('ul').one(Foundation.transitionend($element), function(){
setTimeout(function() {
$element.parent('li').parent('ul').parent('li').children('a').first().focus();
}, 1);
});
+ return true;
} else if ($element.is(_this.$submenuAnchors)) {
_this._show($element.parent('li'));
$element.parent('li').one(Foundation.transitionend($element), function(){
$element.parent('li').find('ul li a').filter(_this.$menuItems).first().focus();
});
+ return true;
}
- return true;
},
handled: function(preventDefault) {
if (preventDefault) {
e.preventDefault();
}
@@ -235,10 +236,16 @@
$elem.children('.js-drilldown-back')
.on('click.zf.drilldown', function(e){
e.stopImmediatePropagation();
// console.log('mouseup on back');
_this._hide($elem);
+
+ // If there is a parent submenu, call show
+ let parentSubMenu = $elem.parent('li').parent('ul').parent('li');
+ if (parentSubMenu.length) {
+ _this._show(parentSubMenu);
+ }
});
}
/**
* Adds event listener to menu items w/o submenus to close open menus on click.
@@ -262,11 +269,12 @@
* @function
* @fires Drilldown#open
* @param {jQuery} $elem - the current element with a submenu to open, i.e. the `li` tag.
*/
_show($elem) {
- $elem.children('[data-submenu]').addClass('is-active');
+ $elem.attr('aria-expanded', true);
+ $elem.children('[data-submenu]').addClass('is-active').attr('aria-hidden', false);
/**
* Fires when the submenu has opened.
* @event Drilldown#open
*/
this.$element.trigger('open.zf.drilldown', [$elem]);
@@ -278,11 +286,12 @@
* @fires Drilldown#hide
* @param {jQuery} $elem - the current sub-menu to hide, i.e. the `ul` tag.
*/
_hide($elem) {
var _this = this;
- $elem.addClass('is-closing')
+ $elem.parent('li').attr('aria-expanded', false);
+ $elem.attr('aria-hidden', true).addClass('is-closing')
.one(Foundation.transitionend($elem), function(){
$elem.removeClass('is-active is-closing');
$elem.blur();
});
/**
@@ -297,17 +306,19 @@
* Prevents content jumping.
* @function
* @private
*/
_getMaxDims() {
- var max = 0, result = {};
- this.$submenus.add(this.$element).each(function(){
- var numOfElems = $(this).children('li').length;
- max = numOfElems > max ? numOfElems : max;
+ var biggest = 0
+ var result = {};
+
+ this.$submenus.add(this.$element).each((i, elem) => {
+ var height = elem.getBoundingClientRect().height;
+ if (height > biggest) biggest = height;
});
- result['min-height'] = `${max * this.$menuItems[0].getBoundingClientRect().height}px`;
+ result['min-height'] = `${biggest}px`;
result['max-width'] = `${this.$element[0].getBoundingClientRect().width}px`;
return result;
}
@@ -325,9 +336,10 @@
this.$submenuAnchors.each(function() {
$(this).off('.zf.drilldown');
});
this.$element.find('a').each(function(){
var $link = $(this);
+ $link.removeAttr('tabindex');
if($link.data('savedHref')){
$link.attr('href', $link.data('savedHref')).removeData('savedHref');
}else{ return; }
});
Foundation.unregisterPlugin(this);