API introduction

After the plugin has been fired, an API is available for the menu. With this API, you can trigger the plugin methods or bind new function to them. The API is stored in the "mmenu" data-attribute after the plugin is fired.

<script type="text/javascript">
   $(document).ready(function() {
      $("#my-menu").mmenu({
         // options
      });

      var api = $("#my-menu").data( "mmenu" );
      api.bind( "openPanel", function( $panel ) {
         console.log( "This panel is now opened:" + $panel.attr( "id" ) );
      });
      api.openPanel( $("#my-panel") );
   });
</script>

If you're looking for methods for an add-on, check the add-ons pages.

Trigger methods

Trigger the plugin methods to control the plugin manually.

Method( arguments ) Default value Datatype Description
closeAllPanels Trigger this method to close all opened panels and go back to the first panel.
closePanel Trigger this method to close a panel (only available if the "slidingSubmenus" option is set to false).
(
$panel jQuery object The panel to close.
)
getInstance Trigger this method to get the class instance for the menu.
initPanels Trigger this method to (re)initialize (a) newly added panel(s).
(
$panel jQuery object The panel to (re)initialize.
)
openPanel Trigger this method to open a panel.
(
$panel jQuery object The panel to open.
)
setSelected Trigger this method to set or unset a menu item as "selected".
(
$li jQuery object The menu item to set or unset as "selected"".
selected true Boolean Whether to set or unset the menu item as "selected".
)
update Trigger this method to update the appearance for the menu.

Note that -although included and turned on by default- the "offCanvas" and "scrollBugFix" add-ons have their own set of methods to trigger, documented on the add-ons pages.

Bind new functions

Bind a new function to the plugin methods with the bind method.

Method( arguments ) Default value Datatype Description
bind Trigger this method to bind a new function to the specified plugin method.
(
method String The method to bind the function to.
Possible values: "closeAllPanels", "closePanel", closingPanel, closedPanel, "initPanels", "openPanel", openingPanel, openedPanel, "setSelected", "update"
fn Function The function to bind to the method.
)

Note that -although included and turned on by default- the "offCanvas" and "scrollBugFix" add-ons have their own set of methods to bind new functions to, documented on the add-ons pages.