Is there a way I can get menu items to collapse once other items are expanded?

Comments

SoTadmin’s picture

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

trofimchouk’s picture

Me too. Please provide a patch for this feature!

trofimchouk’s picture

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 .

budda’s picture

Category: support » bug

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 :)

Ibn al-Hazardous’s picture

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?).

brmassa’s picture

Assigned: Unassigned » brmassa
Status: Active » Fixed

Guys,

i just implemented this feature. Soon on next release (only for D6)

regards,

massa

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

8thom’s picture

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");
    }
  }
};