6

I'm firing the plugin on click.

$('#activate_mmenu').on('click', function(){
    $('#menu').mmenu();
});

is there a way to bind another function after the plugin has been activated?

something like this:

$('#activate_mmenu').on('click', function(){
    $('#menu').mmenu(function(){
        alert('plugin is activated!');
    });
});
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199

2 Answers2

1

Mmenu triggers it's own events

$("#nav")
   .mmenu()
   .trigger( "mmenu-created" )
);

more information is available here: http://mmenu.frebsite.nl/events.php

Edit: Had removed the wrong part of the code. You can trigger an event right after the mmenu initialisation.

Hendrik
  • 576
  • 6
  • 10
  • This would trigger the alert when the menu opened. If I understand the question correct, it should be triggered right after the plugin was fired. – Fred Oct 22 '13 at 12:12
  • Sorry, I seem to have taken out the wrong code part: See the page for a solution but also take into account, that this is version 4 of the library that is not that stable anymore, in my opinion. – Hendrik Oct 22 '13 at 14:59
  • I can't see any reference to a 'menu-created' event in the docs. Still unclear from you answer how to do this. – Brighty May 02 '14 at 10:38
1
$('#activate_mmenu').on('click', function(){
    $("#menu")
        .mmenu()
        .on('init', function(){
            console.log('init');
        })
        .trigger( "init" );
});

The documentation doesn't say a ton about custom events, but I got this to work. Then trigger it. As a result, you can simulate callbacks on initialization.

At first I created the custom event and bound it to the .mm namespace as recommended in the docs, but that doesn't appear to be necessary.

cole
  • 21
  • 3