"); top.MenuFrame.document.close(); window.status = 'WebBrancher Hierarchial Menu - (C) Colin Tucker - http://farrer.riv.csu.edu.au/~ctucker/webbrancher'; } function drawNode(node) { var imageSequence = node.imageSequence; writeImageSequence(node,imageSequence); top.MenuFrame.document.write("�") if (node.type == 'root') {nodeName = '' + node.name + ''} else {nodeName = node.name} if (node.target == '') {var nodeTarget = 'PageFrame'} else {nodeTarget = node.target} top.MenuFrame.document.writeln("" + nodeName + "
") } function writeImageSequence(node,sequence) { var finished = false; var lengthOfString = sequence.length; var imageSeq = sequence; while (finished == false) { if (imageSeq == '') {finished = true} else { imageString = stringUpToBar(imageSeq); if (imageString.length == imageSeq.length) {imageSeq = ''} else {imageSeq = imageSeq.substring(imageString.length + 1,imageSeq.length);} if ((imageString == 'img-plus-cont.gif') || (imageString == 'img-plus-end.gif')) { nodeIdent = "'" + node.id + "'" top.MenuFrame.document.write("")} else {if ((imageString == 'img-minus-cont.gif') || (imageString == 'img-minus-end.gif')) { nodeIdent = "'" + node.id + "'" top.MenuFrame.document.write("")} else {top.MenuFrame.document.write("")}} } } } function stringUpToBar(string) { var lengthOfString = string.length; var currentIndex = 0; var newString = ''; var finished = false; while (finished == false) { if (currentIndex == lengthOfString) {finished = true} else { if (string.charAt(currentIndex) == '|') {finished = true} else {newString = newString + string.charAt(currentIndex)} currentIndex = currentIndex + 1 } if (currentIndex == lengthOfString) {finished = true} } return newString } // addStringToStart() function - adds the addition string to the front of the existing string function addStringToStart(existingString,addition) { newString = addition + existingString; return newString } // createParentalStructure() function - creates a string that shows the parental tree structure function createParentalStructure(treeVariable,nodeID) { var parentAppearance = ''; var parentID = treeVariable.itemWithID(nodeID).parentID; var currentNode = treeVariable.itemWithID(parentID); while (parentID != 'root') { var nodePos = currentNode.position; parentID = currentNode.parentID; currentNode = treeVariable.itemWithID(parentID); var lengthOfBranch = extractChildren(treeVariable,currentNode).length; if (nodePos < lengthOfBranch) {parentAppearance = addStringToStart(parentAppearance,'img-vert-line.gif|')} else {parentAppearance = addStringToStart(parentAppearance,'img-blank.gif|')} } return parentAppearance } // extractExpandableNodes() - METHOD of obj_collection - extracts the root and all folder nodes // into a new collection function extractExpandableNodes() { var newCollection = new obj_collection(); var collectionSize = this.length; var currentIndex = 1; var currentArray = this; while (currentIndex <= collectionSize) { if ((currentArray[currentIndex].type == 'folder') || (currentArray[currentIndex].type == 'root')) { newCollection = newCollection.addItem(currentArray[currentIndex]) } currentIndex = currentIndex + 1 } return newCollection } // ADDITEM function - METHOD of OBJ_COLLECTION - adds an object to the collection function addItem(object) { collectionSize = this.length; returnArray = this; idExists = returnArray.itemIDExists(object.id) if (idExists == false) {returnArray.length = collectionSize + 1; returnArray[returnArray.length] = object; return returnArray} else {alert("ERROR: Object with id: " + object.id + " already exists in this collection.") return returnArray} } function countChildrenOf(treeVariable,nodeID) { var node = treeVariable.itemWithID(nodeID); var nodeChildren = extractChildren(treeVariable,node); var currentIndex = 1; while (currentIndex <= nodeChildren.length) { if (nodeChildren[currentIndex].type != 'page') {countChildrenOf(treeVariable,nodeChildren[currentIndex].id)} childCount = childCount + 1; currentIndex = currentIndex + 1; } } function posOfItemWithID(id) { collectionSize = this.length; currentIndex = 1; returnIndex = 'undefined'; while (currentIndex <= collectionSize) { if (this[currentIndex].id == id) {returnIndex = currentIndex} currentIndex = currentIndex + 1} if (returnObject == 'undefined') {alert("ERROR: Object with id: " + id + " not found in this collection.")} else {return returnIndex} } // ITEMWITHID function - METHOD of OBJ_COLLECTION and OBJ_ARRAY - returns an object with the given ID function itemWithID(id) { collectionSize = this.length; currentIndex = 1; returnObject = 'undefined'; while (currentIndex <= collectionSize) { if (this[currentIndex].id == id) {returnObject = this[currentIndex]} currentIndex = currentIndex + 1} if (returnObject == 'undefined') {alert("ERROR: Object with id: " + id + " not found in this collection.")} else {return returnObject} } // ITEMIDEXISTS function - METHOD of OBJ_COLLECTION and OBJ_ARRAY - checks if an object with the given ID // already exists in the collection function itemIDExists(id) { collectionSize = this.length; currentIndex = 1; returnStatus = false; while (currentIndex <= collectionSize) { if ((this[currentIndex].id) == id) {returnStatus = true} currentIndex = currentIndex + 1} return returnStatus } // definitionsHaveErrors function - general function - checks the defined menu infrastructure // for errors. function definitionsHaveErrors(treeVariable) { hasErrors = false if (checkForMultipleRoots(treeVariable) == true) {hasErrors = true} if (checkNodeTypes(treeVariable) == true) {hasErrors = true} if (checkForOrphanNodes(treeVariable) == true) {hasErrors = true} if (checkForChildren(treeVariable) == true) {hasErrors = true} if (checkNodePositions(treeVariable) == true) {hasErrors = true} return hasErrors } // checkNodeTypes function - called from definitionsHaveErrors() function // - checks for nodes with unknown types function checkNodeTypes(treeVariable) { collectionSize = treeVariable.length; var currentIndex = 1; var returnStatus = false; while (currentIndex <= collectionSize) { if ((treeVariable[currentIndex].type != 'root') && (treeVariable[currentIndex].type != 'page') && (treeVariable[currentIndex].type != 'folder') ) { alert("Node with ID: " + treeVariable[currentIndex].id + " is of an unknown type: " + treeVariable[currentIndex].type + " (not a page, folder or root).") } currentIndex = currentIndex + 1; } return returnStatus } // checkForMultipleRoots function - called from definitionsHaveErrors() function // - checks if the menu infrastructure has multiple root nodes function checkForMultipleRoots(treeVariable) { collectionSize = treeVariable.length; currentIndex = 1; rootCount = 0; while (currentIndex <= collectionSize) { if ((treeVariable[currentIndex].type) == 'root') {rootCount = rootCount + 1} currentIndex = currentIndex + 1} if (rootCount == 1) {return false} else {if (rootCount == 0) {alert("ERROR: You have not defined a root node.")} else {alert("ERROR: You have defined more than one root node.")} return true} } // checkForOrphanNodes() function - called from definitionsHaveErrors() function // - checks if the menu infrastructure contains any nodes without defined parents function checkForOrphanNodes(treeVariable) { collectionSize = treeVariable.length; var currentIndex = 1; var returnStatus = false; while (currentIndex <= collectionSize) { if ((treeVariable[currentIndex].type) != 'root') {if (((treeVariable.itemIDExists(treeVariable[currentIndex].parentID)) == false) && (treeVariable[currentIndex].parentID != '')) {returnStatus = true; alert("ERROR: The parent node: " + treeVariable[currentIndex].parentID + " does not exist for node: " + treeVariable[currentIndex].id + ".")} if (treeVariable[currentIndex].parentID == '') {returnStatus = true; alert("ERROR: Node with ID: " + treeVariable[currentIndex].id + " has no parent, and is not the root node.")} if (treeVariable.itemWithID(treeVariable[currentIndex].parentID).type == 'page') {returnStatus = true; alert("ERROR: Node with ID: " + treeVariable[currentIndex].id + " has a parent (" + treeVariable[currentIndex].parentID + "), but this parent is a page (should be a folder or the root).")} } currentIndex = currentIndex + 1} return returnStatus } // checkForChildren() function - called from definitionsHaveErrors() function // - checks that all nodes (except pages) in the menu infrastructure have at least one child function checkForChildren(treeVariable) { collectionSize = treeVariable.length; var currentIndex = 1; var returnStatus = false; while (currentIndex <= collectionSize) { if ((treeVariable[currentIndex].type) != 'page') { if (checkParentID(treeVariable,treeVariable[currentIndex].id) == false) {returnStatus = true; alert("ERROR: Node with ID: " + treeVariable[currentIndex].id + " is a root node or a folder node (or an node of unknown type) without any defined children. The root node and any folder nodes MUST have at least one child node.")} } currentIndex = currentIndex + 1 } return returnStatus } // checkParentID() function - checks the given tree for nodes with the given parent ID function checkParentID(treeVariable,parentCode) { collectionSize = treeVariable.length; var currentIndex = 1; var returnStatus = false; while (currentIndex <= collectionSize) { if ((treeVariable[currentIndex].parentID) == parentCode) {returnStatus = true} currentIndex = currentIndex + 1 } return returnStatus } // checkNodePositions() function - checks the tree infrastructure for node positioning errors function checkNodePositions(treeVariable) { // 1. Make a collection of all folders and the root node expandableNodes = treeVariable.extractExpandableNodes() // 2. For each node in this collection, make a collection of all the nodes that // are children of that node. var currentIndex = 1; var collectionSize = expandableNodes.length; var returnStatus = false; while (currentIndex <= collectionSize) { var scanCollection = extractChildren(treeVariable,expandableNodes[currentIndex]); if (scanPositionErrors(scanCollection,expandableNodes[currentIndex].id) == true) {returnStatus = true} currentIndex = currentIndex + 1 } return returnStatus } // scanPositionErrors() function - scans the given collection of children for positioning errors function scanPositionErrors(scanCollection,idOfParent) { var returnStatus = false; var currentIndex = 1; var collectionSize = scanCollection.length; // Check for nodes with positions less than 1 while (currentIndex <= collectionSize) { if (scanCollection[currentIndex].position < 1) {returnStatus = true; alert("ERROR: Node with ID: " + scanCollection[currentIndex].id + " with parent: " + scanCollection[currentIndex].parentID + " has a illegal position value (less than 1).")} currentIndex = currentIndex + 1 } currentIndex = 1 while (currentIndex <= collectionSize) { if (scanCollection[currentIndex].position > collectionSize) {returnStatus = true; alert("ERROR: Node with ID: " + scanCollection[currentIndex].id + " with parent: " + scanCollection[currentIndex].parentID + " has a illegal position value (greater than branch maximum of " + collectionSize + " positions).")} currentIndex = currentIndex + 1 } var loopNo = 1; while (loopNo <= collectionSize) { var currentIndex = 1; var positionFound = false; while (currentIndex <= collectionSize) { if (scanCollection[currentIndex].position == loopNo) {positionFound = true} currentIndex = currentIndex + 1 } if (positionFound == false) {returnStatus = true; alert("ERROR: There is no node at position " + loopNo + " in branch " + idOfParent + ". Two or more nodes may have the same position value.")} loopNo = loopNo + 1 } currentIndex = 1 return returnStatus } function extractChildren(treeVariable,node) { var newCollection = new obj_collection(); var currentIndex = 1; var collectionSize = treeVariable.length; nodeID = node.id; while (currentIndex <= collectionSize) { if ((treeVariable[currentIndex].parentID) == nodeID) { newCollection = newCollection.addItem(treeVariable[currentIndex]) } currentIndex = currentIndex + 1 } return newCollection } function extractAndSortChildren(treeVariable,node) { var childCollection = extractChildren(treeVariable,node); var newCollection = new obj_collection(); var lengthOfCollection = childCollection.length; var currentIndex = 1; while (currentIndex <= lengthOfCollection) { var newNode = extractNodeWithPosition(childCollection,currentIndex) newCollection = newCollection.addItem(newNode) currentIndex = currentIndex + 1 } return newCollection } function extractNodeWithPosition(collection,position) { var currentIndex = 1; var lengthOfCollection = collection.length; while (currentIndex <= lengthOfCollection) { if (collection[currentIndex].position == position) {var node = collection[currentIndex]} currentIndex = currentIndex + 1 } return node } // DEFINEMENUITEMS function - general function - called from start of script to create the menu // infrastructure. // // FORMAT: uniqueID,displayName,parentID,typeOfNode,URL,altImage,positionInTree,targetFrame function defineMenuItems(treeVariable) { treeVariable = treeVariable.addItem(new obj_node('root','WebBrancher','','root','index1.html','',0,'')); treeVariable = treeVariable.addItem(new obj_node('page-001','MSnet','root','page','http://msnet.home.ml.org/','',1,'')); treeVariable = treeVariable.addItem(new obj_node('fold-001','Emus/Roms','root','folder','emu.html','',2,'')); treeVariable = treeVariable.addItem(new obj_node('page-002','contra','fold-001','page','contra.nes','',1,'')); treeVariable = treeVariable.addItem(new obj_node('page-003','RBI Baseball','fold-001','page','rbi1.nes','',2,'_top')); } // -->