vendor/assets/js/foundation.drilldown.js.es6 in foundation-rails-6.2.0.1 vs vendor/assets/js/foundation.drilldown.js.es6 in foundation-rails-6.2.1.0

- old
+ new

@@ -42,13 +42,13 @@ /** * Initializes the drilldown by creating jQuery collections of elements * @private */ _init() { - this.$submenuAnchors = this.$element.find('li.is-drilldown-submenu-parent'); - this.$submenus = this.$submenuAnchors.children('[data-submenu]'); - this.$menuItems = this.$element.find('li').not('.js-drilldown-back').attr('role', 'menuitem'); + this.$submenuAnchors = this.$element.find('li.is-drilldown-submenu-parent').children('a'); + this.$submenus = this.$submenuAnchors.parent('li').children('[data-submenu]'); + this.$menuItems = this.$element.find('li').not('.js-drilldown-back').attr('role', 'menuitem').find('a'); this._prepareMenu(); this._keyboardEvents(); } @@ -111,11 +111,11 @@ } // if(e.target !== e.currentTarget.firstElementChild){ // return false; // } - _this._show($elem); + _this._show($elem.parent('li')); if(_this.options.closeOnClick){ var $body = $('body').not(_this.$wrapper); $body.off('.zf.drilldown').on('click.zf.drilldown', function(e){ e.preventDefault(); @@ -130,61 +130,75 @@ * Adds keydown event listener to `li`'s in the menu. * @private */ _keyboardEvents() { var _this = this; - this.$menuItems.add(this.$element.find('.js-drilldown-back')).on('keydown.zf.drilldown', function(e){ + + this.$menuItems.add(this.$element.find('.js-drilldown-back > a')).on('keydown.zf.drilldown', function(e){ + var $element = $(this), - $elements = $element.parent('ul').children('li'), + $elements = $element.parent('li').parent('ul').children('li').children('a'), $prevElement, $nextElement; $elements.each(function(i) { if ($(this).is($element)) { $prevElement = $elements.eq(Math.max(0, i-1)); $nextElement = $elements.eq(Math.min(i+1, $elements.length-1)); return; } }); + Foundation.Keyboard.handleKey(e, 'Drilldown', { next: function() { if ($element.is(_this.$submenuAnchors)) { - _this._show($element); - $element.on(Foundation.transitionend($element), function(){ - $element.find('ul li').filter(_this.$menuItems).first().focus(); + _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(); } }, previous: function() { - _this._hide($element.parent('ul')); - $element.parent('ul').on(Foundation.transitionend($element), function(){ + _this._hide($element.parent('li').parent('ul')); + $element.parent('li').parent('ul').one(Foundation.transitionend($element), function(){ setTimeout(function() { - $element.parent('ul').parent('li').focus(); + $element.parent('li').parent('ul').parent('li').children('a').first().focus(); }, 1); }); + e.preventDefault(); }, up: function() { $prevElement.focus(); + e.preventDefault(); }, down: function() { $nextElement.focus(); + e.preventDefault(); }, close: function() { _this._back(); //_this.$menuItems.first().focus(); // focus to first element }, open: function() { if (!$element.is(_this.$menuItems)) { // not menu item means back button - _this._hide($element.parent('ul')); - setTimeout(function(){$element.parent('ul').parent('li').focus();}, 1); + _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); - setTimeout(function(){$element.find('ul li').filter(_this.$menuItems).first().focus();}, 1); + _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(); } }, handled: function() { - e.preventDefault(); e.stopImmediatePropagation(); } }); }); // end keyboardAccess } @@ -242,11 +256,11 @@ /** * Opens a submenu. * @function * @fires Drilldown#open - * @param {jQuery} $elem - the current element with a submenu to 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'); this.$element.trigger('open.zf.drilldown', [$elem]); @@ -254,11 +268,11 @@ /** * Hides a submenu * @function * @fires Drilldown#hide - * @param {jQuery} $elem - the current sub-menu to hide. + * @param {jQuery} $elem - the current sub-menu to hide, i.e. the `ul` tag. */ _hide($elem) { var _this = this; $elem.addClass('is-closing') .one(Foundation.transitionend($elem), function(){ @@ -317,11 +331,11 @@ /** * Markup used for JS generated back button. Prepended to submenu lists and deleted on `destroy` method, 'js-drilldown-back' class required. Remove the backslash (`\`) if copy and pasting. * @option * @example '<\li><\a>Back<\/a><\/li>' */ - backButton: '<li class="js-drilldown-back"><a>Back</a></li>', + backButton: '<li class="js-drilldown-back"><a tabindex="0">Back</a></li>', /** * Markup used to wrap drilldown menu. Use a class name for independent styling; the JS applied class: `is-drilldown` is required. Remove the backslash (`\`) if copy and pasting. * @option * @example '<\div class="is-drilldown"><\/div>' */ @@ -342,6 +356,6 @@ }; // Window exports Foundation.plugin(Drilldown, 'Drilldown'); -}(jQuery); +}(jQuery); \ No newline at end of file