Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Callback event when jQuery 'mmenu' opened

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.

like image 931
Dan Avatar asked May 31 '15 16:05

Dan


3 Answers

Got it (not documented!):

var api = $('#menu').data('mmenu');
api.bind('opened', function () {
    console.log('opened');
});
like image 195
Dan Avatar answered Nov 17 '22 11:11

Dan


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.

like image 31
user3621841 Avatar answered Nov 17 '22 11:11

user3621841


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

like image 3
PM-Designs Avatar answered Nov 17 '22 11:11

PM-Designs