// +-----------------------------------------------------------------------+ // | Copyright (c) 2002-2005, Richard Heyes, Harald Radi | // | All rights reserved. | // | | // | Redistribution and use in source and binary forms, with or without | // | modification, are permitted provided that the following conditions | // | are met: | // | | // | o Redistributions of source code must retain the above copyright | // | notice, this list of conditions and the following disclaimer. | // | o Redistributions in binary form must reproduce the above copyright | // | notice, this list of conditions and the following disclaimer in the | // | documentation and/or other materials provided with the distribution.| // | o The names of the authors may not be used to endorse or promote | // | products derived from this software without specific prior written | // | permission. | // | | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | // | | // +-----------------------------------------------------------------------+ // | Author: Richard Heyes | // | Harald Radi | // +-----------------------------------------------------------------------+ // // $Id: TreeMenu.js,v 1.1 2005/04/14 17:13:08 dpascual Exp $ // Menú para el árbol /** * Function to create copies of objects which are * normally passed around by references (Arrays for example) */ function arrayCopy(input) { var output = new Array(input.length); for (i in input) { if (typeof(input[i]) == 'array') { output[i] = arrayCopy(input[i]); } else { output[i] = input[i]; } } return output; } /** * TreeMenu class */ function TreeMenu(iconpath, myname, linkTarget, defaultClass, usePersistence, noTopLevelImages) { // Properties this.iconpath = iconpath; this.myname = myname; this.linkTarget = linkTarget; this.defaultClass = defaultClass; this.usePersistence = usePersistence; this.noTopLevelImages = noTopLevelImages; this.n = new Array(); this.output = ''; this.nodeRefs = new Array(); this.branches = new Array(); this.branchStatus = new Array(); this.layerRelations = new Array(); this.childParents = new Array(); this.cookieStatuses = new Array(); this.preloadImages(); } /** * Adds a node to the tree */ TreeMenu.prototype.addItem = function (newNode) { newIndex = this.n.length; this.n[newIndex] = newNode; return this.n[newIndex]; } /** * Preload images hack for Mozilla */ TreeMenu.prototype.preloadImages = function () { var plustop = new Image; plustop.src = this.iconpath + '/plustop.gif'; var plusbottom = new Image; plusbottom.src = this.iconpath + '/plusbottom.gif'; var plus = new Image; plus.src = this.iconpath + '/plus.gif'; var minustop = new Image; minustop.src = this.iconpath + '/minustop.gif'; var minusbottom = new Image; minusbottom.src = this.iconpath + '/minusbottom.gif'; var minus = new Image; minus.src = this.iconpath + '/minus.gif'; var branchtop = new Image; branchtop.src = this.iconpath + '/branchtop.gif'; var branchbottom = new Image; branchbottom.src = this.iconpath + '/branchbottom.gif'; var branch = new Image; branch.src = this.iconpath + '/branch.gif'; var linebottom = new Image; linebottom.src = this.iconpath + '/linebottom.gif'; var line = new Image; line.src = this.iconpath + '/line.gif'; } /** * Main function that draws the menu and assigns it * to the layer (or document.write()s it) */ TreeMenu.prototype.drawMenu = function ()// OPTIONAL ARGS: nodes = [], level = [], prepend = '', expanded = false, visbility = 'inline', parentLayerID = null { /** * Necessary variables */ var output = ''; var modifier = ''; var layerID = ''; var parentLayerID = ''; /** * Parse any optional arguments */ var nodes = arguments[0] ? arguments[0] : this.n var level = arguments[1] ? arguments[1] : []; var prepend = arguments[2] ? arguments[2] : ''; var expanded = arguments[3] ? arguments[3] : false; var visibility = arguments[4] ? arguments[4] : 'inline'; var parentLayerID = arguments[5] ? arguments[5] : null; var currentlevel = level.length; for (var i=0; i 1 ? "top" : 'single'; } else if(i == (nodes.length-1)) { modifier = "bottom"; } else { modifier = ""; } /** * Single root branch is always expanded */ if (!this.doesMenu() || (parentLayerID == null && (nodes.length == 1 || this.noTopLevelImages))) { expanded = true; } else if (nodes[i].expanded) { expanded = true; } else { expanded = false; } /** * Make sure visibility is correct based on parent status */ visibility = this.checkParentVisibility(layerID) ? visibility : 'none'; /** * Setup branch status and build an indexed array * of branch layer ids */ if (nodes[i].n.length > 0) { this.branchStatus[layerID] = expanded; this.branches[this.branches.length] = layerID; } /** * Setup toggle relationship */ if (!this.layerRelations[parentLayerID]) { this.layerRelations[parentLayerID] = new Array(); } this.layerRelations[parentLayerID][this.layerRelations[parentLayerID].length] = layerID; /** * Branch images */ var gifname = nodes[i].n.length && this.doesMenu() && nodes[i].isDynamic ? (expanded ? 'minus' : 'plus') : 'branch'; var iconName = expanded && nodes[i].expandedIcon ? nodes[i].expandedIcon : nodes[i].icon; var iconimg = nodes[i].icon ? this.stringFormat('', this.iconpath, iconName, layerID) : ''; /** * Add event handlers */ var eventHandlers = ""; for (j in nodes[i].events) { eventHandlers += this.stringFormat('{0}="{1}" ', j, nodes[i].events[j]); } /** * Build the html to write to the document * IMPORTANT: * document.write()ing the string: '
', layerID, visibility, (nodes[i].cssClass ? nodes[i].cssClass : this.defaultClass)) : this.stringFormat('
', nodes[i].cssClass ? nodes[i].cssClass : this.defaultClass); var onMDown = this.doesMenu() && nodes[i].n.length && nodes[i].isDynamic ? this.stringFormat('onmousedown="{0}.toggleBranch(\'{1}\', true)" style="cursor: pointer; cursor: hand"', this.myname, layerID) : ''; var imgTag = this.stringFormat('', this.iconpath, gifname, modifier, layerID, onMDown); var linkTarget= nodes[i].linkTarget ? nodes[i].linkTarget : this.linkTarget; var linkStart = nodes[i].link ? this.stringFormat('', nodes[i].link, linkTarget, layerID) : ''; // MOD: ENLAZA var linkEnd = nodes[i].link ? '' : ''; this.output += this.stringFormat('{0}{1}{2}{3}{4}{6}{7}
', layerTag, prepend, parentLayerID == null && (nodes.length == 1 || this.noTopLevelImages) ? '' : imgTag, iconimg, linkStart, eventHandlers, nodes[i].title, linkEnd); /* MOD(ENLAZA): Guarda el nodo seleccionado en una variable */ if (nodes[i].cssClass.indexOf('seleccionado') != -1) { window.layerArbolAVisualizar = 'link_' + layerID; } /* FIN MOD. */ /** * Traverse sub nodes ? */ if (nodes[i].n.length) { /** * Determine what to prepend. If there is only one root * node then the prepend to pass to children is nothing. * Otherwise it depends on where we are in the tree. */ if (parentLayerID == null && (nodes.length == 1 || this.noTopLevelImages)) { var newPrepend = ''; } else if (i < (nodes.length - 1)) { var newPrepend = prepend + this.stringFormat('', this.iconpath); } else { var newPrepend = prepend + this.stringFormat('', this.iconpath); } this.drawMenu(nodes[i].n, arrayCopy(level), newPrepend, nodes[i].expanded, expanded ? 'inline' : 'none', layerID); } } } /** * Writes the output generated by drawMenu() to the page */ TreeMenu.prototype.writeOutput = function () { document.write(this.output); } /** * Toggles a branches visible status. Called from resetBranches() * and also when a +/- graphic is clicked. */ TreeMenu.prototype.toggleBranch = function (layerID, updateStatus) // OPTIONAL ARGS: fireEvents = true { var currentDisplay = this.getLayer(layerID).style.display; var newDisplay = (this.branchStatus[layerID] && currentDisplay == 'inline') ? 'none' : 'inline'; var fireEvents = arguments[2] != null ? arguments[2] : true; for (var i=0; i= 5)); var is_gecko = (agt.indexOf('gecko') != -1); var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)); var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) ); var is_ie4up = (is_ie && (is_major >= 4)); var is_opera = (agt.indexOf("opera") != -1); var is_opera7 = (is_opera && is_major >= 7) || agt.indexOf("opera 7") != -1; // Patch from Harald Fielker if (agt.indexOf('konqueror') != -1) { var is_nav = false; var is_nav6up = false; var is_gecko = false; var is_ie = true; var is_ie4 = true; var is_ie4up = true; } //--> end hide JavaScript