I was asked to rig DHTML menu so that any open menu items would close when another menu item was opened, so that only one menu item can be open at a time. From what I have read, this is an option in the 6.x version, and I thought I would post my code here in case anyone wanted this facility in 5.x

I added the following to dhtml_menu.js, line 53, in the switchMenu function:


	var siblings = $(parent).parent().find('li.expanded');
	$(siblings).find('div.sub-expanded').animate({height: 'hide', opacity: 'hide'}, '500');
	$(siblings).find('div.sub-expanded').removeClass('sub-expanded').addClass('sub-collapsed');
	$(siblings).removeClass('expanded').addClass('collapsed');

I haven't done extensive testing, but it seems to work fine, so far.

CommentFileSizeAuthor
#4 343509.patch1.24 KBGold
#4 dhtml_menu_one_menu.js.txt3.21 KBGold
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fpedraza’s picture

That's exactly what I was trying to do. Wonderful.
Thank you!
It works perfectly for me with drupal 5.14.

davedg629’s picture

Can you show exactly where you put this code? That would help a lot because I put it in on line 53 and it didn't have any effect. I'm sure if I knew anything about javascript I could figure it out, but I don't.

fpedraza’s picture

if (Drupal.settings.dhtmlMenu.useEffects) {
      $(submenu).animate({height: 'show', opacity: 'show'}, '500');
        /**
         * http://drupal.org/node/343509 - leave only 1 menu open
         */
        var siblings = $(parent).parent().find('li.expanded');
        $(siblings).find('div.sub-expanded').animate({height: 'hide', opacity: 'hide'}, '500');
        $(siblings).find('div.sub-expanded').removeClass('sub-expanded').addClass('sub-collapsed');
        $(siblings).removeClass('expanded').addClass('collapsed');

This works only if you have effects ON.

Gold’s picture

Status: Active » Needs review
FileSize
3.21 KB
1.24 KB

This behavior is exactly what I've been looking for for a while now. L0rne, your JS skills are superior to mine. :) I'd pretty much given up on trying to get this to work.

I really need this functionality added to the module. The deployment environment we use uses subversion and we can only checkin modules from contrib.

To this end I've created a new JS file with this code included (attached) and added a checkbox to the Admin DHTML Menu form that allows the user to select it. The patch file will add this.

If people could review this it would be appreciated.

cburschka’s picture

Status: Needs review » Needs work

Please make this feature upward compatible with D6 by using the same system variable and/or providing an upgrade path that copies the variable over. People who upgrade their site from D5 to D6 will expect the option to remain enabled. :)

Also: All changes (including the ones to JS) must be provided in patch form. One patch file is preferable (use cvs diff -up to generate a patch from your local version against the CVS branch), but if you can't use CVS you can also diff each file separately.

vuil’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

I close the issue as Closed (outdated).