Full Toggle TreeMenu Magic

There are occasions when you would like the TMM system to automatically toggle the open submenu each time you click a menu button. This will assure that only one menu section is open at any time. This tweak will create a complete, full toggle for every section and level in the menu. When a link is clicked, all other open menu sections in the menu will be closed while keeping all of the parent sections of this link open.

This tweak is strictly to the JavaScript and will require no extra html markup or other modifications.

How to...

You can use this special JavaScript function, P7_TMfull().

Here's the function:

function P7_TMfull(tL){ //v1.1 by Project Seven Development(PVII)
var i,x,pp,pa,d,ha,s,tN,tA,c,k,j,pd,pc,m;
var tD=new Array(),tAA=new Array();
if(tL&&tL.parentNode){pp=tL.parentNode;while(pp){
if(pp.tagName&&pp.tagName=="DIV"){if(pp.id &&pp.id=="p7TMnav"){
break;}tD.push(pp);}pp=pp.parentNode;}}
d=document.getElementById("p7TMnav");tA=d.getElementsByTagName("A");
for(i=0;i<tA.length;i++){m=true;if(tA[i].onclick){
ag=tA[i].onclick.toString();if(ag&&ag.indexOf("P7_TMenu")>-1){
if(tA[i].parentNode && tA[i].parentNode.childNodes){
for(x=0;x<tD.length;x++){if(tA[i].parentNode==tD[x]){
m=false;break;}}if(m){tAA.push(tA[i]);}}}}}
for(i=0;i<tAA.length;i++){if(tAA[i].onclick){
ag=tAA[i].onclick.toString();if(ag&&ag.indexOf("P7_TMenu")>-1){
if(tAA[i].parentNode && tAA[i].parentNode.childNodes){
tN=tAA[i].parentNode.childNodes;for(x=0;x<tN.length;x++){
if(tN[x].tagName=="DIV"){s=tN[x].style.display;if(s=='block'){
P7_TMenu(tAA[i]);}}}}}}}
}

Here's how it works :

1. Copy and paste this new JavaScript function, P7_TMfull(), into your p7tmscript.js file, or use the complete JavaScript from this page source.

2. Next, we'll make a code tweak to the P7_TMenu() function:

-Add this right after the first line of the script:

P7_TMfull(b);

-the modified function should look like this:

function P7_TMenu(b,og) { //v2.5 by Project Seven Development(PVII)
var i,s,c,k,j,tN,hh;if(document.getElementById){
P7_TMfull(b);
if(b.parentNode && b.parentNode.childNodes){tN=b.parentNode.childNodes;}else{return;}
........
........

3. Save the JavaScript file.

That's It!

Now the menu system will toggle on every click to show one submenu section at a time.

 

Tree Menu Magic by PVII
imagine the possibilities