### Install MetisMenu with Bun Source: https://onokumus.github.io/metismenu/mm-docs.html Install MetisMenu using Bun for project dependency management. ```bash $ bun add metismenu ``` -------------------------------- ### Install MetisMenu with npm Source: https://onokumus.github.io/metismenu/index.html Use npm to install the MetisMenu package. This is a common method for managing project dependencies. ```bash npm install--save metismenu ``` -------------------------------- ### Install MetisMenu with Composer Source: https://onokumus.github.io/metismenu/index.html Install MetisMenu using Composer, a dependency manager for PHP. This is useful if your project integrates with PHP. ```bash composer require onokumus/metismenu:dev-master ``` -------------------------------- ### Install MetisMenu with Yarn Source: https://onokumus.github.io/metismenu/index.html Use Yarn to add MetisMenu to your project dependencies. Yarn is an alternative package manager to npm. ```bash yarn add metismenu ``` -------------------------------- ### Stop and Re-start MetisMenu Instance Source: https://onokumus.github.io/metismenu/mm-dispose.html Use the 'dispose' method to stop a MetisMenu instance. Re-initialize the menu to start it again. Ensure the DOM is ready before executing. ```javascript $(function() { $('#menu').metisMenu(); $('#stopMm').on('click', function (event) { $('#menu').metisMenu('dispose'); }); $('#startMm').on('click', function (event) { $('#menu').metisMenu(); }); }); ``` -------------------------------- ### Handle 'shown.metisMenu' Event Source: https://onokumus.github.io/metismenu/mm-event2.html Use this snippet to attach a listener for the 'shown.metisMenu' event. This event fires after a menu item is expanded. Ensure jQuery and MetisMenu are included before this script. The example scrolls to the menu after an item is shown. ```javascript ``` -------------------------------- ### Initialize MetisMenu with ESM/Bundler Source: https://onokumus.github.io/metismenu/mm-docs.html Import MetisMenu and jQuery (if needed) and initialize the plugin using modern JavaScript module bundlers like Vite or Webpack. ```javascript import $ from 'jquery'; import MetisMenu from 'metismenu'; // OR import { MetisMenu } from 'metismenu'; const mm = new MetisMenu("#metismenu"); // OR $("#metismenu").metisMenu(); ``` -------------------------------- ### Initialize MetisMenu with Custom Selectors Source: https://onokumus.github.io/metismenu/mm-faq.html Initialize MetisMenu on FAQ elements using custom selectors for toggle, trigger, parent trigger, and submenus. Ensure the DOM is ready before initialization. ```javascript $(function() { $('.faq-menu').metisMenu({ toggle: false, triggerElement: '.faq-link', parentTrigger: '.faq-item', subMenu: '.faq-answer' }); }); ``` -------------------------------- ### Load Menu Items with Ajax Source: https://onokumus.github.io/metismenu/mm-ajax.html Initializes MetisMenu and then uses an Ajax call to load menu items from 'demo-ajax.html'. After loading, it disposes of the old menu, appends the new content, and reinitializes MetisMenu. The button is disabled after the first click. ```javascript $('#menu').metisMenu(); $("#ajaxButton").one('click', function() { var $this = $(this); $.ajax({ url: "demo-ajax.html", success: function(result) { $('#menu').metisMenu('dispose'); $("#menu").append(result); $('#menu').metisMenu(); $this.attr('disabled', 'disabled'); } }); }); ``` -------------------------------- ### Initialize Folder View with MetisMenu Source: https://onokumus.github.io/metismenu/mm-folder.html Use this JavaScript snippet to initialize the MetisMenu plugin for a folder view. The `toggle: false` option prevents automatic opening of the first item on load. ```javascript ``` -------------------------------- ### Initialize MetisMenu with RTL Support Source: https://onokumus.github.io/metismenu/mm-vertical.html Apply MetisMenu to a vertical menu within an RTL-enabled body. Ensure the `dir="rtl"` attribute is set on the `
` tag. ```html ... ``` -------------------------------- ### Initialize MetisMenu with Auto Collapse Source: https://onokumus.github.io/metismenu/mm-vertical.html Use this snippet to initialize MetisMenu with default auto-collapse behavior for vertical menus. ```html ``` -------------------------------- ### Remove Element and Dispose MetisMenu Instance Source: https://onokumus.github.io/metismenu/mm-dispose.html This snippet demonstrates removing a specific menu item and then disposing of the MetisMenu instance. It also shows re-initializing the menu after element removal. Use 'one' for click events to ensure it only runs once. ```javascript $('#menu1').metisMenu(); $('#deleteElem').one('click', function (event) { $(this).removeClass('btn-danger') .addClass('btn-success') .html('Menu 1 removed') .attr('disabled', 'disabled'); $('#menu1').metisMenu('dispose'); $('#menu1 #removable').remove(); $('#menu1').metisMenu(); }); ``` -------------------------------- ### Include Animate.css Source: https://onokumus.github.io/metismenu/mm-animate.html Link the Animate.css stylesheet to enable animation effects. ```html ``` -------------------------------- ### Include MetisMenu Stylesheet Source: https://onokumus.github.io/metismenu/mm-docs.html Include the MetisMenu stylesheet in your HTML to apply the menu's styling. Use either the unpkg or npm CDN link. ```html ``` -------------------------------- ### Load Submenu Items with Ajax Source: https://onokumus.github.io/metismenu/mm-ajax.html Initializes MetisMenu for '#menu2' and then iterates through elements with a 'data-url' attribute. On click, it prevents the default action, fetches content via Ajax using the 'data-url', disposes of the current menu, appends the loaded content to the parent list item, and reinitializes MetisMenu. ```javascript $('#menu2').metisMenu(); $('[data-url]').each(function(){ $(this).one('click', function(event){ event.preventDefault(); var $this = $(this); var url = $this.attr('data-url'); console.log(url); $.ajax({ url: url, success: function(result) { $('#menu2').metisMenu('dispose'); $this.parent('li').append(result); $('#menu2').metisMenu(); $this.click(); } }); }); }); ``` -------------------------------- ### Initialize MetisMenu with No Collapse Source: https://onokumus.github.io/metismenu/mm-vertical.html Configure MetisMenu to prevent automatic collapsing of menu items by setting `toggle` to `false`. ```html ``` -------------------------------- ### Include MetisMenu Plugin Source: https://onokumus.github.io/metismenu/mm-docs.html Include the MetisMenu plugin's JavaScript file in your HTML. Use either the unpkg or npm CDN link. ```html ``` -------------------------------- ### Include jQuery Source: https://onokumus.github.io/metismenu/mm-docs.html Include the jQuery library before MetisMenu if you are not using a bundler. Use either the unpkg or npm CDN link. ```html ``` -------------------------------- ### Include MetisMenu Stylesheet Source: https://onokumus.github.io/metismenu/index.html Link the MetisMenu CSS file in your HTML to apply the plugin's styling. You can use a CDN or a local path. ```html ``` -------------------------------- ### Initialize Hoverable Vertical Menu Source: https://onokumus.github.io/metismenu/mm-vertical-hover.html Use this JavaScript snippet to initialize the MetisMenu plugin on an element with the ID 'menu1'. Ensure the DOM is ready before calling the function. ```javascript ``` -------------------------------- ### Initialize MetisMenu Source: https://onokumus.github.io/metismenu/index.html Call the metisMenu() jQuery plugin on your target unordered list to initialize the collapsible menu functionality. ```javascript $"#metismenu".metisMenu(); ``` -------------------------------- ### Handle MetisMenu Events Source: https://onokumus.github.io/metismenu/mm-event.html Attach event listeners to the MetisMenu instance to perform actions during show, shown, hide, and hidden states. Ensure the DOM is ready before initializing. ```javascript $(function() { $('#menu').metisMenu() .on('show.metisMenu', function(event) { // do something… }).on('shown.metisMenu', function(event) { // do something… }).on('hide.metisMenu', function(event) { // do something… }).on('hidden.metisMenu', function(event) { // do something… }); }); ``` -------------------------------- ### Include MetisMenu Plugin Source: https://onokumus.github.io/metismenu/index.html Add the MetisMenu JavaScript file to your project. Ensure it's included after jQuery. ```html ``` -------------------------------- ### MetisMenu Method: dispose Source: https://onokumus.github.io/metismenu/index.html Call the `dispose` method to stop and destroy the MetisMenu instance, removing its functionality and event listeners. ```javascript $("#metismenu").metisMenu('dispose'); ``` -------------------------------- ### MetisMenu Option: toggle Source: https://onokumus.github.io/metismenu/index.html Set the `toggle` option to `false` to disable the auto-collapse behavior, allowing multiple submenus to be open simultaneously. ```javascript $("#metismenu").metisMenu({ toggle: false }); ``` -------------------------------- ### Apply Animation Classes to UL Element Source: https://onokumus.github.io/metismenu/mm-animate.html Add 'animate__animated' and 'animate__bounce' classes to the UL element to apply a bounce animation. ```html