Giter VIP home page Giter VIP logo

metismenu's Introduction

metismenu NPM version NPM monthly downloads NPM total downloads

A collapsible jQuery menu plugin

This version does not support any version of IE browser.

Getting started

Install

Install with npm:

npm install --save metismenu

Install with yarn:

yarn add metismenu

Install with composer

composer require onokumus/metismenu:dev-master

Download

download

Usage

  1. Include metismenu StyleSheet
<link rel="stylesheet" href="https://unpkg.com/metismenu/dist/metisMenu.min.css">
<!-- OR -->  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/metismenu/dist/metisMenu.min.css">
  1. Include jQuery
<script src="https://unpkg.com/jquery"></script>
<!-- OR -->
<script src="https://cdn.jsdelivr.net/npm/jquery"></script>
  1. Include metisMenu plugin's code
<script src="https://unpkg.com/metismenu"></script>
<!-- OR -->
<script src="https://cdn.jsdelivr.net/npm/metismenu"></script>
  1. Add id attribute to unordered list
<ul id="metismenu">

</ul>
  1. Make expand/collapse controls accessible

Be sure to add aria-expanded to the element a. This attribute explicitly defines the current state of the collapsible element to screen readers and similar assistive technologies. If the collapsible element is closed by default, it should have a value of aria-expanded="false". If you've set the collapsible element's parent li element to be open by default using the mm-active class, set aria-expanded="true" on the control instead. The plugin will automatically toggle this attribute based on whether or not the collapsible element has been opened or closed.

<ul id="metismenu">
  <li class="mm-active">
    <a href="#" aria-expanded="true">Menu 1</a>
    <ul>
    ...
    </ul>
  </li>
  <li>
    <a href="#" aria-expanded="false">Menu 2</a>
    <ul>
    ...
    </ul>
  </li>
  ...
  </ul>
  1. Arrow Options

add has-arrow class to a element

<ul id="metismenu">
<li class="mm-active">
  <a class="has-arrow" href="#" aria-expanded="true">Menu 1</a>
  <ul>
  ...
  </ul>
</li>
<li>
  <a class="has-arrow" href="#" aria-expanded="false">Menu 2</a>
  <ul>
  ...
  </ul>
</li>
...
</ul>
  1. Call the plugin:
  $("#metismenu").metisMenu();

Stopping list opening on certain elements

Setting aria-disabled="true" in the <a> element as shown will stop metisMenu opening the menu for that particular list. This can be changed dynamically and will be obeyed correctly:

<a href="#" aria-expanded="false" aria-disabled="true">List 1</a>

toggle

Type: Boolean Default: true

For auto collapse support.

 $("#metismenu").metisMenu({
   toggle: false
 });

dispose

Type: String Default: null

For stop and destroy metisMenu.

 $("#metismenu").metisMenu('dispose');

preventDefault

Type: Boolean Default: true

Prevents or allows dropdowns' onclick events after expanding/collapsing.

 $("#menu").metisMenu({
   preventDefault: false
 });

since from version 2.7.0

triggerElement

Type: jQuery selector Default: a

 $("#metismenu").metisMenu({
   triggerElement: '.nav-link' // bootstrap 5
 });

parentTrigger

Type: jQuery selector Default: li

 $("#metismenu").metisMenu({
   parentTrigger: '.nav-item' // bootstrap 5
 });

subMenu

Type: jQuery selector Default: ul

 $("#metismenu").metisMenu({
   subMenu: '.nav.flex-column' // bootstrap 5
 });

Events

Event Type Description
show.metisMenu This event fires immediately when the _show instance method is called.
shown.metisMenu This event is fired when a collapse ul element has been made visible to the user (will wait for CSS transitions to complete).
hide.metisMenu This event is fired immediately when the _hide method has been called.
hidden.metisMenu This event is fired when a collapse ul element has been hidden from the user (will wait for CSS transitions to complete).

Migrating to v3 from v2

  • Update metisMenu.js & metisMenu.css files
  • Change active class to mm-active

Demo

http://mm.onokumus.com

Contains a simple HTML file to demonstrate metisMenu plugin.

About

Related projects

Contributors

Contributor
onokumus
diegozhu
sinabs
DrugoLebowski
BurkovBA
arthurtalkgoal
mrdziuban
nicolasigot
PeterDaveHello
kalidema
AndrewEastwood
rgnevashev
719media
chriswiggins
jmagnusson
LukasDrgon
Cediddi
WoMayr
capynet

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for advice on opening issues, pull requests, and coding standards.

Release History

DATE VERSION CHANGES
2021-05-16 v3.0.7 sass support
2020-03-22 v3.0.6 fix security vulnerabilities
2019-12-28 v3.0.5 Fix dispose to be similar to init (adding event) #184
2019-03-07 v3.0.4 fix
2018-10-05 v3.0.3 fix
2018-10-05 v3.0.2 fix
2018-10-05 v3.0.1 fix
2018-10-05 v3.0.0 more functionally
2018-10-05 v2.7.9.1 Fix dispose option #173
2018-06-28 v2.7.9 Make jquery a peer dependency
2018-06-14 v2.7.8 remove aria-expanded attribute & remove transitionend check
2018-02-14 v2.7.4 jQuery -> $ in src/metisMenu.js to fix import. #158
2018-02-14 v2.7.3 window might not be defined in node.js environment #156
2017-12-31 v2.7.2 isolate against bootstrap changes, remove old legacy ie9 code #154
2017-10-30 v2.7.1 added check in complete()-callback to break when menu was disposed #150
2017-03-08 v2.7.0 fixed has-arrow class border color & added new 3 options
2017-02-23 v2.6.3 fixed #129
2017-02-02 v2.6.2 doubleTapToGo option is deprecated
2016-12-06 v2.6.1 fix require.js
2016-11-29 v2.6.0 dispose support
2016-05-06 v2.5.2 fix Menu failed to remove collapsing class
2016-05-06 v2.5.1 fixed bootstrap conflict
2016-03-31 v2.5.0 Event support
2016-03-11 v2.4.3 create meteor package
2016-03-04 v2.4.2 back to version 2.4.0
2016-03-03 v2.4.1 Transition element passed to methods (removed)
2016-01-25 v2.4.0 Support AMD / Node / CommonJS
2016-01-08 v2.3.0 Adding aria-disabled=true to the link element prevents the dropdown from opening
2015-09-27 v2.2.0 Events supported & added preventDefault options
2015-08-06 v2.1.0 RTL & aria-expanded attribute & TypeScript type definitions support
2015-07-25 v2.0.3 When the active item has doubleTapToGo should not collapse
2015-05-23 v2.0.2 fixed
2015-05-22 v2.0.1 changeable classname support
2015-04-03 v2.0.0 Remove Bootstrap dependency
2015-03-24 v1.1.3 composer support
2014-11-01 v1.1.3 Bootstrap 3.3.0
2014-07-07 v1.1.0 Add double tap functionality
2014-06-24 v1.0.3 cdnjs support & rename plugin
2014-06-18 v1.0.3 Create grunt task
2014-06-10 v1.0.2 Fixed for IE8 & IE9

Author

Osman Nuri Okumus

License

Copyright © 2021, Osman Nuri Okumus. Released under the MIT License.

metismenu's People

Contributors

719media avatar andreweastwood avatar arthurtalkgoal avatar burkovba avatar capynet avatar cediddi avatar chriswiggins avatar cuwomayr avatar dependabot[bot] avatar diegozhu avatar drugolebowski avatar jacobsvante avatar kalidema avatar leomeurer avatar lukasdrgon avatar mrdziuban avatar nicolasigot avatar onokumus avatar peterdavehello avatar rgnevashev avatar sbtpanja avatar sinabs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

metismenu's Issues

Demo code pulls old version from CDN

The index.html demo pulls:

"//cdn.jsdelivr.net/bootstrap.metismenu/1.1.0/js/metismenu.min.js"

i.e. not the latest version of metismenu.min.js.

Steve

expand

Hi,

When the menu is open and one of the sub menu has a href set to another page. Is it possible to once navigated to keep this menu open. I tried with jquery cookie but it is not working properly see below code :

        var menuCookie = $.cookie('cookie_collapse');
        $(".nav-second-level li a").click(function (e) {
            menuCookie = $.cookie('cookie_collapse', $(e.target).attr('id'));
            console.log(menuCookie);
            e.stopPropagation();
        });

        console.log(menuCookie);
        if (menuCookie) {
            $('#' + menuCookie).parent().parent().parent().addClass('active');
        }

Improvement: Active class for child item

Hi,

I think an active class should be added for menu item selected (child item).
This is also confusing because in your code the active class is for open state instead of active (selected).
bug #33
I was looking for that because I want to add the active class to the selected sub-item.

Parent 1
------ Child A
-------Child B (selected/clicked)
-------Child C

IE8 Collapse Issue

I was having an issue with this plugin working in IE8. Clicking a menu item once would do nothing but the second time would toggle the collapse. I corrected the issue by modifying the Plugin.prototype function to the below.

$this.find('li.active').has('ul').children('ul').collapse('show');
$this.find('li').not('.active').has('ul').children('ul').collapse('hide');

Bower.json: main

I think the 'main' property in bower.json should have a value of "dist/metisMenu.js" rather than "metisMenu.js". As it is currently, build tools will not find any metisMenu.js in the root directory...

Plugin not work

Hi,
This plugin is great, but not work at all.
Not work your demos: if i extract all zip folder and lunch /test/ files like hover.html, metisFolder.html and others. All CSS is broken and no js functionality.
2015-05-24_145213

If i try to use in my website (with bootstrap 100% included and work good). same results...

Why this happen? in true seem a your error in create download package.
Thanks

Menu items are not clickable?

Hello Onokumus

I was wondering if you could help me with a code change please?
I recently implemented your metismenu here: http://bit.ly/1hus0IV
The items on the menu that are marked in blue e.g. "Adult Costumes" or "Childrens Costumes"
I need them to be clickable. They are meant to go to a page on the website.

At the moment the link is somehow turned off.

How do I change this?

Thanks very much.

Cheers

ie8/9 issue

Collapse issue, same like #7 but its not working

if you open it on Internet Explorer you have to open -> close -> open to view the child menu.

Even the repo demo is not working on IE

Minimum jquery version for using metis menu.

Will the metis menu work with jquery 1..3.1.Earlier i was using version 2.1.1 and it was working properly.I have to use version 1.3.1 because my organization has strict restriction to use this version.Please help me with this scenario.

Multi-level keep menu open

Hello,

With the current version only the first sub-level (

    ) keeps open when the page reload.

    I need the menu to keep the same behavior for the next sub-level (

      ). The class is set to active for the .

      Is this possible by modifying the js ?

Open level of active only?

Is it possible to leave the selected menu open after click? It is possible to change the script on the end page to leave the selected menu open after click?

Closed menu (at start)

Country 1
Country 2
Country 3


Opened menu after click on Country 2

Country 1
Country 2
--Region 1 > Click on this item
--Region 2
--Region 3
Country 3


Country 1
Country 2 This level should be opened
--Region 1 > This item should be active
--Region 2
--Region 3
Country 3

Adding items to menu

I am building a backbone client app that adds one or more

  • items after fetching data from an API asynchronously. It does not seem to be possible to make metis menu work for
  • items that are added at a later stage. I can call $('#side-menu').metisMenu() a second time but it won't pick up the new items.

  • while doesn't loop

    I found this structure twice in the code. Looks like a flow control issue

      while (
                div.innerHTML = "<!--[if gt IE " + (++v) + "]><i></i><![endif]-->",
                all[0]
            ) {
                return v > 4 ? v : undef;
            }
    

    Suggestion for changing the .active class name

    Just a suggestion: maybe the .active class name should be changed to .open: IMHO, the .active class name should be used only for the list item bound to current page opened
    Anyway, metisMenu is a GREAT job: thank you!

    Suggestion to make the .arrow class name more specific

    I'm trying to implement the intl-tel-input plugin and there is a conflict with metisMenu regarding the .arrow class.

    The issue is that while intl-tel-input specifies the selector as specific:
    .intl-tel-input .selected-flag .arrow {

    metisMenu has a broad selector that captures everything, including other elements:
    .arrow {

    This results in some important styles being overwritten and forces me to reset the defaults on my app's CSS.

    Is it possible to refactor the stylesheet for metisMenu to be more specific as to isolate the effect it has on other controls in the same application?

    Bootstrap in depedency

    I'm using it with inventive ui so I don't need bootstrap in bower components though it still download that.

    Its possible to use your product without bootstrap so you can include general version and bootstrap version.

    There should not be dependency in package itself when it can easily be replaced with generic.

    This way you can reach all audiences not specific ones.

    metisMenu.d.ts

    Haven't looked into how hard it would be, might be nice to make a Typescript d.ts file for this.

    toggle doesn't work when no sub-menu is present

    Hi, I found out that toggle doesn't work right with items that don't have sub-menus.

    For example:

    <ul id="menu">
        <li><a href="#/page1">Page 1</a>
            <ul>
                <li><a href="#/sub-page1">Sub-page </a></li>
                <li><a href="#/sub-page2">Sub-page 2</a></li>
            </ul>
        </li>
        <li><a href="#/page2">Page 2</a></li>
    </ul>

    The problem is line 37 in the code:

    $this.find("li").has("ul").children("a").on("click" + "." + pluginName, function(e) ...

    Everything works fine when I remove .has("ul") from the code.

    The thing is I'm working with angular and not using direct links but routing based on my location, so even when the link doesn't have a sub-menu, it still doesn't go to a new page but should toggle the other menus.

    Cheers,
    Jan Fucik

    Dependency on bootstrap

    Why did you add dependency on bootstrap in version 1.1.2?

    The problem is there are 2 version of bootstrap: bootstrap and bootstrap-sass. And now it's hard to use metisMenu with the second one because it require to install unnecessary bootstrap.

    Can we do anything with this?

    Thank you for your work on metisMenu ❤️!

    Highlight active leaf item

    I'd like to highlight the current "clicked" (active) link at the leaf level, how can I do that?

    Currently, the "active" css class is added only to the items which are menu or sub-menu, but I'd like to
    add an active status to the "ul ul ul a"

    I added this css code:

    .sidebar-nav ul ul ul a:hover,
    .sidebar-nav ul ul ul a:focus,
    .sidebar-nav ul ul ul a:active {
    background-color: rgba(0, 0, 255, 0.15);
    background-color: rgba(0, 0, 255, 0.15);
    }

    the leaf are highlighted on mouse over, but when the link is clicked the doesn't remain highlighted!

    2nd click goto page

    How to do when user clicks on second time on the parent it should navigate to page directly?

    More levels

    Is there a way that I can add more levels to the menu,. I see only

    Root

    • level 1
      -- level 2
      --- level 3
      ---- level 4 (how can i do this?)

    I would like to add a level 4

    Thanks again for amazing work

    Animations duplicate on Safari browser

    metisMenu works great on every browser I have tested it on, except for Safari. I have tested on both OS X Mavericks and Yosemite with the same outcome.

    When clicking on a menu category, the expanding animation occurs twice in a row. After the first animation, it resets and does it a second time.

    focus on and open toggle menu

    Hello,

    I want to focus on and open toggle menu item.
    I mean for example if I click on first level nav I want to show a page and to open the accordion menu to see the second level nav. Right now it's only possible to open the accordion menu.
    Is that possible?

    delegate events

    hi,

    I am trying to use the menu with angular, and the html does not exist when the plugin is called in de document ready.

    when you apply the events you use:
    $this.find("li").has("ul").children("a").on("click", function(e) {

    this requires the html markup exist, and creates one event for every link, i have change in my local version for some thing like
    $this.on( "click", "a", function( e ) {

    this change creates only one event.

    i don´t know if this change is usefull.

    p.d. if you want to try witdh angular this is my aproach

    the html
    <li class="active" ng-repeat='item in items'>
    <a href="#"><i class="fa {{item.icon}} fa-fw"></i> {{item.title}}<span class="{{item.arrow}}"></span></a>
    <ul class="nav nav-second-level">
    <li class="active" ng-repeat='itemLv2 in item.childsLv2'>
    <a href="#"><i class="fa {{itemLv2.icon}} fa-fw"></i>{{itemLv2.title}}<span class="{{item.arrow}}"></span></a>
    <ul class="nav nav-third-level">
    <li ng-repeat='itemLv3 in itemLv2.childsLv3'>
    <a href="#"><i class="fa {{itemLv3.icon}} fa-fw"></i> {{itemLv3.title}}</a>
    </li>
    </ul>
    <!-- /.nav-third-level -->
    </li>
    </ul>
    <!-- /.nav-second-level -->
    </li>

    the js
    var app = angular.module('consolas', [ 'ngRoute' ]);
    function SideBarController($scope) {
    $scope.items = [ {
    title : 'JASOP Bundlor',
    page : 'index',
    icon : 'fa-sitemap',
    arrow: 'fa arrow',
    childsLv2 : [ {
    title : 'Transaction Processing',
    page : 'transactionLogic',
    icon : 'fa-dashboard',
    arrow: 'fa arrow',
    childsLv3 : [ {
    title : 'Transaction logic',
    page : 'transactionLogic',
    icon : 'fa-table'
    }, {
    title : 'Transaction config',
    page : 'transactionConfig',
    icon : 'fa-table'
    } ]
    }, {
    title : 'Online Applications',
    page : 'onlineApplications',
    icon : 'fa-dashboard'
    } ]
    }, {
    title : ' JASOP Online',
    page : 'index',
    icon : 'fa-sitemap',
    arrow: 'fa arrow',
    childsLv2 : [ {
    title : 'OSGI',
    page : 'bundles',
    icon : 'fa-dashboard',
    arrow: 'fa arrow',
    childsLv3 : [ {
    title : 'Bundles',
    page : 'bundles',
    icon : 'fa-table'
    }, {
    title : 'Configuration',
    page : 'configuration',
    icon : 'fa-wrench'
    }, {
    title : 'Log service',
    page : 'logService',
    icon : 'fa-edit'
    }, {
    title : 'Services',
    page : 'services',
    icon : 'fa-table'
    } ]
    }, {
    title : 'Memory Usage',
    page : 'memoryUsage',
    icon : 'fa-bar-chart-o'
    }, {
    title : 'System information',
    page : 'systemInformation',
    icon : 'fa-edit'
    }, {
    title : 'Licenses',
    page : 'licenses',
    icon : 'fa-files-o'
    }
    ]
    }
    ];
    }

    thanks

    URL recognition isn't quite magic enough

    I'm trying to use metisMenu on our admin area. When I go to the URL /admin/reports/monthly_sales/, all three listed below are highlighted in the menu. As the admin area is namespaced, all the URLs start with /admin/, therefore visiting any URL will highlight the root admin link.

    /admin/reports/monthly_sales
    /admin/reports
    /admin
    

    I don't know if it's related, but any option at the third level is collapsed, rather than remaining expanded as it should.

    Tag for version 1.1.0

    Versión 1.1.0 don't have tag. This is a little problem for bower users, that want use it.

    Disable

    How to disable a item of list? Disabling means preventing to expand the item. Adding the .disabled of bootstrap causes the visual effect but still can be expanded.

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. 📊📈🎉

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google ❤️ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.