onokumus / metismenu

A collapsible jQuery menu plugin
https://onokumus.github.io/metismenu/
MIT License
1.96k stars 487 forks source link

Expand & Collapse All #75

Open softelos opened 8 years ago

softelos commented 8 years ago

I'm trying to add a button that expands or collapses all the first level <li> tags in the menu (I'm giving them class first to easily locate them). I can get the menu expanding and collapsing, however with the following issues:

Can you please check if I'm doing it properly? here is my code, where dashboard-sidebar-expand is the ID of the button that is pressed, dashboard-sidebar-menu is the menu ID, and the glyphicon thing is just to control the picture shown on the button:

$('#dashboard-sidebar-expand').on('click',function(){
    $(this).children('.glyphicon').toggleClass('glyphicon-resize-full glyphicon-resize-small');
    $('#dashboard-sidebar-menu li.first').toggleClass('active');
    $('#dashboard-sidebar-menu li.first ul:first').toggleClass('collapse');
});

Thanks.

jd19007 commented 8 years ago

I use this in my code for mine side menu I have and thought I would share this.

html -

jquery - $(document).ready(function() { $(".custom-search-form input[type=text]").keyup(function(e) { var valThis = $(this).val(); $("#side-menu a").each(function() { if($(this).html().search(new RegExp(valThis, 'ig')) < 0 && valThis.length > 0) { if($(this).parent('li').length > 0) { $(this).hide(); } else { $(this).hide(); } } else if(valThis.length > 0) { $(this).show().addClass('active').parent().parent().addClass('in').parent().children('a.active').show(); } else { $(this).show().removeClass('active').parent().parent().removeClass('in').parent(); } }); }); });

maybe will fix this