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);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | dhtml_menu-cookie-save-d5-272117-6.patch | 1.94 KB | cburschka |
| #3 | dhtml_menu-cookie-save-272117-3.patch | 1.6 KB | cburschka |
Comments
Comment #1
hedroom commentedIt's interesting... I did not have this problem with 5.x-1.2. Your hack works well for me also.
Cheers,
Wade
Comment #2
jhm commentedI 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.
Comment #3
cburschkaThe 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.
Comment #4
cburschkaCommitted. Will port to 5.x-1.x in a moment.
Comment #5
cburschkaDrat. The jQuery version used in Drupal 5 does not have hasClass(). I must work around this by using is().
Comment #6
cburschkaHere we go. It works on my D5 site.
Comment #7
cburschkaCommitted to DRUPAL-5.
There will be an official release soon.
Comment #8
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.