/*--------------------------------------------------| | dTree 2.05 | www.destroydrop.com/javascript/tree/ | |---------------------------------------------------| | Copyright (c) 2002-2003 Geir Landrö | | | | This script can be used freely as long as all | | copyright messages are intact. | | | | Updated: 17.04.2003 | |--------------------------------------------------*/ /* The content of attribute values should be quoted properly by using the equivalent entities. */ function dTreeQuote(str) { return (str .replace(/\"/g, """) .replace(/\'/g, "'")); } // Node object function Node(id, pid, name, isParent, url, dataname, datatype, title, target, icon, iconOpen, open, hasUnseen) { this.isParent = isParent; this.id = id; this.pid = pid; this.name = name; this.url = url; this.title = title; this.target = target; this.icon = icon; this.iconOpen = iconOpen; this.dataname = dataname; this.datatype = datatype; this.hasUnseen = hasUnseen; this._io = open || false; this._is = false; this._ls = false; this._hc = false; this._ai = 0; this._p; }; // Tree object function dTree(objName) { this.obj = objName; this.config = { target: null, hideRoot: false, folderLinks: true, useSelection: true, useCookies: false, useLines: true, useIcons: true, useStatusText: false, closeSameLevel: false, inOrder: false }; this.icon = { root: 'img/base.gif', folder: 'img/folder.gif', folderOpen: 'img/folderopen.gif', node: 'img/page.gif', empty: 'img/empty.gif', line: 'img/line.gif', join: 'img/join.gif', joinBottom: 'img/joinbottom.gif', plus: 'img/plus.gif', plusBottom: 'img/plusbottom.gif', minus: 'img/minus.gif', minusBottom: 'img/minusbottom.gif', nlPlus: 'img/nolines_plus.gif', nlMinus: 'img/nolines_minus.gif' }; this.aNodes = []; this.aIndent = []; this.root = new Node(-1); this.selectedNode = null; this.selectedFound = false; this.completed = false; return this; }; dTree.prototype = { obj: null, config: null, icon: null, aNodes: null, aIndent: null, root: null, selectedNode: null, selectedFound: false, completed: false, // Adds a new node to the node array add: function(id, pid, name, isParent, url, datatype, title, target, icon, iconOpen, open, hasUnseen) { this.aNodes[this.aNodes.length] = new Node(id, pid, name, isParent, url, datatype, title, target, icon, iconOpen, open, false, hasUnseen); }, // Open/close all nodes openAll: function() { this.oAll(true); }, closeAll: function() { this.oAll(false); }, // Outputs the tree to the page toString: function() { var str = '
\n'; if (document.getElementById) { if (this.config.useCookies) this.selectedNode = this.getSelected(); str += this.addNode(this.root); } else str += 'Browser not supported.'; str += '
'; if (!this.selectedFound) this.selectedNode = null; this.completed = true; return str; }, valueOf: function() { return this.toString(); }, // Creates the tree structure addNode: function(pNode) { var str = ''; var n=0; if (this.config.inOrder) n = pNode._ai; for (n; n'; if (this.config.useIcons) { if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node); if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node; if (this.root.id == node.pid) { node.icon = this.icon.root; node.iconOpen = this.icon.root; } str += ''; } str += '' + node.name + ''; if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += ''; str += ''; } if (node._hc) { str += '
'; str += this.addNode(node); str += '
'; } this.aIndent.pop(); return str; }, // Adds the empty and line icons indent: function(node, nodeId) { var str = ''; if (this.root.id != node.pid) { for (var n=0; n'; (node._ls) ? this.aIndent.push(0) : this.aIndent.push(1); if (node._hc) { str += ''; } else str += ''; } return str; }, // Checks if a node has any children and if it is the last sibling setCS: function(node) { var lastId; for (var n=0; n