PDA

View Full Version : Modification of simple tree menu



superbb78
02-10-2011, 10:32 AM
Hi there,
Question about Simple Tree Menu
http://www.dynamicdrive.com/dynamicindex1/navigate1.htm
The tutorial shows separated expand or contract buttons to control the menu.
I'd like to know if I wanna expand a Folder, but contract other expanded folders, how can I make it?
Thanks in advance!:)

vwphillips
02-10-2011, 04:36 PM
modify function


ddtreemenu.buildSubTree=function(treeid, ulelement, index){
ulelement.parentNode.className="submenu"
if (typeof persisteduls[treeid]=="object"){ //if cookie exists (persisteduls[treeid] is an array versus "" string)
if (ddtreemenu.searcharray(persisteduls[treeid], index)){
ulelement.setAttribute("rel", "open")
ulelement.style.display="block"
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
else {
ulelement.setAttribute("rel", "closed")
}
} //end cookie persist code
else if (ulelement.getAttribute("rel")==null || ulelement.getAttribute("rel")==false){ //if no cookie and UL has NO rel attribute explicted added by user
ulelement.setAttribute("rel", "closed")
}
else if (ulelement.getAttribute("rel")=="open"){ //else if no cookie and this UL has an explicit rel value of "open"
ddtreemenu.expandSubTree(treeid, ulelement) //expand this UL plus all parent ULs (so the most inner UL is revealed!)
}
ulelement.parentNode.onclick=function(e){
var submenu=this.getElementsByTagName("ul")[0]
if (submenu.getAttribute("rel")=="closed"){
submenu.style.display="block"
submenu.setAttribute("rel", "open")
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
ddtreemenu.closelast(submenu);
}
else if (submenu.getAttribute("rel")=="open"){
submenu.style.display="none"
submenu.setAttribute("rel", "closed")
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.closefolder+")"
}
ddtreemenu.preventpropagate(e)
}
ulelement.onclick=function(e){
ddtreemenu.preventpropagate(e)
}
}


add new function


ddtreemenu.closelast=function(submenu){
var obj=submenu,myl=0;
while (obj.parentNode){
obj=obj.parentNode;
if (obj.className=='treeview'){
break;
}
myl++;
}
var uls=obj.getElementsByTagName('UL'),ary=[];
for (var level,ul,z0=0;z0<uls.length;z0++){
level=-2;
ul=uls[z0];
while (ul.parentNode){
level++;
if (ul.className=='treeview'){
break;
}
ul=ul.parentNode;
}
ary.push(level);
}
for (var z1=0;z1<uls.length;z1++){
if (uls[z1]!=submenu&&ary[z1]>=myl){
uls[z1].style.display="none";
uls[z1].setAttribute("rel", "closed");
uls[z1].parentNode.style.backgroundImage="url("+ddtreemenu.closefolder+")";
}
}
}

superbb78
02-11-2011, 08:15 AM
:D Thank you very much!