Heirachy Menu

[Total: 0    Average: 0/5]

If you are looking for a simple navigation system for your site then this is the answer.

Head Code:

<script type="text/javascript"><!-- 
// Author: Jim Chisholm 
// Email: jim_chis@hotmail.com 
// Notes: Email me if you like this script 
// I will add style sheeting to it soon 

// Enter your menu items here in the following format 
// [nodeId] | parentId | pageName | fileName 
// nodeId goes up in 10's so you can add a parent page easily in between 
// nodeId is optional, only add if it is a parent 
// Only use spaces in the Page name, no where else. This is important!! 
// This script currently only works when all pages are located in the same directory 

var NODE_ID = 0; 
var PARENT_ID = 1; 
var PAGE_NAME = 2; 
var FILE_NAME = 3; 

var aTree = new Array; 

var nodes = new Array(); 
var nCurrentNodeId; 
var sCurrentFileName; 
var nodeValues; 
var childValues; 

var nTreeId = -1; 

// *************** Only make modifications here ********************* 


aTree[++nTreeId] = "10|0|About Us|aboutus.htm"; 
aTree[++nTreeId] = "|10|Mission Statement|missionstatement.htm"; 
aTree[++nTreeId] = "|10|History|history.htm"; 
aTree[++nTreeId] = "|10|Prospectus-Philosophy|prospectus.htm"; 
aTree[++nTreeId] = "|10|Policy|policy.htm"; 
aTree[++nTreeId] = "|10|Facilites|facilites.htm"; 
aTree[++nTreeId] = "|10|Board Details|boarddetails.htm"; 
aTree[++nTreeId] = "|10|Our Community|ourcommunity.htm"; 

aTree[++nTreeId] = "20|0|Curriculum|curriculum.htm"; 

aTree[++nTreeId] = "30|0|Enrolments|enrolments.htm"; 

aTree[++nTreeId] = "40|0|Events & News|eventsnews.htm"; 
aTree[++nTreeId] = "|40|Excursions|excursions.htm"; 
aTree[++nTreeId] = "|40|Sports|sports.htm"; 
aTree[++nTreeId] = "|40|School Calendar|schoolcalendar.htm"; 
aTree[++nTreeId] = "|40|Principal|principal.htm"; 

aTree[++nTreeId] = "50|0|School classes|schoolclasses.htm"; 
aTree[++nTreeId] = "|50|P/I Prep year one|year1.htm"; 
aTree[++nTreeId] = "|50|Years 2,3,4|year234.htm"; 
aTree[++nTreeId] = "|50|Years 5,6,7|year567.htm"; 

aTree[++nTreeId] = "60|0|Our Sponsors|oursponsors.htm"; 

aTree[++nTreeId] = "70|0|Contact Us|contactus.htm"; 

aTree[++nTreeId] = "9999|0|Home|default.htm"; 


// ************************** End here ****************************** 


function w(sString) { 
document.write(sString); 
} 

function getFileName(sUrl) { 
var sPath, aPathElements, nLength; 
sPath = new String(sUrl); 
aPathElements = sPath.split("/"); 
nLength = aPathElements.length; 
return aPathElements[nLength-1].toLowerCase(); 
} 

function getTopNodeId() { 

var nNodeId; 
var nParentId; 
for (i=0; i<nodes.length; i++) { 
nodeValues = nodes[i].split("|"); 
if (nodeValues[FILE_NAME]==sCurrentFileName) { 
nParentId = nodeValues[PARENT_ID]; 
nNodeId = nodeValues[NODE_ID]; 
} 
} 
if (nParentId==0) { 
// page is parent, return node id 
return nNodeId; 
} 
else { 
// page is child 
for (i=0; i<nodes.length; i++) { 
nodeValues = nodes[i].split("|"); 
if (nodeValues[NODE_ID]==nParentId) { 
return nodeValues[NODE_ID]; 
} 
} 
} 
} 

// Create the tree 
function createTree(arrName,sPage) { 
nodes = arrName; 
sCurrentFileName = new String(sPage); 
nCurrentNodeId = getTopNodeId(); 

if (nodes.length > 0) { 
for (i=0; i<nodes.length; i++) { 
nodeValues = nodes[i].split("|"); 
if (nodeValues[PARENT_ID]==0) { 
w("<a href="" + nodeValues[FILE_NAME] + "" onmouseover="window.status='" + nodeValues[PAGE_NAME] + "';return true;" onmouseout="window.status=' ';return true;">" + nodeValues[PAGE_NAME] + "</a><br />"); 
if (nCurrentNodeId == nodeValues[NODE_ID]) { 
for (j=0; j<nodes.length; j++) { 
childValues = nodes[j].split("|"); 
if (childValues[PARENT_ID]==nCurrentNodeId) { 
w("&nbsp;&nbsp;&nbsp;&nbsp;"); 
w("<a href="" + childValues[FILE_NAME] + "" onmouseover="window.status='" + childValues[PAGE_NAME] + "';return true;" onmouseout="window.status=' ';return true;">" + childValues[PAGE_NAME] + "</a><br />"); 
} 
} 

} 
} 
} 
} 
} 

//--> 
</script> 

Body Code:

<script type="text/javascript"> 
<!-- 
createTree(aTree,getFileName(document.location)); 
//--> 
</script> 

Times Viewed: 9

Leave a Reply

Your email address will not be published. Required fields are marked *