When collapsing a menu item, the cookie is set, but the cookie shows the last collapsed menu as still open ( display is block).

The cookie was being updated, it just kept saying the display:hidden was actually block when it shouldn't be.

Looks like the problem was that the block was still in the process of collapsing when the cookie was being set? (best guess)

I fixed it by adding a delay (setTimeOut) of 1 second in the javascript so it could give the menu a chance to fully close. Note this is hackinsh, but it should help solve the problem temporarily.

Note: I tried 10ms, 100ms, and 500ms, and they all still didn't work!

  setTimeout('Drupal.dhtmlMenu.saveMenuState()', 1000);

here is the whole function

/**
 *  Changes the state of a submenu from open to close.
 */
Drupal.dhtmlMenu.switchMenu = function(submenu, parent) {
  if($(parent).is('.expanded')) {
    if (Drupal.settings.dhtmlMenu.useEffects) {
      $(submenu).slideUp('fast');
    } else {
      $(submenu).css('display', 'none');
    }
    $(parent).removeClass('expanded').addClass('collapsed');
  } else {
    if (Drupal.settings.dhtmlMenu.useEffects) {
      $(submenu).slideDown('fast');
    } else {
      $(submenu).css('display', 'block');
    }
    $(parent).removeClass('collapsed').addClass('expanded');
  }
  setTimeout('Drupal.dhtmlMenu.saveMenuState()', 1000);
}

Comments

hedroom’s picture

It's interesting... I did not have this problem with 5.x-1.2. Your hack works well for me also.

Cheers,

Wade

jhm’s picture

I integrated that little hack in all of my sites which use dhtml_menu as well. Nicely done. Will try to figure out what caused this in the 1st place.

cburschka’s picture

Version: 5.x-1.3 » 6.x-2.x-dev
StatusFileSize
new1.6 KB

The problem is directly coupled to the slide effect. jQuery animation calls run parallel to the normal thread, so the rest of the commands get executed before the animation ends. Naturally, then, you can't rely on a value that is set at the end of the animation.

The problem occurs in all known versions of dhtml_menu, D6 and D5, if the slide effect is enabled. Thank you very, very much for identifying the problem; I've somehow been blind all this time.

Here's a fix for HEAD that doesn't rely on real time. Instead of waiting for the style.display to be set, the cookie saver should look for the collapsed/expanded class, which is added without animation and should therefore be in immediately.

I've tested it and found that it fixes the problem. It's a bit inelegant because it adds an extra class to the sub-menu rather than trying to traverse the DOM to the parent menu where the class is already set. But that's cosmetical, and the bug is critical.

cburschka’s picture

Version: 6.x-2.x-dev » 5.x-1.4
Status: Needs review » Patch (to be ported)

Committed. Will port to 5.x-1.x in a moment.

cburschka’s picture

Drat. The jQuery version used in Drupal 5 does not have hasClass(). I must work around this by using is().

cburschka’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.94 KB

Here we go. It works on my D5 site.

cburschka’s picture

Status: Needs review » Fixed

Committed to DRUPAL-5.

There will be an official release soon.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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