vendor/assets/js/foundation.drilldown.js.es6 in foundation-rails-6.2.1.0 vs vendor/assets/js/foundation.drilldown.js.es6 in foundation-rails-6.2.3.0
- old
+ new
@@ -64,35 +64,35 @@
var _this = this;
// if(!this.options.holdOpen){
// this._menuLinkEvents();
// }
this.$submenuAnchors.each(function(){
- var $sub = $(this);
- var $link = $sub.find('a:first');
+ 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');
- $sub.children('[data-submenu]')
+ $link.children('[data-submenu]')
.attr({
'aria-hidden': true,
'tabindex': 0,
'role': 'menu'
});
- _this._events($sub);
+ _this._events($link);
});
this.$submenus.each(function(){
var $menu = $(this),
$back = $menu.find('.js-drilldown-back');
if(!$back.length){
$menu.prepend(_this.options.backButton);
}
_this._back($menu);
});
if(!this.$element.parent().hasClass('is-drilldown')){
- this.$wrapper = $(this.options.wrapper).addClass('is-drilldown').css(this._getMaxDims());
- this.$element.wrap(this.$wrapper);
+ this.$wrapper = $(this.options.wrapper).addClass('is-drilldown');
+ this.$wrapper = this.$element.wrap(this.$wrapper).parent().css(this._getMaxDims());
}
}
/**
* Adds event handlers to elements in the menu.
@@ -114,12 +114,13 @@
// return false;
// }
_this._show($elem.parent('li'));
if(_this.options.closeOnClick){
- var $body = $('body').not(_this.$wrapper);
+ var $body = $('body');
$body.off('.zf.drilldown').on('click.zf.drilldown', function(e){
+ if (e.target === _this.$element[0] || $.contains(_this.$element[0], e.target)) { return; }
e.preventDefault();
_this._hideAll();
$body.off('.zf.drilldown');
});
}
@@ -130,13 +131,13 @@
* Adds keydown event listener to `li`'s in the menu.
* @private
*/
_keyboardEvents() {
var _this = this;
-
+
this.$menuItems.add(this.$element.find('.js-drilldown-back > a')).on('keydown.zf.drilldown', function(e){
-
+
var $element = $(this),
$elements = $element.parent('li').parent('ul').children('li').children('a'),
$prevElement,
$nextElement;
@@ -153,29 +154,29 @@
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();
});
- e.preventDefault();
+ return true;
}
},
previous: function() {
_this._hide($element.parent('li').parent('ul'));
$element.parent('li').parent('ul').one(Foundation.transitionend($element), function(){
setTimeout(function() {
$element.parent('li').parent('ul').parent('li').children('a').first().focus();
}, 1);
});
- e.preventDefault();
+ return true;
},
up: function() {
$prevElement.focus();
- e.preventDefault();
+ return true;
},
down: function() {
$nextElement.focus();
- e.preventDefault();
+ return true;
},
close: function() {
_this._back();
//_this.$menuItems.first().focus(); // focus to first element
},
@@ -184,21 +185,23 @@
_this._hide($element.parent('li').parent('ul'));
$element.parent('li').parent('ul').one(Foundation.transitionend($element), function(){
setTimeout(function() {
$element.parent('li').parent('ul').parent('li').children('a').first().focus();
}, 1);
- });
- e.preventDefault();
+ });
} 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();
- });
- e.preventDefault();
+ });
}
+ return true;
},
- handled: function() {
+ handled: function(preventDefault) {
+ if (preventDefault) {
+ e.preventDefault();
+ }
e.stopImmediatePropagation();
}
});
}); // end keyboardAccess
}
@@ -260,11 +263,14 @@
* @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');
-
+ /**
+ * Fires when the submenu has opened.
+ * @event Drilldown#open
+ */
this.$element.trigger('open.zf.drilldown', [$elem]);
};
/**
* Hides a submenu
@@ -278,11 +284,11 @@
.one(Foundation.transitionend($elem), function(){
$elem.removeClass('is-active is-closing');
$elem.blur();
});
/**
- * Fires when the submenu is has closed.
+ * Fires when the submenu has closed.
* @event Drilldown#hide
*/
$elem.trigger('hide.zf.drilldown', [$elem]);
}
@@ -313,12 +319,14 @@
this._hideAll();
Foundation.Nest.Burn(this.$element, 'drilldown');
this.$element.unwrap()
.find('.js-drilldown-back, .is-submenu-parent-item').remove()
.end().find('.is-active, .is-closing, .is-drilldown-submenu').removeClass('is-active is-closing is-drilldown-submenu')
- .end().find('[data-submenu]').removeAttr('aria-hidden tabindex role')
- .off('.zf.drilldown').end().off('zf.drilldown');
+ .end().find('[data-submenu]').removeAttr('aria-hidden tabindex role');
+ this.$submenuAnchors.each(function() {
+ $(this).off('.zf.drilldown');
+ });
this.$element.find('a').each(function(){
var $link = $(this);
if($link.data('savedHref')){
$link.attr('href', $link.data('savedHref')).removeData('savedHref');
}else{ return; }
@@ -356,6 +364,6 @@
};
// Window exports
Foundation.plugin(Drilldown, 'Drilldown');
-}(jQuery);
\ No newline at end of file
+}(jQuery);