YAHOO.widget.TreeView = function(id) { if (id) { this.init(id);}
}; YAHOO.widget.TreeView.prototype = { id: null, _nodes: null, locked: false, _expandAnim: null, _collapseAnim: null, _animCount: 0, _maxAnim: 2, setExpandAnim: function(type) { if (YAHOO.widget.TVAnim.isValid(type)) { this._expandAnim = type;}
}, setCollapseAnim: function(type) { if (YAHOO.widget.TVAnim.isValid(type)) { this._collapseAnim = type;}
}, animateExpand: function(el) { if (this._expandAnim && this._animCount < this._maxAnim) { var tree = this; var a = YAHOO.widget.TVAnim.getAnim(this._expandAnim, el, function() { tree.expandComplete();}); if (a) { ++this._animCount; a.animate();}
return true;}
return false;}, animateCollapse: function(el) { if (this._collapseAnim && this._animCount < this._maxAnim) { var tree = this; var a = YAHOO.widget.TVAnim.getAnim(this._collapseAnim, el, function() { tree.collapseComplete();}); if (a) { ++this._animCount; a.animate();}
return true;}
return false;}, expandComplete: function() { --this._animCount;}, collapseComplete: function() { --this._animCount;}, init: function(id) { this.id = id; this._nodes = new Array(); YAHOO.widget.TreeView.trees[id] = this; this.root = new YAHOO.widget.RootNode(this);}, draw: function() { var html = this.root.getHtml(); document.getElementById(this.id).innerHTML = html; this.firstDraw = false;}, regNode: function(node) { this._nodes[node.index] = node;}, getRoot: function() { return this.root;}, setDynamicLoad: function(fnDataLoader) { this.root.setDynamicLoad(fnDataLoader);}, expandAll: function() { if (!this.locked) { this.root.expandAll();}
}, collapseAll: function() { if (!this.locked) { this.root.collapseAll();}
}, getNodeByIndex: function(nodeIndex) { var n = this._nodes[nodeIndex]; return (n) ? n : null;}, getNodeByProperty: function(property, value) { for (var i in this._nodes) { var n = this._nodes[i]; if (n.data && value == n.data[property]) { return n;}
}
return null;}, onExpand: function(node) { }, onCollapse: function(node) { }
}; YAHOO.widget.TreeView.trees = []; YAHOO.widget.TreeView.getTree = function(treeId) { var t = YAHOO.widget.TreeView.trees[treeId]; return (t) ? t : null;}; YAHOO.widget.TreeView.nodeCount = 0; YAHOO.widget.TreeView.getNode = function(treeId, nodeIndex) { var t = YAHOO.widget.TreeView.getTree(treeId); return (t) ? t.getNodeByIndex(nodeIndex) : null;}; YAHOO.widget.TreeView.addHandler = function (el, sType, fn, capture) { capture = (capture) ? true : false; if (el.addEventListener) { el.addEventListener(sType, fn, capture);} else if (el.attachEvent) { el.attachEvent("on" + sType, fn);} else { el["on" + sType] = fn;}
}; YAHOO.widget.TreeView.preload = function() { var styles = [ "ygtvtn", "ygtvtm", "ygtvtmh", "ygtvtp", "ygtvtph", "ygtvln", "ygtvlm", "ygtvlmh", "ygtvlp", "ygtvlph", "ygtvloading" ]; var sb = []; for (var i = 0; i < styles.length; ++i) { sb[sb.length] = '<span class="' + styles[i] + '">&nbsp;</span>';}
var f = document.createElement("div"); var s = f.style; s.position = "absolute"; s.top = "-1000px"; s.left = "-1000px"; f.innerHTML = sb.join(""); document.body.appendChild(f);}; YAHOO.widget.TreeView.addHandler(window, "load", YAHOO.widget.TreeView.preload); YAHOO.widget.Node = function(oData, oParent, expanded) { if (oParent) { this.init(oData, oParent, expanded);}
}; YAHOO.widget.Node.prototype = { index: 0, children: null, tree: null, data: null, parent: null, depth: -1, href: null, ic: null, target: "_self", expanded: false, multiExpand: true, renderHidden: false, childrenRendered: false, previousSibling: null, nextSibling: null, _dynLoad: false, dataLoader: null, isLoading: false, hasIcon: true, init: function(oData, oParent, expanded) { this.data = oData; this.children = []; this.index = YAHOO.widget.TreeView.nodeCount; ++YAHOO.widget.TreeView.nodeCount; this.expanded = expanded; if (oParent) { this.tree = oParent.tree; this.parent = oParent; this.href = "javascript:" + this.getToggleLink(); this.depth = oParent.depth + 1; this.multiExpand = oParent.multiExpand; oParent.appendChild(this);}
}, appendChild: function(node) { if (this.hasChildren()) { var sib = this.children[this.children.length - 1]; sib.nextSibling = node; node.previousSibling = sib;}
this.tree.regNode(node); this.children[this.children.length] = node; return node;}, getSiblings: function() { return this.parent.children;}, showChildren: function() { if (!this.tree.animateExpand(this.getChildrenEl())) { if (this.hasChildren()) { this.getChildrenEl().style.display = "";}
}
}, hideChildren: function() { if (!this.tree.animateCollapse(this.getChildrenEl())) { this.getChildrenEl().style.display = "none";}
}, getElId: function() { return "ygtv" + this.index;}, getChildrenElId: function() { return "ygtvc" + this.index;}, getToggleElId: function() { return "ygtvt" + this.index;}, getEl: function() { return document.getElementById(this.getElId());}, getChildrenEl: function() { return document.getElementById(this.getChildrenElId());}, getToggleEl: function() { return document.getElementById(this.getToggleElId());}, getToggleLink: function() { return "YAHOO.widget.TreeView.getNode(\'" + this.tree.id + "\'," + this.index + ").toggle()";}, collapse: function() { if (!this.expanded) { return;}
if (!this.getEl()) { this.expanded = false; return;}
this.hideChildren(); this.expanded = false; if (this.hasIcon) { this.getToggleEl().className = this.getStyle();}
this.tree.onCollapse(this);}, expand: function() { if (this.expanded) { return;}
if (!this.getEl()) { this.expanded = true; return;}
if (! this.childrenRendered) { this.getChildrenEl().innerHTML = this.renderChildren();}
this.expanded = true; if (this.hasIcon) { this.getToggleEl().className = this.getStyle();}
if (this.isLoading) { this.expanded = false; return;}
if (! this.multiExpand) { var sibs = this.getSiblings(); for (var i=0; i<sibs.length; ++i) { if (sibs[i] != this && sibs[i].expanded) { sibs[i].collapse();}
}
}
this.showChildren(); this.tree.onExpand(this);}, getStyle: function() { if (this.isLoading) { return "ygtvloading";} else { var loc = (this.nextSibling) ? "t" : "l"; var type = "n"; if (this.hasChildren(true) || this.isDynamic()) { type = (this.expanded) ? "m" : "p";}
return "ygtv" + loc + type;}
}, getHoverStyle: function() { var s = this.getStyle(); if (this.hasChildren(true) && !this.isLoading) { s += "h";}
return s;}, expandAll: function() { for (var i=0;i<this.children.length;++i) { var c = this.children[i]; if (c.isDynamic()) { alert("Not supported (lazy load + expand all)"); break;} else if (! c.multiExpand) { alert("Not supported (no multi-expand + expand all)"); break;} else { c.expand(); c.expandAll();}
}
}, collapseAll: function() { for (var i=0;i<this.children.length;++i) { this.children[i].collapse(); this.children[i].collapseAll();}
}, setDynamicLoad: function(fnDataLoader) { this.dataLoader = fnDataLoader; this._dynLoad = true;}, isRoot: function() { return (this == this.tree.root);}, isDynamic: function() { var lazy = (!this.isRoot() && (this._dynLoad || this.tree.root._dynLoad)); return lazy;}, hasChildren: function(checkForLazyLoad) { return ( this.children.length > 0 || (checkForLazyLoad && this.isDynamic() && !this.childrenRendered) );}, toggle: function() { if (!this.tree.locked && ( this.hasChildren(true) || this.isDynamic()) ) { if (this.expanded) { this.collapse();} else { this.expand();}
}
}, getHtml: function() { var sb = []; sb[sb.length] = '<div class="ygtvitem" id="' + this.getElId() + '">'; sb[sb.length] = this.getNodeHtml(); sb[sb.length] = this.getChildrenHtml(); sb[sb.length] = '</div>'; return sb.join("");}, getChildrenHtml: function() { var sb = []; sb[sb.length] = '<div class="ygtvchildren"'; sb[sb.length] = ' id="' + this.getChildrenElId() + '"'; if (!this.expanded) { sb[sb.length] = ' style="display:none;"';}
sb[sb.length] = '>'; if (this.hasChildren(true) && this.expanded) { sb[sb.length] = this.renderChildren();}
sb[sb.length] = '</div>'; return sb.join("");}, renderChildren: function() { var node = this; if (this.isDynamic() && !this.childrenRendered) { this.isLoading = true; this.tree.locked = true; if (this.dataLoader) { setTimeout( function() { node.dataLoader(node, function() { node.loadComplete();});}, 10);} else if (this.tree.root.dataLoader) { setTimeout( function() { node.tree.root.dataLoader(node, function() { node.loadComplete();});}, 10);} else { return "Error: data loader not found or not specified.";}
return "";} else { return this.completeRender();}
}, completeRender: function() { var sb = []; for (var i=0; i < this.children.length; ++i) { sb[sb.length] = this.children[i].getHtml();}
this.childrenRendered = true; return sb.join("");}, loadComplete: function() { this.getChildrenEl().innerHTML = this.completeRender(); this.isLoading = false; this.expand(); this.tree.locked = false;}, getAncestor: function(depth) { if (depth >= this.depth || depth < 0) { return null;}
var p = this.parent; while (p.depth > depth) { p = p.parent;}
return p;}, getDepthStyle: function(depth) { return (this.getAncestor(depth).nextSibling) ?
"ygtvdepthcell" : "ygtvblankdepthcell";}, getNodeHtml: function() { return "";}
}; YAHOO.widget.RootNode = function(oTree) { this.init(null, null, true); this.tree = oTree;}; YAHOO.widget.RootNode.prototype = new YAHOO.widget.Node(); YAHOO.widget.RootNode.prototype.getNodeHtml = function() { return "";}; YAHOO.widget.TextNode = function(oData, oParent, expanded) { if (oParent) { this.init(oData, oParent, expanded); this.setUpLabel(oData);}
}; YAHOO.widget.TextNode.prototype = new YAHOO.widget.Node(); YAHOO.widget.TextNode.prototype.labelStyle = "ygtvlabel"; YAHOO.widget.TextNode.prototype.labelElId = null; YAHOO.widget.TextNode.prototype.label = null; YAHOO.widget.TextNode.prototype.setUpLabel = function(oData) { if (typeof oData == "string") { oData = { label: oData };}
this.label = oData.label; if (oData.href) { this.href = oData.href;}
if (oData.ic) { this.ic = oData.ic;}
if (oData.target) { this.target = oData.target;}
this.labelElId = "ygtvlabelel" + this.index;}; YAHOO.widget.TextNode.prototype.getLabelEl = function() { return document.getElementById(this.labelElId);}; YAHOO.widget.TextNode.prototype.getNodeHtml = function() { var sb = new Array(); sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">'; sb[sb.length] = '<tr>'; for (i=0;i<this.depth;++i) { sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '">&nbsp;</td>';}
var getNode = 'YAHOO.widget.TreeView.getNode(\'' + this.tree.id + '\',' + this.index + ')'; sb[sb.length] = '<td'; sb[sb.length] = ' id="' + this.getToggleElId() + '"'; sb[sb.length] = ' class="' + this.getStyle() + '"'; if (this.hasChildren(true)) { sb[sb.length] = ' onmouseover="this.className='; sb[sb.length] = getNode + '.getHoverStyle()"'; sb[sb.length] = ' onmouseout="this.className='; sb[sb.length] = getNode + '.getStyle()"';}
sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '">&nbsp;'; sb[sb.length] = '</td>'; sb[sb.length] = '<td>'; sb[sb.length] = '<a'; sb[sb.length] = ' id="' + this.labelElId + '"'; sb[sb.length] = ' class="' + this.labelStyle + '"'; sb[sb.length] = ' href="' + this.href + '"'; sb[sb.length] = ' target="' + this.target + '"'; if (this.hasChildren(true)) { sb[sb.length] = ' onmouseover="document.getElementById(\''; sb[sb.length] = this.getToggleElId() + '\').className='; sb[sb.length] = getNode + '.getHoverStyle()"'; sb[sb.length] = ' onmouseout="document.getElementById(\''; sb[sb.length] = this.getToggleElId() + '\').className='; sb[sb.length] = getNode + '.getStyle()"';}
sb[sb.length] = ' >'; if (this.ic == "T") { sb[sb.length] = '<b style="color:#CC0000;text-decoration:underline;">' + this.label + '</b>';} else { sb[sb.length] = this.label;}
sb[sb.length] = '</a>'; sb[sb.length] = '</td>'; sb[sb.length] = '</tr>'; sb[sb.length] = '</table>'; return sb.join("");}; YAHOO.widget.MenuNode = function(oData, oParent, expanded) { if (oParent) { this.init(oData, oParent, expanded); this.setUpLabel(oData);}
this.multiExpand = false;}; YAHOO.widget.MenuNode.prototype = new YAHOO.widget.TextNode(); YAHOO.widget.HTMLNode = function(oData, oParent, expanded, hasIcon) { if (oParent) { this.init(oData, oParent, expanded); this.initContent(oData, hasIcon);}
}; YAHOO.widget.HTMLNode.prototype = new YAHOO.widget.Node(); YAHOO.widget.HTMLNode.prototype.contentStyle = "ygtvhtml"; YAHOO.widget.HTMLNode.prototype.contentElId = null; YAHOO.widget.HTMLNode.prototype.content = null; YAHOO.widget.HTMLNode.prototype.initContent = function(oData, hasIcon) { if (typeof oData == "string") { oData = { html: oData };}
this.html = oData.html; this.contentElId = "ygtvcontentel" + this.index; this.hasIcon = hasIcon;}; YAHOO.widget.HTMLNode.prototype.getContentEl = function() { return document.getElementById(this.contentElId);}; YAHOO.widget.HTMLNode.prototype.getNodeHtml = function() { var sb = new Array(); sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">'; sb[sb.length] = '<tr>'; for (i=0;i<this.depth;++i) { sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '">&nbsp;</td>';}
if (this.hasIcon) { sb[sb.length] = '<td'; sb[sb.length] = ' id="' + this.getToggleElId() + '"'; sb[sb.length] = ' class="' + this.getStyle() + '"'; sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '">&nbsp;'; if (this.hasChildren(true)) { sb[sb.length] = ' onmouseover="this.className='; sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\''; sb[sb.length] = this.tree.id + '\',' + this.index + ').getHoverStyle()"'; sb[sb.length] = ' onmouseout="this.className='; sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\''; sb[sb.length] = this.tree.id + '\',' + this.index + ').getStyle()"';}
sb[sb.length] = '</td>';}
sb[sb.length] = '<td'; sb[sb.length] = ' id="' + this.contentElId + '"'; sb[sb.length] = ' class="' + this.contentStyle + '"'; sb[sb.length] = ' >'; sb[sb.length] = this.html; sb[sb.length] = '</td>'; sb[sb.length] = '</tr>'; sb[sb.length] = '</table>'; return sb.join("");}; YAHOO.widget.TVAnim = new function() { this.FADE_IN = "YAHOO.widget.TVFadeIn"; this.FADE_OUT = "YAHOO.widget.TVFadeOut"; this.getAnim = function(type, el, callback) { switch (type) { case this.FADE_IN: return new YAHOO.widget.TVFadeIn(el, callback); case this.FADE_OUT: return new YAHOO.widget.TVFadeOut(el, callback); default: return null;}
}; this.isValid = function(type) { return ( "undefined" != eval("typeof " + type) );};}; YAHOO.widget.TVFadeIn = function(el, callback) { this.el = el; this.callback = callback;}; YAHOO.widget.TVFadeIn.prototype = { animate: function() { var tvanim = this; var s = this.el.style; s.opacity = 0.1; s.filter = "alpha(opacity=10)"; s.display = ""; var dur = 0.4; var a = new YAHOO.util.Anim(this.el, {opacity: {from: 0.1, to: 1, unit:""}}, dur); a.onComplete.subscribe( function() { tvanim.onComplete();} ); a.animate();}, onComplete: function() { this.callback();}
}; YAHOO.widget.TVFadeOut = function(el, callback) { this.el = el; this.callback = callback;}; YAHOO.widget.TVFadeOut.prototype = { animate: function() { var tvanim = this; var dur = 0.4; var a = new YAHOO.util.Anim(this.el, {opacity: {from: 1, to: 0.1, unit:""}}, dur); a.onComplete.subscribe( function() { tvanim.onComplete();} ); a.animate();}, onComplete: function() { var s = this.el.style; s.display = "none"; s.filter = "alpha(opacity=100)"; this.callback();}
};