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|/index.php"; 
aTree[++nTreeId] = "|10|Mission Statement|/index.php"; 
aTree[++nTreeId] = "|10|History|/index.php"; 
aTree[++nTreeId] = "|10|Prospectus-Philosophy|/index.php"; 
aTree[++nTreeId] = "|10|Policy|/index.php"; 
aTree[++nTreeId] = "|10|Facilites|/index.php"; 
aTree[++nTreeId] = "|10|Board Details|/index.php"; 
aTree[++nTreeId] = "|10|Our Community|/index.php"; 

aTree[++nTreeId] = "20|0|Curriculum|/index.php"; 

aTree[++nTreeId] = "30|0|Enrolments|/index.php"; 

aTree[++nTreeId] = "40|0|Events & News|/index.php"; 
aTree[++nTreeId] = "|40|Excursions|/index.php"; 
aTree[++nTreeId] = "|40|Sports|/index.php"; 
aTree[++nTreeId] = "|40|School Calendar|/index.php"; 
aTree[++nTreeId] = "|40|Principal|/index.php"; 

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

aTree[++nTreeId] = "60|0|Our Sponsors|/index.php"; 

aTree[++nTreeId] = "70|0|Contact Us|/index.php"; 

aTree[++nTreeId] = "9999|0|Home|/index.php"; 


// ************************** 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("    "); 
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: 7

Leave a Reply

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