9

Using the jQuery mmenu plugin I need to call a JavaScript function after the menu has finished opening. I can't see from the API documentation how to do this using the plug-in API, so I'm thinking perhaps the only option is to observe the class name on the <html> element, which gains a class of mm-opened when the menu is opened. This feels a little 'hacky' though, so I wondered if anyone could see a way, within the bounds of the native API, to accomplish the required function call?

EDIT: Contrary to expectations the openPanel event doesn't fire when the menu is opened - it only fires when sub-menus are opened, so although this suggests it would do the job, it doesn't.

Many thanks.

Dan
  • 5,836
  • 22
  • 86
  • 140

3 Answers3

18

Got it (not documented!):

var api = $('#menu').data('mmenu');
api.bind('opened', function () {
    console.log('opened');
});
Dan
  • 5,836
  • 22
  • 86
  • 140
6

You may search for .trigger( on the source code: https://raw.githubusercontent.com/FrDH/jQuery.mmenu/master/dist/js/jquery.mmenu.min.js

You will find the following events:

  • init
  • update
  • setSelected
  • setPage
  • open
  • opening
  • opened
  • close
  • closing
  • closed
  • openPanel
  • openingPanel
  • openedPanel
  • closePanel
  • closingPanel
  • closedPanel

I believe those are it. Among them you can see the 'opened' and 'closed' events that will be useful for your case.

user3621841
  • 815
  • 2
  • 10
  • 18
3
var api = self.$el.data("mmenu");

api.bind('close:finish', function() {
   console.log('close');
});

api.bind('open:finish', function () {
   console.log('open');
});

Thanks to ChezFre

PM-Designs
  • 189
  • 2
  • 7