// wp_dtree_Node object function wp_dtree_Node(id, pid, name, url, title, targ, count, rsspath){ this.id = id; this.pid = pid; this.name = name; this.url = url; this.title = title; this.count = count; //for postcounts this.rsspath = rsspath; //for feed link. var icon, iconOpen, open; //these were originally passed as parameters, but were never used in wp-dtree. this.target = targ; this.icon = icon; this.iconOpen = iconOpen; this._io = open || false; this._is = false; this._ls = false; this._hc = false; this._ai = 0; this._p; }; // Tree object function wp_dTree(objName, baseUrl, truncate){ this.config ={ target : null, folderLinks : false, useSelection : false, useCookies : true, useLines : true, useIcons : true, useStatusText : false, closeSameLevel : false, inOrder : false } this.icon ={ root : 'images/empty.gif', folder : 'images/folder.gif', folderOpen : 'images/folderopen.gif', node : 'images/page.gif', empty : 'images/empty.gif', line : 'images/line.gif', join : 'images/join.gif', joinBottom : 'images/joinbottom.gif', plus : 'images/plus.gif', plusBottom : 'images/plusbottom.gif', minus : 'images/minus.gif', minusBottom : 'images/minusbottom.gif', nlPlus : 'images/nolines_plus.gif', nlMinus : 'images/nolines_minus.gif' }; this._url = baseUrl; this._truncate = truncate; this.obj = objName; this.awp_dtree_Nodes = []; this.aIndent = []; this.root = new wp_dtree_Node(-1); this.selectedwp_dtree_Node = null; this.selectedFound = false; this.completed = false; }; // Adds a new node to the node array wp_dTree.prototype.a = function(id, pid, title, path, link_target, count, rsspath){ if(typeof(count) != "undefined" && count != ""){ count = "
(" + count + ")
"; } if(typeof(rsspath) != "undefined" && rsspath != ""){ rsspath = " "; } name = this.htmlEntities(this.truncate(title, this._truncate)); path += ""; //remove this and the next line breaks down for some reason. var url = path; //default value. if(!path.indexOf('http://') == 0){ //if the path doesn't start with "http://" (eg. home path) url = this._url + path; } this.awp_dtree_Nodes[this.awp_dtree_Nodes.length] = new wp_dtree_Node(id, pid, name, url, this.htmlEntities(title),link_target, count, rsspath); }; wp_dTree.prototype.truncate = function(str, length){ var length = length || 16; var truncation = '...'; if(str.length > length) { return str.slice(0, length - truncation.length) + truncation; } return str; }; wp_dTree.prototype.htmlEntities = function(str) { str=str.replace(/\&/g,'\&'); str=str.replace(/\"/g,'\"'); str=str.replace(/\/g,'\>'); return str; } // Open/close all nodes wp_dTree.prototype.openAll = function(){ this.oAll(true); }; wp_dTree.prototype.closeAll = function(){ this.oAll(false); }; // Outputs the tree to the page wp_dTree.prototype.toString = function(){ var str = '
\n'; if(document.getElementById){ if(this.config.useCookies) this.selectedwp_dtree_Node = this.getSelected(); str += this.addwp_dtree_Node(this.root); } else str += 'Browser not supported.'; str += '
'; if(!this.selectedFound) this.selectedwp_dtree_Node = null; this.completed = true; return str; }; // Creates the tree structure wp_dTree.prototype.addwp_dtree_Node = function(pwp_dtree_Node){ var str = ''; var n=0; if(this.config.inOrder) n = pwp_dtree_Node._ai; for (n; n < this.awp_dtree_Nodes.length; n++){ if(this.awp_dtree_Nodes[n].pid == pwp_dtree_Node.id){ var cn = this.awp_dtree_Nodes[n]; cn._p = pwp_dtree_Node; cn._ai = n; this.setCS(cn); if(!cn.target && this.config.target) cn.target = this.config.target; if(cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id); if(!this.config.folderLinks && cn._hc) cn.url = null; if(this.config.useSelection && cn.id == this.selectedwp_dtree_Node && !this.selectedFound){ cn._is = true; this.selectedwp_dtree_Node = n; this.selectedFound = true; } str += this.node(cn, n); if(cn._ls) break; } } return str; }; // Creates the node icon, url and text wp_dTree.prototype.node = function(node, nodeId){ var str = '
' + this.indent(node, nodeId); 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){ str += ''; } } if(this.root.id != node.pid){ if(node.url){ str += ''; str += this.addwp_dtree_Node(node); str += '
'; } this.aIndent.pop(); return str; }; // Adds the empty and line icons wp_dTree.prototype.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 ifa node has any children and ifit is the last sibling wp_dTree.prototype.setCS = function(node){ var lastId; for (var n=0; n