Maxmenu JS API – hidePanel() closes mobile menu
-
I’ve added some javascript to inject a ‘close submenu’ button on all menu items for mobile. Those buttons have handlers that fire
hidePanel()
.Click works perfect. However, any keypress event hides the submenu *and* dismisses the whole mobile menu. Am I doing something wrong?
$(document).ready(function() { // mobile only if (Modernizr.mq('(max-width: 1129px)')) { // get all menu bar top-level links var $lis = $('#mega-menu-primary').children('li.mega-menu-item-has-children'); // this is the 'close submenu' button for accessibility var $closer = $('<a role="button" aria-label="close submenu" href="#" tabindex="0" class="close_submenu"><span aria-hidden="true">X</span></a>'); $lis.each(function() { var $li = $(this); var $a = $closer.clone(); // inject the 'close submenu' button $li.children('ul.mega-sub-menu').children('li').first().prepend($a); $a.off().on('click keydown', function(e) { if (e.type === 'click' || e.which == 13) { e.preventDefault(); e.stopPropagation(); // <- this doesn't help var $submenu = $li.children('a.mega-menu-link'); // on click event, this works perfectly. // on keydown:enter event, this hides the submenu AND dismisses the mobile menu, not what I want :( $('#mega-menu-primary').data('maxmegamenu').hidePanel($submenu, true); } }); }); } });
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Maxmenu JS API – hidePanel() closes mobile menu’ is closed to new replies.