1/*--------------------------------------------------| 2| dTree 2.05 | www.destroydrop.com/javascript/tree/ | 3|---------------------------------------------------| 4| Copyright (c) 2002-2003 Geir Landr? | 5| | 6| This script can be used freely as long as all | 7| copyright messages are intact. | 8| | 9| Updated: 17.04.2003 | 10|--------------------------------------------------*/ 11 12// Node object 13function Node(id, pid, name, url, title, target, icon, iconOpen, open) { 14 this.id = id; 15 this.pid = pid; 16 this.name = name; 17 this.url = url; 18 this.title = title; 19 this.target = target; 20 this.icon = icon; 21 this.iconOpen = iconOpen; 22 this._io = open || false; 23 this._is = false; 24 this._ls = false; 25 this._hc = false; 26 this._ai = 0; 27 this._p; 28}; 29 30// Tree object 31function dTree(objName) { 32 this.config = { 33 target : null, 34 folderLinks : true, 35 useSelection : true, 36 useCookies : true, 37 useLines : true, 38 useIcons : true, 39 useStatusText : false, 40 closeSameLevel : false, 41 inOrder : false, 42 domain : '', 43 path : '' 44 } 45 this.icon = { 46 root : '/components/com_sobi2/images/base.gif', 47 folder : '/components/com_sobi2/images/folder.gif', 48 folderOpen : '/components/com_sobi2/images/folderopen.gif', 49 node : '/components/com_sobi2/images/page.gif', 50 empty : '/components/com_sobi2/images/empty.gif', 51 line : '/components/com_sobi2/images/line.gif', 52 join : '/components/com_sobi2/images/join.gif', 53 joinBottom : '/components/com_sobi2/images/joinbottom.gif', 54 plus : '/components/com_sobi2/images/plus.gif', 55 plusBottom : '/components/com_sobi2/images/plusbottom.gif', 56 minus : '/components/com_sobi2/images/minus.gif', 57 minusBottom : '/components/com_sobi2/images/minusbottom.gif', 58 nlPlus : '/components/com_sobi2/images/nolines_plus.gif', 59 nlMinus : '/components/com_sobi2/images/nolines_minus.gif' 60 }; 61 this.obj = objName; 62 this.aNodes = []; 63 this.aIndent = []; 64 this.root = new Node(-1); 65 this.selectedNode = null; 66 this.selectedFound = false; 67 this.completed = false; 68}; 69 70// Adds a new node to the node array 71dTree.prototype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) { 72 this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title, target, icon, iconOpen, open); 73}; 74 75// Open/close all nodes 76dTree.prototype.openAll = function() { 77 this.oAll(true); 78}; 79 80dTree.prototype.closeAll = function() { 81 this.oAll(false); 82}; 83 84 85// Outputs the tree to the page 86dTree.prototype.toString = function() { 87 var str = '<div class="dtree">\n'; 88 if (document.getElementById) { 89 if (this.config.useCookies) this.selectedNode = this.getSelected(); 90 str += this.addNode(this.root); 91 } else str += 'Browser not supported.'; 92 str += '</div>'; 93 if (!this.selectedFound) this.selectedNode = null; 94 this.completed = true; 95 return str; 96}; 97 98// Creates the tree structure 99dTree.prototype.addNode = function(pNode) { 100 var str = ''; 101 var n=0; 102 if (this.config.inOrder) n = pNode._ai; 103 for (n; n<this.aNodes.length; n++) { 104 if (this.aNodes[n].pid == pNode.id) { 105 var cn = this.aNodes[n]; 106 cn._p = pNode; 107 cn._ai = n; 108 this.setCS(cn); 109 if (!cn.target && this.config.target) cn.target = this.config.target; 110 if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id); 111 if (!this.config.folderLinks && cn._hc) cn.url = null; 112 if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) { 113 cn._is = true; 114 this.selectedNode = n; 115 this.selectedFound = true; 116 } 117 str += this.node(cn, n); 118 if (cn._ls) break; 119 } 120 } 121 return str; 122}; 123 124// Creates the node icon, url and text 125dTree.prototype.node = function(node, nodeId) { 126 var str = '<div class="dTreeNode">' + this.indent(node, nodeId); 127 if (this.config.useIcons) { 128 if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node); 129 if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node; 130 if (this.root.id == node.pid) { 131 node.icon = this.icon.root; 132 node.iconOpen = this.icon.root; 133 } 134 str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />'; 135 } 136 if (node.url) { 137 str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"'; 138 if (node.title) str += ' title="' + node.title + '"'; 139 if (node.target) str += ' target="' + node.target + '"'; 140 if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" '; 141 if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc)) 142 str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"'; 143 str += '>'; 144 } 145 else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id) 146 str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">'; 147 str += node.name; 148 if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>'; 149 str += '</div>'; 150 if (node._hc) { 151 str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">'; 152 str += this.addNode(node); 153 str += '</div>'; 154 } 155 this.aIndent.pop();
156 return str; 157}; 158 159// Adds the empty and line icons 160dTree.prototype.indent = function(node, nodeId) { 161 var str = ''; 162 if (this.root.id != node.pid) { 163 for (var n=0; n<this.aIndent.length; n++) 164 str += '<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '" alt="" />'; 165 (node._ls) ? this.aIndent.push(0) : this.aIndent.push(1); 166 if (node._hc) { 167 str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '" border="0" src="'; 168 if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus; 169 else str += ( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) ); 170 str += '" alt="" /></a>'; 171 } else str += '<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '" alt="" />'; 172 } 173 return str; 174}; 175 176// Checks if a node has any children and if it is the last sibling 177dTree.prototype.setCS = function(node) { 178 var lastId; 179 for (var n=0; n<this.aNodes.length; n++) { 180 if (this.aNodes[n].pid == node.id) node._hc = true; 181 if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id; 182 } 183 if (lastId==node.id) node._ls = true; 184}; 185 186// Returns the selected node 187dTree.prototype.getSelected = function() { 188 var sn = this.getCookie('cs' + this.obj); 189 return (sn) ? sn : null; 190}; 191 192// Highlights the selected node 193dTree.prototype.s = function(id) { 194 if (!this.config.useSelection) return; 195 var cn = this.aNodes[id]; 196 if (cn._hc && !this.config.folderLinks) return; 197 if (this.selectedNode != id) { 198 if (this.selectedNode || this.selectedNode==0) { 199 eOld = document.getElementById("s" + this.obj + this.selectedNode); 200 eOld.className = "node"; 201 } 202 eNew = document.getElementById("s" + this.obj + id); 203 eNew.className = "nodeSel"; 204 this.selectedNode = id; 205 if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id, null, this.config.path, this.config.domain); 206 } 207}; 208 209// Toggle Open or close 210dTree.prototype.o = function(id) { 211 var cn = this.aNodes[id]; 212 this.nodeStatus(!cn._io, id, cn._ls); 213 cn._io = !cn._io; 214 if (this.config.closeSameLevel) this.closeLevel(cn); 215 if (this.config.useCookies) this.updateCookie(); 216}; 217 218// Open or close all nodes 219dTree.prototype.oAll = function(status) { 220 for (var n=0; n<this.aNodes.length; n++) { 221 if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) { 222 this.nodeStatus(status, n, this.aNodes[n]._ls) 223 this.aNodes[n]._io = status; 224 } 225 } 226 if (this.config.useCookies) this.updateCookie(); 227}; 228 229// Opens the tree to a specific node 230dTree.prototype.openTo = function(nId, bSelect, bFirst) { 231 if (!bFirst) { 232 for (var n=0; n<this.aNodes.length; n++) { 233 if (this.aNodes[n].id == nId) { 234 nId=n; 235 break; 236 } 237 } 238 } 239 var cn=this.aNodes[nId]; 240 if (cn.pid==this.root.id || !cn._p) return; 241 cn._io = true; 242 cn._is = bSelect; 243 if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls); 244 if (this.completed && bSelect) this.s(cn._ai); 245 else if (bSelect) this._sn=cn._ai; 246 this.openTo(cn._p._ai, false, true); 247}; 248 249// Closes all nodes on the same level as certain node 250dTree.prototype.closeLevel = function(node) { 251 for (var n=0; n<this.aNodes.length; n++) { 252 if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) { 253 this.nodeStatus(false, n, this.aNodes[n]._ls); 254 this.aNodes[n]._io = false; 255 this.closeAllChildren(this.aNodes[n]); 256 } 257 } 258} 259 260// Closes all children of a node 261dTree.prototype.closeAllChildren = function(node) { 262 for (var n=0; n<this.aNodes.length; n++) { 263 if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) { 264 if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls); 265 this.aNodes[n]._io = false; 266 this.closeAllChildren(this.aNodes[n]); 267 } 268 } 269} 270 271// Change the status of a node(open or closed) 272dTree.prototype.nodeStatus = function(status, id, bottom) { 273 eDiv = document.getElementById('d' + this.obj + id); 274 eJoin = document.getElementById('j' + this.obj + id); 275 if (this.config.useIcons) { 276 eIcon = document.getElementById('i' + this.obj + id); 277 eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon; 278 } 279 eJoin.src = (this.config.useLines)? 280 ((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)): 281 ((status)?this.icon.nlMinus:this.icon.nlPlus); 282 eDiv.style.display = (status) ? 'block': 'none'; 283}; 284 285 286// [Cookie] Clears a cookie 287dTree.prototype.clearCookie = function() { 288 var now = new Date(); 289 var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24); 290 this.setCookie('co'+this.obj, 'cookieValue', yesterday); 291 this.setCookie('cs'+this.obj, 'cookieValue', yesterday); 292}; 293 294// [Cookie] Sets value in a cookie 295dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) { 296 document.cookie = 297 escape(cookieName) + '=' + escape(cookieValue) 298 + (expires ? '; expires=' + expires.toGMTString() : '') 299 + (path ? '; path=' + path : '') 300 + (domain ? '; domain=' + domain : '') 301 + (secure ? '; secure' : ''); 302};
303 304// [Cookie] Gets a value from a cookie 305dTree.prototype.getCookie = function(cookieName) { 306 var cookieValue = ''; 307 var posName = document.cookie.indexOf(escape(cookieName) + '='); 308 if (posName != -1) { 309 var posValue = posName + (escape(cookieName) + '=').length; 310 var endPos = document.cookie.indexOf(';', posValue); 311 if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos)); 312 else cookieValue = unescape(document.cookie.substring(posValue)); 313 } 314 return (cookieValue); 315}; 316 317// [Cookie] Returns ids of open nodes as a string 318dTree.prototype.updateCookie = function() { 319 var str = ''; 320 for (var n=0; n<this.aNodes.length; n++) { 321 if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) { 322 if (str) str += '.'; 323 str += this.aNodes[n].id; 324 } 325 } 326 this.setCookie('co' + this.obj, str, null, this.config.path, this.config.domain); 327}; 328 329// [Cookie] Checks if a node id is in a cookie 330dTree.prototype.isOpen = function(id) { 331 var aOpen = this.getCookie('co' + this.obj).split('.'); 332 for (var n=0; n<aOpen.length; n++) 333 if (aOpen[n] == id) return true; 334 return false; 335}; 336 337// If Push and pop is not implemented by the browser 338if (!Array.prototype.push) { 339 Array.prototype.push = function array_push() { 340 for(var i=0;i<arguments.length;i++) 341 this[this.length]=arguments[i]; 342 return this.length; 343 } 344}; 345if (!Array.prototype.pop) { 346 Array.prototype.pop = function array_pop() { 347 lastElement = this[this.length-1]; 348 this.length = Math.max(this.length-1,0); 349 return lastElement; 350 } 351};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.