📄 sectree.js
字号:
nodeTarget = node.target
}
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);
}
switch(imageString)
{
case 'img-plus-cont.gif':
nodeIdent = "'" + node.id + "'"
top.MenuFrame.document.write("<A HREF=javascript:top.expandNode(" + nodeIdent + ")><IMG SRC='" + imageDirectory + "/" + imageString + "' ALIGN=TEXTTOP BORDER=0></A>")
break
case 'img-plus-end.gif':
nodeIdent = "'" + node.id + "'"
top.MenuFrame.document.write("<A HREF=javascript:top.expandNode(" + nodeIdent + ")><IMG SRC='" + imageDirectory + "/" + imageString + "' ALIGN=TEXTTOP BORDER=0></A>")
break
case 'img-folder.gif':
imgstyle="close"
nodeIdent = "'" + node.id + "'"
top.MenuFrame.document.write("<A HREF=javascript:top.expandNode(" + nodeIdent + ")><IMG SRC='" + imageDirectory + "/" + imageString + "' ALIGN=TEXTTOP BORDER=0></A>")
break
case 'img-minus-cont.gif':
nodeIdent = "'" + node.id + "'"
top.MenuFrame.document.write("<A HREF=javascript:top.collapseNode(" + nodeIdent + ")><IMG SRC='" + imageDirectory + "/" + imageString + "' ALIGN=TEXTTOP BORDER=0></A>")
break
case 'img-minus-end.gif':
nodeIdent = "'" + node.id + "'"
top.MenuFrame.document.write("<A HREF=javascript:top.collapseNode(" + nodeIdent + ")><IMG SRC='" + imageDirectory + "/" + imageString + "' ALIGN=TEXTTOP BORDER=0></A>")
break
case 'img-folder-open.gif':
imgstyle="open"
nodeIdent = "'" + node.id + "'"
top.MenuFrame.document.write("<A HREF=javascript:top.collapseNode(" + nodeIdent + ")><IMG SRC='" + imageDirectory + "/" + imageString + "' ALIGN=TEXTTOP BORDER=0></A>")
break
case 'img-page.gif':
nodeIdent = "'" + node.id + "'"
top.MenuFrame.document.write("<A HREF='" + node.url + "' TARGET='" + nodeTarget + "'><IMG SRC='" + imageDirectory + "/" + imageString + "' ALIGN=TEXTTOP BORDER=0></A>")
break
default:
top.MenuFrame.document.write("<IMG SRC='" + imageDirectory + "/" + imageString + "' ALIGN=TEXTTOP>")
}
}
}
}
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
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -