Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
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 .
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?).
Comments
Comment #1
SoTadmin commentedI 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
Comment #2
trofimchouk commentedMe too. Please provide a patch for this feature!
Comment #3
trofimchouk commentedFinally, 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 .
Comment #4
buddaChanging the module code:
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 :)
Comment #5
Ibn al-Hazardous commentedI 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
In the same file, change the function dhtmlMenu.switchMenu to call hideAllChildren by changing:
to
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?).
Comment #6
brmassa commentedGuys,
i just implemented this feature. Soon on next release (only for D6)
regards,
massa
Comment #7
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #8
8thom commentedthanks 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.