View Full Version : SD Menu - Initial collapse vs persistence

12-17-2008, 08:17 PM
1) Script Title: Slashdot Menu

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex1/slashdot.htm

3) Describe problem:

I looked through the previous SD menu thread and saw some people address this issue, however it was on an earlier version of SD menu.

The issue is that I'd like to have the menu completely collapsed the first time someone visits the site (or deletes their cookies/cache). But once someone starts navigating the site they can have a submenu collapsed or expanded.

I currently have :

function SDMenu(id) {
if (!document.getElementById || !document.getElementsByTagName)
return false;
this.menu = document.getElementById(id);
this.submenus = this.menu.getElementsByTagName("div");
this.remember = true;
this.speed = 3;
this.markCurrent = true;
this.oneSmOnly = true;

Any help or links to a solution are much appreciated!

Also thanks for the great menu DimX!

12-17-2008, 10:43 PM
If it's not too much trouble, you could try one of these:
http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu.htm (http://www.dynamicdrive.com/dynamicindex17/ddaccordionmenu.htm)
Then, all you need to do to get the desired effect is to make sure these settings look like this: defaultexpanded: [] and persiststate: true which means all tabs are collapsed as a default when the browser session starts, but the states remain persistent during the session.

12-17-2008, 10:49 PM
In the code:

var firstSubmenu = myMenu.submenus[0];
myMenu.expandMenu(firstSubmenu); // Expand a submenu
myMenu.collapseMenu(firstSubmenu); // Collapse a menu
myMenu.toggleMenu(firstSubmenu); // Expand if collapsed and collapse if expanded

myMenu.expandAll(); // Expand all submenus
myMenu.collapseAll(); // Collapse all submenus

Either change the highlighted to your desired code or change that whole section to:

var myMenu = new SDMenu("main_menu"); // ID of the menu element
// Default values...
myMenu.speed = 3; // Menu sliding speed (1 - 5 recomended)
myMenu.remember = true; // Store menu states (expanded or collapsed) in cookie and restore later
myMenu.oneSmOnly = false; // One expanded submenu at a time
myMenu.markCurrent = true; // Mark current link / page (link.href == location.href)


myMenu.collapseAll(); // Collapse all submenus

Although that would have to go in the onload with myMenu.init()(the selected).