Posted by ldutson on June 12, 2007 at 11:36am
Jump to:
| Project: | DHTML Menu |
| Version: | 5.x-0.7 |
| Component: | Javascript code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | brmassa |
| Status: | closed (fixed) |
Issue Summary
Is there a way I can get menu items to collapse once other items are expanded?
Comments
#1
I agree. This is a very nice module. Plugged in and worked without a hitch. I'm using it as-is and loving the speed increase.
I can see where the option to have only one sub-menu open would add a lot of value. Or maybe a "collapse all" icon or menuitem.
Thanks for the work.
jackson
#2
Me too. Please provide a patch for this feature!
#3
Finally, I've the way to do it! You should do the following:
- edit your "dhtml_menu.module" file
- find string with "dhtml_menu.js" and replace it with "DEV-dhtml_menu.js"
- edit "DEV-dhtml_menu.js" and comment strings where "saveMenuState" function is invoked.
Actually there two such strings and the function definition itself.
That's all. Now previously expanded menus (except currently active) will collapse with new page opens.
The other way to do it is to edit "dhtml_menu.module" and replace:
if (menu_in_active_trail($mid) || ($type & MENU_EXPANDED) || in_array("sub$mid", $expanded)) {
with
if (menu_in_active_trail($mid) || ($type & MENU_EXPANDED)) {
Mmm.. I didn't check this, but I'm sure it will work the same way as ".js and .module" edition.
The last.... You might also try to encode "DEV-dhtml_menu.js" as it is done in module. I mean that "dhtml_menu.js" referenced in ".module" is the clone of "DEV-dhtml_menu.js" encoded in some way .
#4
Changing the module code:
if (menu_in_active_trail($mid) || ($type & MENU_EXPANDED) || in_array("sub$mid", $expanded)) {with
if (menu_in_active_trail($mid) || ($type & MENU_EXPANDED)) {
Fixed an issue I was having where navigating to any other page would auto open the dhtml sub menu without being clicked on. SO good fix :)
#5
I don't know if this is what was asked for originally, but I needed a feature to collapse open siblings when expanding a submenu. (I am corrupting dhtml_menu into a cascading menu with some css.)
As it turns out this was a pretty simple piece to program.
Add the following in DEV-dhtml_menu.js
/**
* Hide all submenus
*/
dhtmlMenu.hideAllChildren = function(parent) {
for (var i=0; i<parent.childNodes.length; ++i) {
if ($(parent.childNodes[i]).is(".expanded")){
$(parent.childNodes[i].getElementsByTagName("div")[0]).css("display","none");
$(parent.childNodes[i]).removeClass("expanded").addClass("collapsed");
}
}
};
In the same file, change the function dhtmlMenu.switchMenu to call hideAllChildren by changing:
else {if (Drupal.settings.dhtmlMenu.useEffects) {
to
else {dhtmlMenu.hideAllChildren(parent.parentNode);
if (Drupal.settings.dhtmlMenu.useEffects) {
And at last, change the call from dhtml_menu.js to DEV-dhtml_menu.js in dhtml_menu.module
If something like this is considered for inclusion - it would be cool to have a setting turning it on/off in the admin menu (perhaps on a per menu basis?).
#6
Guys,
i just implemented this feature. Soon on next release (only for D6)
regards,
massa
#7
Automatically closed -- issue fixed for two weeks with no activity.
#8
thanks for posting - this really helped me out.
Made simple change to the Hide all submenus function below so the children slide away too.
Just a little easier on the eyes.
/**
* Hide all submenus
*/
dhtmlMenu.hideAllChildren = function(parent) {
for (var i=0; i<parent.childNodes.length; ++i) {
if ($(parent.childNodes[i]).is(".expanded")){
$(parent.childNodes[i].getElementsByTagName("div")[0]).slideUp("fast", dhtmlMenu.saveMenuState);
$(parent.childNodes[i]).removeClass("expanded").addClass("collapsed");
}
}
};