If a menu is set to open on click only, then a click anywhere outside the open menu should close it. The same behavior as an OS menu.

This is the jQuery I'm using, for the "no-style" version:


(function ($) {
Drupal.behaviors.omMaximenuClose = {
attach: function (context, settings) {
$('html').click(function() {
// Close any open menus.
$('.om-maximenu-content:visible').each(function() {
$(this).hide();
});
});

// Allow opening closed menu.
$('.om-link').click(function(ev) {
ev.stopPropagation();
});

// Don't close an open menu if the click is inside it.
$('.om-maximenu-content').click(function(ev) {
ev.stopPropagation();
});
}
}
})(jQuery);

Comments

danielhonrade’s picture

Status: Active » Closed (fixed)

commit in dev, with some modifications...

johnpitcairn’s picture

Latest dev is not quite right. A click anywhere inside the dropdown content will close it. I still need to add this to the behaviour attach function:

// Don't close an open menu if the click is inside it.
$('.om-maximenu-content').click(function(ev) {
  ev.stopPropagation();
});
danielhonrade’s picture

Thanks John for looking into this, committed on dev.