PDA

View Full Version : Simple Tree menu defaults to expanded state



outre2001
08-29-2006, 03:30 PM
Simple Tree Menu

http://www.dynamicdrive.com/dynamicindex1/navigate1.htm

Hello all,
hoping that someone have come across and already solved this problem.
Here's what I'm seeing: Simple Tree Menu ignores its default "all collapsed" settings or the rel="closed" and opens with its subtrees expanded. I can close a subtree manually, but that's not the behavior that I need.
I have not made any modifications to the code nor the css file. They are fresh from DD. And my test page has nothing else on it just the menu.
The same incorrect behavior occurs in FF1.5 and IE6.
Any insight would be much appreciated.

Here's my page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<script type="text/javascript" src="javascript/simpletreemenu.js">
/***********************************************
* Simple Tree Menu- &#169; Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>

<link rel="stylesheet" type="text/css" href="simpletree.css" />

</head>
<body>

<ul id="treemenu" class="treeview">
<li><a href="#">services</a>
<ul>
<li><a href="#">graphic</a></li>
<li><a href="#">web</a></li>
<li><a href="#">photography</a></li>
<li><a href="#">copywriting</a></li>
<li><a href="#">direct mail</a></li>
</ul>
</li>
<li><a href="#">portfolio</a></li>
<li><a href="#">contact us</a></li>
<li><a href="#">about t.a.</a></li>
</ul>

<script type="text/javascript">
//creates the tree menu
//ddtreemenu.createTree(treeid, enablepersist, opt_persist_in_days (default is 1))
ddtreemenu.createTree("treemenu", false);
</script>

</body>
</html>


P.S. Looking through the DD code I noticed that none of the lines are terminated with ';' I'm a relative beginner with Javascript but I thought that every statement must end with ';'. What am I missing? Thanks

jscheuer1
08-29-2006, 05:58 PM
The ; is optional in javascript, as long as it is obvious (usually due to a line break) where it would belong. However, I see what you mean about this script. Looks like it might be a bug, I will look into it more when I get a chance.

outre2001
08-30-2006, 12:49 AM
I needed to move on so here's a bandaid that works. Call the ddtreemenu.flatten (treeid, 'contract') function from the last line of the ddtreemenu.createTree function in the simpletreemenu.js like this:


ddtreemenu.createTree=function(treeid, enablepersist, persistdays){
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
...
ddtreemenu.dotask(window, function(){ddtreemenu.rememberstate(treeid, durationdays)}, "unload") //save opened UL indexes on body unload
}
ddtreemenu.flatten (treeid, 'contract')
}

I also changed the .treeview li.submenu ul style to display:block; in the css file. This has the advantage of making the menu javascript independent. If javascript is disabled the entire menu (including subtrees) will be displayed and will remain usable.
Cheers.