From: Marius Olbertz Date: Wed, 16 Mar 2016 04:36:09 +0000 (+0100) Subject: Enable triggering of links within menu via keyboard. X-Git-Tag: v6.2.1~43^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80a8ebabe901a1d9921843e32187a2a3b57c65b0;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Enable triggering of links within menu via keyboard. --- diff --git a/js/foundation.accordionMenu.js b/js/foundation.accordionMenu.js index 513ff3e4f..39cc9fd9b 100644 --- a/js/foundation.accordionMenu.js +++ b/js/foundation.accordionMenu.js @@ -109,19 +109,19 @@ class AccordionMenu { $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)); + $prevElement = $elements.eq(Math.max(0, i-1)).find('a').first(); + $nextElement = $elements.eq(Math.min(i+1, $elements.length-1)).find('a').first(); if ($(this).children('[data-submenu]:visible').length) { // has open sub menu - $nextElement = $element.find('li:first-child'); + $nextElement = $element.find('li:first-child').find('a').first(); } if ($(this).is(':first-child')) { // is first element of sub menu - $prevElement = $element.parents('li').first(); + $prevElement = $element.parents('li').first().find('a').first(); } else if ($prevElement.children('[data-submenu]:visible').length) { // if previous element has open sub menu - $prevElement = $prevElement.find('li:last-child'); + $prevElement = $prevElement.find('li:last-child').find('a').first(); } if ($(this).is(':last-child')) { // is last element of sub menu - $nextElement = $element.parents('li').first().next('li'); + $nextElement = $element.parents('li').first().next('li').find('a').first(); } return; @@ -131,7 +131,7 @@ class AccordionMenu { open: function() { if ($target.is(':hidden')) { _this.down($target); - $target.find('li').first().focus(); + $target.find('li').first().find('a').first().focus(); } }, close: function() { @@ -139,14 +139,16 @@ class AccordionMenu { _this.up($target); } else if ($element.parent('[data-submenu]').length) { // close currently open sub _this.up($element.parent('[data-submenu]')); - $element.parents('li').first().focus(); + $element.parents('li').first().find('a').first().focus(); } }, up: function() { $prevElement.attr('tabindex', -1).focus(); + e.preventDefault(); }, down: function() { $nextElement.attr('tabindex', -1).focus(); + e.preventDefault(); }, toggle: function() { if ($element.children('[data-submenu]').length) { @@ -157,7 +159,6 @@ class AccordionMenu { _this.hideAll(); }, handled: function() { - e.preventDefault(); e.stopImmediatePropagation(); } });