/* ----------------------------------------------------------------------------- dTree 2.0 | www.destroydrop.com/javascript/tree/ ----------------------------------------------------------------------------- Copyright (c) 2002 Geir Landrö This script can be used freely as long as all copyright messages are intact. ----------------------------------------------------------------------------- */ // * Temporary solution for IE6 select's bug function hideSelect() { if (document.all) { document.all.ultimosacessos.style.visibility="hidden"; } } function unhideSelect() { if (document.all) { document.all.ultimosacessos.style.visibility="visible"; } } // * End // Node object function Node(id, pid, name, url, title, target, isopen, img) { this.id = id; this.pid = pid; this.name = name; this.url = url; //'/gsan/' + url; this.title = title; this.target = target; this.img = img; this._io = isopen || false; this._ls = false; this._hc = false; this._is = false; } // Tree object function dTree(objName) { // Variables // ---------------------------------------------------------------------------- this.arrNodes = []; this.arrRecursed = []; this.arrIcons = []; this.rootNode = -1; this.strOutput = ''; this.selectedNode = null; this.instanceName = objName; this.imgFolder = '/gsan/imagens/'; this.target = null; this.hasLines = true; this.clickSelect = true; this.folderLinks = false; this.useCookies = false; // Functions // ---------------------------------------------------------------------------- // Adds a new node to the node array this.add = function(id, pid, name, url, title, target, isopen, img) { this.arrNodes[this.arrNodes.length] = new Node(id, pid, name, url, title, target, isopen, img); } // Outputs the tree to the page this.draw = function() { if (document.getElementById) { this.preloadIcons(); if (this.useCookies) this.selectedNode = this.getSelected(); this.addNode(this.rootNode); document.writeln(this.strOutput); } else { document.writeln('Browser not supported.'); } } this.openAll = function() { this.oAll(true); } this.closeAll = function() { this.oAll(false); } // Private // ---------------------------------------------------------------------------- // Prealoads images that are used in the tree this.preloadIcons = function() { if (this.hasLines) { this.arrIcons[0] = new Image(); this.arrIcons[0].src = this.imgFolder + 'plus.gif'; this.arrIcons[1] = new Image(); this.arrIcons[1].src = this.imgFolder + 'plusbottom.gif'; this.arrIcons[2] = new Image(); this.arrIcons[2].src = this.imgFolder + 'minus.gif'; this.arrIcons[3] = new Image(); this.arrIcons[3].src = this.imgFolder + 'minusbottom.gif'; } else { this.arrIcons[0] = new Image(); this.arrIcons[0].src = this.imgFolder + 'nolines_plus.gif'; this.arrIcons[1] = new Image(); this.arrIcons[1].src = this.imgFolder + 'nolines_plus.gif'; this.arrIcons[2] = new Image(); this.arrIcons[2].src = this.imgFolder + 'nolines_minus.gif'; this.arrIcons[3] = new Image(); this.arrIcons[3].src = this.imgFolder + 'nolines_minus.gif'; } this.arrIcons[4] = new Image(); this.arrIcons[4].src = this.imgFolder + 'folder.gif'; this.arrIcons[5] = new Image(); this.arrIcons[5].src = this.imgFolder + 'folderopen.gif'; } // Recursive function that creates the tree structure this.addNode = function(pNode) { for (var n=0; n'; // Line & empty icons (cn._ls) ? this.arrRecursed.push(0) : this.arrRecursed.push(1); // Write out join icons if (cn._hc) { this.strOutput += '' + ''; } else this.strOutput += ''; } // Start the node link if (cn.url) { this.strOutput += ''; } // Write out folder & page icons this.strOutput += ''; // Write out span this.strOutput += ''; // Write out node name this.strOutput += cn.name; this.strOutput += ''; // Close the link if (cn.url || (!this.folderLinks && cn._hc)) this.strOutput += ''; this.strOutput += '
\n'; // If node has children write out divs and go deeper if (cn._hc) { this.strOutput += '
\n'; this.addNode(cn.id); this.strOutput += '
\n'; } this.arrRecursed.pop(); } } } // Checks if a node has any children this.hasChildren = function(node) { for (n=0; n