Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a callback or any other way to execute a function after the jQuery mmenu has plugin finished activation?

Tags:

jquery

mmenu

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!');
    });
});
like image 377
web-designed Avatar asked Oct 17 '13 12:10

web-designed


2 Answers

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.

like image 173
Hendrik Avatar answered Nov 21 '22 00:11

Hendrik


$('#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.

like image 35
cole Avatar answered Nov 20 '22 23:11

cole