source: branches/comu/html/test/kakinaka/js/treeview/treeview.js @ 2

Revision 2, 52.5 KB checked in by root, 17 years ago (diff)

new import

Line 
1/*                                                                                                                                                     
2Copyright (c) 2006, Yahoo! Inc. All rights reserved.
3Code licensed under the BSD License:
4http://developer.yahoo.net/yui/license.txt
5version: 0.11.3
6*/
7
8/**
9 * Contains the tree view state data and the root node.  This is an
10 * ordered tree; child nodes will be displayed in the order created, and
11 * there currently is no way to change this.
12 *
13 * @constructor
14 * @param {string|HTMLElement} id The id of the element, or the element
15 * itself that the tree will be inserted into.
16 */
17YAHOO.widget.TreeView = function(id) {
18    if (id) { this.init(id); }
19};
20
21/**
22 * Count of all nodes in all trees
23 * @type int
24 */
25YAHOO.widget.TreeView.nodeCount = 100;
26
27YAHOO.widget.TreeView.prototype = {
28
29    /**
30     * The id of tree container element
31     *
32     * @type String
33     */
34    id: null,
35
36    /**
37     * The host element for this tree
38     * @private
39     */
40    _el: null,
41
42     /**
43     * Flat collection of all nodes in this tree
44     *
45     * @type Node[]
46     * @private
47     */
48    _nodes: null,
49
50    /**
51     * We lock the tree control while waiting for the dynamic loader to return
52     *
53     * @type boolean
54     */
55    locked: false,
56
57    /**
58     * The animation to use for expanding children, if any
59     *
60     * @type string
61     * @private
62     */
63    _expandAnim: null,
64
65    /**
66     * The animation to use for collapsing children, if any
67     *
68     * @type string
69     * @private
70     */
71    _collapseAnim: null,
72
73    /**
74     * The current number of animations that are executing
75     *
76     * @type int
77     * @private
78     */
79    _animCount: 0,
80
81    /**
82     * The maximum number of animations to run at one time.
83     *
84     * @type int
85     */
86    maxAnim: 2,
87
88    /**
89     * Sets up the animation for expanding children
90     *
91     * @param {string} the type of animation (acceptable values defined in
92     * YAHOO.widget.TVAnim)
93     */
94    setExpandAnim: function(type) {
95        if (YAHOO.widget.TVAnim.isValid(type)) {
96            this._expandAnim = type;
97        }
98    },
99
100    /**
101     * Sets up the animation for collapsing children
102     *
103     * @param {string} the type of animation (acceptable values defined in
104     * YAHOO.widget.TVAnim)
105     */
106    setCollapseAnim: function(type) {
107        if (YAHOO.widget.TVAnim.isValid(type)) {
108            this._collapseAnim = type;
109        }
110    },
111
112    /**
113     * Perform the expand animation if configured, or just show the
114     * element if not configured or too many animations are in progress
115     *
116     * @param el {HTMLElement} the element to animate
117     * @return {boolean} true if animation could be invoked, false otherwise
118     */
119    animateExpand: function(el) {
120
121        if (this._expandAnim && this._animCount < this.maxAnim) {
122            // this.locked = true;
123            var tree = this;
124            var a = YAHOO.widget.TVAnim.getAnim(this._expandAnim, el,
125                            function() { tree.expandComplete(); });
126            if (a) {
127                ++this._animCount;
128                a.animate();
129            }
130
131            return true;
132        }
133
134        return false;
135    },
136
137    /**
138     * Perform the collapse animation if configured, or just show the
139     * element if not configured or too many animations are in progress
140     *
141     * @param el {HTMLElement} the element to animate
142     * @return {boolean} true if animation could be invoked, false otherwise
143     */
144    animateCollapse: function(el) {
145
146        if (this._collapseAnim && this._animCount < this.maxAnim) {
147            // this.locked = true;
148            var tree = this;
149            var a = YAHOO.widget.TVAnim.getAnim(this._collapseAnim, el,
150                            function() { tree.collapseComplete(); });
151            if (a) {
152                ++this._animCount;
153                a.animate();
154            }
155
156            return true;
157        }
158
159        return false;
160    },
161
162    /**
163     * Function executed when the expand animation completes
164     */
165    expandComplete: function() {
166        --this._animCount;
167        // this.locked = false;
168    },
169
170    /**
171     * Function executed when the collapse animation completes
172     */
173    collapseComplete: function() {
174        --this._animCount;
175        // this.locked = false;
176    },
177
178    /**
179     * Initializes the tree
180     *
181     * @parm {string|HTMLElement} id the id of the element that will hold the tree
182     * @private
183     */
184    init: function(id) {
185
186        this.id = id;
187
188        if ("string" !== typeof id) {
189            this._el = id;
190            this.id = this.generateId(id);
191        }
192
193        this._nodes = [];
194
195        // store a global reference
196        YAHOO.widget.TreeView.trees[this.id] = this;
197
198        // Set up the root node
199        this.root = new YAHOO.widget.RootNode(this);
200
201
202    },
203
204    /**
205     * Renders the tree boilerplate and visible nodes
206     */
207    draw: function() {
208        var html = this.root.getHtml();
209        this.getEl().innerHTML = html;
210        this.firstDraw = false;
211    },
212
213    /**
214     * Returns the tree's host element
215     * @return {HTMLElement} the host element
216     */
217    getEl: function() {
218        if (! this._el) {
219            this._el = document.getElementById(this.id);
220        }
221        return this._el;
222    },
223
224    /**
225     * Nodes register themselves with the tree instance when they are created.
226     *
227     * @param node {Node} the node to register
228     * @private
229     */
230    regNode: function(node) {
231        this._nodes[node.index] = node;
232    },
233
234    /**
235     * Returns the root node of this tree
236     *
237     * @return {Node} the root node
238     */
239    getRoot: function() {
240        return this.root;
241    },
242
243    /**
244     * Configures this tree to dynamically load all child data
245     *
246     * @param {function} fnDataLoader the function that will be called to get the data
247     * @param iconMode {int} configures the icon that is displayed when a dynamic
248     * load node is expanded the first time without children.  By default, the
249     * "collapse" icon will be used.  If set to 1, the leaf node icon will be
250     * displayed.
251     */
252    setDynamicLoad: function(fnDataLoader, iconMode) {
253        this.root.setDynamicLoad(fnDataLoader, iconMode);
254    },
255
256    /**
257     * Expands all child nodes.  Note: this conflicts with the "multiExpand"
258     * node property.  If expand all is called in a tree with nodes that
259     * do not allow multiple siblings to be displayed, only the last sibling
260     * will be expanded.
261     */
262    expandAll: function() {
263        if (!this.locked) {
264            this.root.expandAll();
265        }
266    },
267
268    /**
269     * Collapses all expanded child nodes in the entire tree.
270     */
271    collapseAll: function() {
272        if (!this.locked) {
273            this.root.collapseAll();
274        }
275    },
276
277    /**
278     * Returns a node in the tree that has the specified index (this index
279     * is created internally, so this function probably will only be used
280     * in html generated for a given node.)
281     *
282     * @param {int} nodeIndex the index of the node wanted
283     * @return {Node} the node with index=nodeIndex, null if no match
284     */
285    getNodeByIndex: function(nodeIndex) {
286        var n = this._nodes[nodeIndex];
287        return (n) ? n : null;
288    },
289
290    /**
291     * Returns a node that has a matching property and value in the data
292     * object that was passed into its constructor.
293     *
294     * @param {object} property the property to search (usually a string)
295     * @param {object} value the value we want to find (usuall an int or string)
296     * @return {Node} the matching node, null if no match
297     */
298    getNodeByProperty: function(property, value) {
299        for (var i in this._nodes) {
300            var n = this._nodes[i];
301            if (n.data && value == n.data[property]) {
302                return n;
303            }
304        }
305
306        return null;
307    },
308
309    /**
310     * Returns a collection of nodes that have a matching property
311     * and value in the data object that was passed into its constructor. 
312     *
313     * @param {object} property the property to search (usually a string)
314     * @param {object} value the value we want to find (usuall an int or string)
315     * @return {Array} the matching collection of nodes, null if no match
316     */
317    getNodesByProperty: function(property, value) {
318        var values = [];
319        for (var i in this._nodes) {
320            var n = this._nodes[i];
321            if (n.data && value == n.data[property]) {
322                values.push(n);
323            }
324        }
325
326        return (values.length) ? values : null;
327    },
328
329    /**
330     * Removes the node and its children, and optionally refreshes the
331     * branch of the tree that was affected.
332     * @param {Node} The node to remove
333     * @param {boolean} autoRefresh automatically refreshes branch if true
334     * @return {boolean} False is there was a problem, true otherwise.
335     */
336    removeNode: function(node, autoRefresh) {
337
338        // Don't delete the root node
339        if (node.isRoot()) {
340            return false;
341        }
342
343        // Get the branch that we may need to refresh
344        var p = node.parent;
345        if (p.parent) {
346            p = p.parent;
347        }
348
349        // Delete the node and its children
350        this._deleteNode(node);
351
352        // Refresh the parent of the parent
353        if (autoRefresh && p && p.childrenRendered) {
354            p.refresh();
355        }
356
357        return true;
358    },
359
360    /**
361     * Deletes this nodes child collection, recursively.  Also collapses
362     * the node, and resets the dynamic load flag.  The primary use for
363     * this method is to purge a node and allow it to fetch its data
364     * dynamically again.
365     * @param {Node} node the node to purge
366     */
367    removeChildren: function(node) {
368        while (node.children.length) {
369             this._deleteNode(node.children[0]);
370        }
371
372        node.childrenRendered = false;
373        node.dynamicLoadComplete = false;
374        // node.collapse();
375        node.expand();
376        node.collapse();
377    },
378
379    /**
380     * Deletes the node and recurses children
381     * @private
382     */
383    _deleteNode: function(node) {
384        // Remove all the child nodes first
385        this.removeChildren(node);
386
387        // Remove the node from the tree
388        this.popNode(node);
389    },
390
391    /**
392     * Removes the node from the tree, preserving the child collection
393     * to make it possible to insert the branch into another part of the
394     * tree, or another tree.
395     * @param {Node} the node to remove
396     */
397    popNode: function(node) {
398        var p = node.parent;
399
400        // Update the parent's collection of children
401        var a = [];
402
403        for (var i=0, len=p.children.length;i<len;++i) {
404            if (p.children[i] != node) {
405                a[a.length] = p.children[i];
406            }
407        }
408
409        p.children = a;
410
411        // reset the childrenRendered flag for the parent
412        p.childrenRendered = false;
413
414         // Update the sibling relationship
415        if (node.previousSibling) {
416            node.previousSibling.nextSibling = node.nextSibling;
417        }
418
419        if (node.nextSibling) {
420            node.nextSibling.previousSibling = node.previousSibling;
421        }
422
423        node.parent = null;
424        node.previousSibling = null;
425        node.nextSibling = null;
426        node.tree = null;
427
428        // Update the tree's node collection
429        delete this._nodes[node.index];
430    },
431
432    /**
433     * toString
434     * @return {string} string representation of the tree
435     */
436    toString: function() {
437        return "TreeView " + this.id;
438    },
439
440    /**
441     * private
442     */
443    generateId: function(el) {
444        var id = el.id;
445
446        if (!id) {
447            id = "yui-tv-auto-id-" + YAHOO.widget.TreeView.counter;
448            YAHOO.widget.TreeView.counter++;
449        }
450
451        return id;
452    },
453
454    /**
455     * Abstract method that is executed when a node is expanded
456     * @param node {Node} the node that was expanded
457     */
458    onExpand: function(node) { },
459
460    /**
461     * Abstract method that is executed when a node is collapsed
462     * @param node {Node} the node that was collapsed.
463     */
464    onCollapse: function(node) { }
465
466};
467
468/**
469 * Global cache of tree instances
470 *
471 * @type Array
472 * @private
473 */
474YAHOO.widget.TreeView.trees = [];
475
476/**
477 * @private
478 */
479YAHOO.widget.TreeView.counter = 0;
480
481/**
482 * Global method for getting a tree by its id.  Used in the generated
483 * tree html.
484 *
485 * @param treeId {String} the id of the tree instance
486 * @return {TreeView} the tree instance requested, null if not found.
487 */
488YAHOO.widget.TreeView.getTree = function(treeId) {
489    var t = YAHOO.widget.TreeView.trees[treeId];
490    return (t) ? t : null;
491};
492
493/**
494 * Global method for getting a node by its id.  Used in the generated
495 * tree html.
496 *
497 * @param treeId {String} the id of the tree instance
498 * @param nodeIndex {String} the index of the node to return
499 * @return {Node} the node instance requested, null if not found
500 */
501YAHOO.widget.TreeView.getNode = function(treeId, nodeIndex) {
502    var t = YAHOO.widget.TreeView.getTree(treeId);
503   
504    alert(t);
505
506    return (t) ? t.getNodeByIndex(nodeIndex) : null;
507};
508
509/**
510 * Adds an event.  Replace with event manager when available
511 *
512 * @param el the elment to bind the handler to
513 * @param {string} sType the type of event handler
514 * @param {function} fn the callback to invoke
515 * @param {boolean} capture if true event is capture phase, bubble otherwise
516 */
517YAHOO.widget.TreeView.addHandler = function (el, sType, fn, capture) {
518    capture = (capture) ? true : false;
519    if (el.addEventListener) {
520        el.addEventListener(sType, fn, capture);
521    } else if (el.attachEvent) {
522        el.attachEvent("on" + sType, fn);
523    } else {
524        el["on" + sType] = fn;
525    }
526};
527
528/**
529 * Attempts to preload the images defined in the styles used to draw the tree by
530 * rendering off-screen elements that use the styles.
531 */
532YAHOO.widget.TreeView.preload = function(prefix) {
533    prefix = prefix || "ygtv";
534    var styles = ["tn","tm","tmh","tp","tph","ln","lm","lmh","lp","lph","loading"];
535
536    var sb = [];
537   
538    for (var i = 0; i < styles.length; ++i) {
539        sb[sb.length] = '<span class="' + prefix + styles[i] + '">&#160;</span>';
540    }
541
542    var f = document.createElement("DIV");
543    var s = f.style;
544    s.position = "absolute";
545    s.top = "-1000px";
546    s.left = "-1000px";
547    f.innerHTML = sb.join("");
548
549    document.body.appendChild(f);
550};
551
552YAHOO.widget.TreeView.addHandler(window,
553                "load", YAHOO.widget.TreeView.preload);
554
555/**
556 * The base class for all tree nodes.  The node's presentation and behavior in
557 * response to mouse events is handled in Node subclasses.
558 *
559 * @param oData {object} a string or object containing the data that will
560 * be used to render this node
561 * @param oParent {Node} this node's parent node
562 * @param expanded {boolean} the initial expanded/collapsed state
563 * @constructor
564 */
565YAHOO.widget.Node = function(oData, oParent, expanded) {
566    if (oData) { this.init(oData, oParent, expanded); }
567};
568
569YAHOO.widget.Node.prototype = {
570
571    /**
572     * The index for this instance obtained from global counter in YAHOO.widget.TreeView.
573     *
574     * @type int
575     */
576    index: 0,
577
578    /**
579     * This node's child node collection.
580     *
581     * @type Node[]
582     */
583    children: null,
584
585    /**
586     * Tree instance this node is part of
587     *
588     * @type TreeView
589     */
590    tree: null,
591
592    /**
593     * The data linked to this node.  This can be any object or primitive
594     * value, and the data can be used in getNodeHtml().
595     *
596     * @type object
597     */
598    data: null,
599
600    /**
601     * Parent node
602     *
603     * @type Node
604     */
605    parent: null,
606
607    /**
608     * The depth of this node.  We start at -1 for the root node.
609     *
610     * @type int
611     */
612    depth: -1,
613
614    /**
615     * The href for the node's label.  If one is not specified, the href will
616     * be set so that it toggles the node.
617     *
618     * @type string
619     */
620    href: null,
621
622    /**
623     * The label href target, defaults to current window
624     *
625     * @type string
626     */
627    target: "_self",
628
629    /**
630     * The node's expanded/collapsed state
631     *
632     * @type boolean
633     */
634    expanded: false,
635
636    /**
637     * Can multiple children be expanded at once?
638     *
639     * @type boolean
640     */
641    multiExpand: true,
642
643    /**
644     * Should we render children for a collapsed node?  It is possible that the
645     * implementer will want to render the hidden data...  @todo verify that we
646     * need this, and implement it if we do.
647     *
648     * @type boolean
649     */
650    renderHidden: false,
651
652    /**
653     * This flag is set to true when the html is generated for this node's
654     * children, and set to false when new children are added.
655     * @type boolean
656     */
657    childrenRendered: false,
658
659    /**
660     * Dynamically loaded nodes only fetch the data the first time they are
661     * expanded.  This flag is set to true once the data has been fetched.
662     * @type boolean
663     */
664    dynamicLoadComplete: false,
665
666    /**
667     * This node's previous sibling
668     *
669     * @type Node
670     */
671    previousSibling: null,
672
673    /**
674     * This node's next sibling
675     *
676     * @type Node
677     */
678    nextSibling: null,
679
680    /**
681     * We can set the node up to call an external method to get the child
682     * data dynamically.
683     *
684     * @type boolean
685     * @private
686     */
687    _dynLoad: false,
688
689    /**
690     * Function to execute when we need to get this node's child data.
691     *
692     * @type function
693     */
694    dataLoader: null,
695
696    /**
697     * This is true for dynamically loading nodes while waiting for the
698     * callback to return.
699     *
700     * @type boolean
701     */
702    isLoading: false,
703
704    /**
705     * The toggle/branch icon will not show if this is set to false.  This
706     * could be useful if the implementer wants to have the child contain
707     * extra info about the parent, rather than an actual node.
708     *
709     * @type boolean
710     */
711    hasIcon: true,
712
713    /**
714     * Used to configure what happens when a dynamic load node is expanded
715     * and we discover that it does not have children.  By default, it is
716     * treated as if it still could have children (plus/minus icon).  Set
717     * iconMode to have it display like a leaf node instead.
718     * @type int
719     */
720    iconMode: 0,
721
722    /**
723     * The node type
724     * @private
725     */
726    _type: "Node",
727
728    /*
729    spacerPath: "http://us.i1.yimg.com/us.yimg.com/i/space.gif",
730    expandedText: "Expanded",
731    collapsedText: "Collapsed",
732    loadingText: "Loading",
733    */
734
735    /**
736     * Initializes this node, gets some of the properties from the parent
737     *
738     * @param oData {object} a string or object containing the data that will
739     * be used to render this node
740     * @param oParent {Node} this node's parent node
741     * @param expanded {boolean} the initial expanded/collapsed state
742     */
743    init: function(oData, oParent, expanded, index) {
744        this.data       = oData;
745        this.children   = [];
746       
747        if(typeof index == "number"){
748            this.index      = index;
749        }else{
750            this.index      = YAHOO.widget.TreeView.nodeCount;
751            ++YAHOO.widget.TreeView.nodeCount;
752        }
753        this.expanded   = expanded;
754       
755
756        // oParent should never be null except when we create the root node.
757        if (oParent) {
758            this.parent_id = oParent.index
759            oParent.appendChild(this);
760        }
761    },
762
763    /**
764     * Certain properties for the node cannot be set until the parent
765     * is known. This is called after the node is inserted into a tree.
766     * the parent is also applied to this node's children in order to
767     * make it possible to move a branch from one tree to another.
768     * @param {Node} parentNode this node's parent node
769     * @return {boolean} true if the application was successful
770     */
771    applyParent: function(parentNode) {
772        if (!parentNode) {
773            return false;
774        }
775
776        this.tree   = parentNode.tree;
777        this.parent = parentNode;
778        this.depth  = parentNode.depth + 1;
779
780        if (! this.href) {
781            this.href = "javascript:" + this.getToggleLink();
782        }
783
784        if (! this.multiExpand) {
785            this.multiExpand = parentNode.multiExpand;
786        }
787
788        this.tree.regNode(this);
789        parentNode.childrenRendered = false;
790
791        // cascade update existing children
792        for (var i=0, len=this.children.length;i<len;++i) {
793            this.children[i].applyParent(this);
794        }
795
796        return true;
797    },
798
799    /**
800     * Appends a node to the child collection.
801     *
802     * @param childNode {Node} the new node
803     * @return {Node} the child node
804     * @private
805     */
806    appendChild: function(childNode) {
807        if (this.hasChildren()) {
808            var sib = this.children[this.children.length - 1];
809            sib.nextSibling = childNode;
810            childNode.previousSibling = sib;
811        }
812        this.children[this.children.length] = childNode;
813        childNode.applyParent(this);
814
815        return childNode;
816    },
817
818    /**
819     * Appends this node to the supplied node's child collection
820     * @param parentNode {Node} the node to append to.
821     * @return {Node} The appended node
822     */
823    appendTo: function(parentNode) {
824        return parentNode.appendChild(this);
825    },
826
827    /**
828    * Inserts this node before this supplied node
829    *
830    * @param node {Node} the node to insert this node before
831    * @return {Node} the inserted node
832    */
833    insertBefore: function(node) {
834        var p = node.parent;
835        if (p) {
836
837            if (this.tree) {
838                this.tree.popNode(this);
839            }
840
841            var refIndex = node.isChildOf(p);
842            p.children.splice(refIndex, 0, this);
843            if (node.previousSibling) {
844                node.previousSibling.nextSibling = this;
845            }
846            this.previousSibling = node.previousSibling;
847            this.nextSibling = node;
848            node.previousSibling = this;
849
850            this.applyParent(p);
851        }
852
853        return this;
854    },
855 
856    /**
857    * Inserts this node after the supplied node
858    *
859    * @param node {Node} the node to insert after
860    * @return {Node} the inserted node
861    */
862    insertAfter: function(node) {
863        var p = node.parent;
864        if (p) {
865
866            if (this.tree) {
867                this.tree.popNode(this);
868            }
869
870            var refIndex = node.isChildOf(p);
871
872            if (!node.nextSibling) {
873                return this.appendTo(p);
874            }
875
876            p.children.splice(refIndex + 1, 0, this);
877
878            node.nextSibling.previousSibling = this;
879            this.previousSibling = node;
880            this.nextSibling = node.nextSibling;
881            node.nextSibling = this;
882
883            this.applyParent(p);
884        }
885
886        return this;
887    },
888
889    /**
890    * Returns true if the Node is a child of supplied Node
891    *
892    * @param parentNode {Node} the Node to check
893    * @return {boolean} The node index if this Node is a child of
894    *                   supplied Node, else -1.
895    * @private
896    */
897    isChildOf: function(parentNode) {
898        if (parentNode && parentNode.children) {
899            for (var i=0, len=parentNode.children.length; i<len ; ++i) {
900                if (parentNode.children[i] === this) {
901                    return i;
902                }
903            }
904        }
905
906        return -1;
907    },
908
909    /**
910     * Returns a node array of this node's siblings, null if none.
911     *
912     * @return Node[]
913     */
914    getSiblings: function() {
915        return this.parent.children;
916    },
917
918    /**
919     * Shows this node's children
920     */
921    showChildren: function() {
922        if (!this.tree.animateExpand(this.getChildrenEl())) {
923            if (this.hasChildren()) {
924                this.getChildrenEl().style.display = "";
925            }
926        }
927    },
928
929    /**
930     * Hides this node's children
931     */
932    hideChildren: function() {
933
934        if (!this.tree.animateCollapse(this.getChildrenEl())) {
935            this.getChildrenEl().style.display = "none";
936        }
937    },
938
939    /**
940     * Returns the id for this node's container div
941     *
942     * @return {string} the element id
943     */
944    getElId: function() {
945        return "ygtv" + this.index;
946    },
947
948    /**
949     * Returns the id for this node's children div
950     *
951     * @return {string} the element id for this node's children div
952     */
953    getChildrenElId: function() {
954        return "ygtvc" + this.index;
955    },
956
957    /**
958     * Returns the id for this node's toggle element
959     *
960     * @return {string} the toggel element id
961     */
962    getToggleElId: function() {
963        return "ygtvt" + this.index;
964    },
965
966    /**
967     * Returns the id for this node's spacer image.  The spacer is positioned
968     * over the toggle and provides feedback for screen readers.
969     * @return {string} the id for the spacer image
970     */
971    /*
972    getSpacerId: function() {
973        return "ygtvspacer" + this.index;
974    },
975    */
976
977    /**
978     * Returns this node's container html element
979     * @return {HTMLElement} the container html element
980     */
981    getEl: function() {
982        return document.getElementById(this.getElId());
983    },
984
985    /**
986     * Returns the div that was generated for this node's children
987     * @return {HTMLElement} this node's children div
988     */
989    getChildrenEl: function() {
990        return document.getElementById(this.getChildrenElId());
991    },
992
993    /**
994     * Returns the element that is being used for this node's toggle.
995     * @return {HTMLElement} this node's toggle html element
996     */
997    getToggleEl: function() {
998        return document.getElementById(this.getToggleElId());
999    },
1000
1001    /**
1002     * Returns the element that is being used for this node's spacer.
1003     * @return {HTMLElement} this node's spacer html element
1004     */
1005    /*
1006    getSpacer: function() {
1007        return document.getElementById( this.getSpacerId() ) || {};
1008    },
1009    */
1010
1011    /*
1012    getStateText: function() {
1013        if (this.isLoading) {
1014            return this.loadingText;
1015        } else if (this.hasChildren(true)) {
1016            if (this.expanded) {
1017                return this.expandedText;
1018            } else {
1019                return this.collapsedText;
1020            }
1021        } else {
1022            return "";
1023        }
1024    },
1025    */
1026
1027    /**
1028     * Generates the link that will invoke this node's toggle method
1029     * @return {string} the javascript url for toggling this node
1030     */
1031    getToggleLink: function() {
1032        return "YAHOO.widget.TreeView.getNode(\'" + this.tree.id + "\'," +
1033            this.index + ").toggle()";
1034    },
1035
1036    /**
1037     * Hides this nodes children (creating them if necessary), changes the
1038     * toggle style.
1039     */
1040    collapse: function() {
1041        // Only collapse if currently expanded
1042        if (!this.expanded) { return; }
1043
1044        // fire the collapse event handler
1045        var ret = this.tree.onCollapse(this);
1046
1047        if ("undefined" != typeof ret && !ret) {
1048            return;
1049        }
1050
1051        if (!this.getEl()) {
1052            this.expanded = false;
1053            return;
1054        }
1055
1056        // hide the child div
1057        this.hideChildren();
1058        this.expanded = false;
1059
1060        if (this.hasIcon) {
1061            this.getToggleEl().className = this.getStyle();
1062        }
1063
1064        // this.getSpacer().title = this.getStateText();
1065
1066    },
1067
1068    /**
1069     * Shows this nodes children (creating them if necessary), changes the
1070     * toggle style, and collapses its siblings if multiExpand is not set.
1071     */
1072    expand: function() {
1073        // Only expand if currently collapsed.
1074        if (this.expanded) { return; }
1075
1076        // fire the expand event handler
1077        var ret = this.tree.onExpand(this);
1078
1079        if ("undefined" != typeof ret && !ret) {
1080            return;
1081        }
1082
1083        if (!this.getEl()) {
1084            this.expanded = true;
1085            return;
1086        }
1087
1088        if (! this.childrenRendered) {
1089            this.getChildrenEl().innerHTML = this.renderChildren();
1090        } else {
1091        }
1092
1093        this.expanded = true;
1094        if (this.hasIcon) {
1095            this.getToggleEl().className = this.getStyle();
1096        }
1097
1098        // this.getSpacer().title = this.getStateText();
1099
1100        // We do an extra check for children here because the lazy
1101        // load feature can expose nodes that have no children.
1102
1103        // if (!this.hasChildren()) {
1104        if (this.isLoading) {
1105            this.expanded = false;
1106            return;
1107        }
1108
1109        if (! this.multiExpand) {
1110            var sibs = this.getSiblings();
1111            for (var i=0; i<sibs.length; ++i) {
1112                if (sibs[i] != this && sibs[i].expanded) {
1113                    sibs[i].collapse();
1114                }
1115            }
1116        }
1117
1118        this.showChildren();
1119    },
1120
1121    /**
1122     * Returns the css style name for the toggle
1123     *
1124     * @return {string} the css class for this node's toggle
1125     */
1126    getStyle: function() {
1127        if (this.isLoading) {
1128            return "ygtvloading";
1129        } else {
1130            // location top or bottom, middle nodes also get the top style
1131            var loc = (this.nextSibling) ? "t" : "l";
1132
1133            // type p=plus(expand), m=minus(collapase), n=none(no children)
1134            var type = "n";
1135            if (this.hasChildren(true) || (this.isDynamic() && !this.getIconMode())) {
1136            // if (this.hasChildren(true)) {
1137                type = (this.expanded) ? "m" : "p";
1138            }
1139
1140            return "ygtv" + loc + type;
1141        }
1142    },
1143
1144    /**
1145     * Returns the hover style for the icon
1146     * @return {string} the css class hover state
1147     */
1148    getHoverStyle: function() {
1149        var s = this.getStyle();
1150        if (this.hasChildren(true) && !this.isLoading) {
1151            s += "h";
1152        }
1153        return s;
1154    },
1155
1156    /**
1157     * Recursively expands all of this node's children.
1158     */
1159    expandAll: function() {
1160        for (var i=0;i<this.children.length;++i) {
1161            var c = this.children[i];
1162            if (c.isDynamic()) {
1163                alert("Not supported (lazy load + expand all)");
1164                break;
1165            } else if (! c.multiExpand) {
1166                alert("Not supported (no multi-expand + expand all)");
1167                break;
1168            } else {
1169                c.expand();
1170                c.expandAll();
1171            }
1172        }
1173    },
1174
1175    /**
1176     * Recursively collapses all of this node's children.
1177     */
1178    collapseAll: function() {
1179        for (var i=0;i<this.children.length;++i) {
1180            this.children[i].collapse();
1181            this.children[i].collapseAll();
1182        }
1183    },
1184
1185    /**
1186     * Configures this node for dynamically obtaining the child data
1187     * when the node is first expanded.  Calling it without the callback
1188     * will turn off dynamic load for the node.
1189     *
1190     * @param fmDataLoader {function} the function that will be used to get the data.
1191     * @param iconMode {int} configures the icon that is displayed when a dynamic
1192     * load node is expanded the first time without children.  By default, the
1193     * "collapse" icon will be used.  If set to 1, the leaf node icon will be
1194     * displayed.
1195     */
1196    setDynamicLoad: function(fnDataLoader, iconMode) {
1197        if (fnDataLoader) {
1198            this.dataLoader = fnDataLoader;
1199            this._dynLoad = true;
1200        } else {
1201            this.dataLoader = null;
1202            this._dynLoad = false;
1203        }
1204
1205        if (iconMode) {
1206            this.iconMode = iconMode;
1207        }
1208    },
1209
1210    /**
1211     * Evaluates if this node is the root node of the tree
1212     *
1213     * @return {boolean} true if this is the root node
1214     */
1215    isRoot: function() {
1216        return (this == this.tree.root);
1217    },
1218
1219    /**
1220     * Evaluates if this node's children should be loaded dynamically.  Looks for
1221     * the property both in this instance and the root node.  If the tree is
1222     * defined to load all children dynamically, the data callback function is
1223     * defined in the root node
1224     *
1225     * @return {boolean} true if this node's children are to be loaded dynamically
1226     */
1227    isDynamic: function() {
1228        var lazy = (!this.isRoot() && (this._dynLoad || this.tree.root._dynLoad));
1229        return lazy;
1230    },
1231
1232    getIconMode: function() {
1233        return (this.iconMode || this.tree.root.iconMode);
1234    },
1235
1236    /**
1237     * Checks if this node has children.  If this node is lazy-loading and the
1238     * children have not been rendered, we do not know whether or not there
1239     * are actual children.  In most cases, we need to assume that there are
1240     * children (for instance, the toggle needs to show the expandable
1241     * presentation state).  In other times we want to know if there are rendered
1242     * children.  For the latter, "checkForLazyLoad" should be false.
1243     *
1244     * @param checkForLazyLoad {boolean} should we check for unloaded children?
1245     * @return {boolean} true if this has children or if it might and we are
1246     * checking for this condition.
1247     */
1248    hasChildren: function(checkForLazyLoad) {
1249        return ( this.children.length > 0 ||
1250                (checkForLazyLoad && this.isDynamic() && !this.dynamicLoadComplete) );
1251    },
1252
1253    /**
1254     * Expands if node is collapsed, collapses otherwise.
1255     */
1256    toggle: function() {
1257        if (!this.tree.locked && ( this.hasChildren(true) || this.isDynamic()) ) {
1258            if (this.expanded) { this.collapse(); } else { this.expand(); }
1259        }
1260    },
1261
1262    /**
1263     * Returns the markup for this node and its children.
1264     *
1265     * @return {string} the markup for this node and its expanded children.
1266     */
1267    getHtml: function() {
1268        var sb = [];
1269        sb[sb.length] = '<div class="ygtvitem" id="' + this.getElId() + '">';
1270        sb[sb.length] = this.getNodeHtml();
1271        sb[sb.length] = this.getChildrenHtml();
1272        sb[sb.length] = '</div>';
1273        return sb.join("");
1274    },
1275
1276    /**
1277     * Called when first rendering the tree.  We always build the div that will
1278     * contain this nodes children, but we don't render the children themselves
1279     * unless this node is expanded.
1280     *
1281     * @return {string} the children container div html and any expanded children
1282     * @private
1283     */
1284    getChildrenHtml: function() {
1285
1286        var sb = [];
1287        sb[sb.length] = '<div class="ygtvchildren"';
1288        sb[sb.length] = ' id="' + this.getChildrenElId() + '"';
1289        if (!this.expanded) {
1290            sb[sb.length] = ' style="display:none;"';
1291        }
1292        sb[sb.length] = '>';
1293
1294        // Don't render the actual child node HTML unless this node is expanded.
1295        if ( (this.hasChildren(true) && this.expanded) ||
1296                (this.renderHidden && !this.isDynamic()) ) {
1297            sb[sb.length] = this.renderChildren();
1298        }
1299
1300        sb[sb.length] = '</div>';
1301
1302        return sb.join("");
1303    },
1304
1305    /**
1306     * Generates the markup for the child nodes.  This is not done until the node
1307     * is expanded.
1308     *
1309     * @return {string} the html for this node's children
1310     * @private
1311     */
1312    renderChildren: function() {
1313
1314
1315        var node = this;
1316
1317        if (this.isDynamic() && !this.dynamicLoadComplete) {
1318            this.isLoading = true;
1319            this.tree.locked = true;
1320
1321            if (this.dataLoader) {
1322
1323                setTimeout(
1324                    function() {
1325                        node.dataLoader(node,
1326                            function() {
1327                                node.loadComplete();
1328                            });
1329                    }, 10);
1330               
1331            } else if (this.tree.root.dataLoader) {
1332
1333                setTimeout(
1334                    function() {
1335                        node.tree.root.dataLoader(node,
1336                            function() {
1337                                node.loadComplete();
1338                            });
1339                    }, 10);
1340
1341            } else {
1342                return "Error: data loader not found or not specified.";
1343            }
1344
1345            return "";
1346
1347        } else {
1348            return this.completeRender();
1349        }
1350    },
1351
1352    /**
1353     * Called when we know we have all the child data.
1354     * @return {string} children html
1355     */
1356    completeRender: function() {
1357        var sb = [];
1358
1359        for (var i=0; i < this.children.length; ++i) {
1360            this.children[i].childrenRendered = false;
1361            sb[sb.length] = this.children[i].getHtml();
1362        }
1363       
1364        this.childrenRendered = true;
1365
1366        return sb.join("");
1367    },
1368
1369    /**
1370     * Load complete is the callback function we pass to the data provider
1371     * in dynamic load situations.
1372     */
1373    loadComplete: function() {
1374        this.getChildrenEl().innerHTML = this.completeRender();
1375        this.dynamicLoadComplete = true;
1376        this.isLoading = false;
1377        this.expand();
1378        this.tree.locked = false;
1379    },
1380
1381    /**
1382     * Returns this node's ancestor at the specified depth.
1383     *
1384     * @param {int} depth the depth of the ancestor.
1385     * @return {Node} the ancestor
1386     */
1387    getAncestor: function(depth) {
1388        if (depth >= this.depth || depth < 0)  {
1389            return null;
1390        }
1391
1392        var p = this.parent;
1393       
1394        while (p.depth > depth) {
1395            p = p.parent;
1396        }
1397
1398        return p;
1399    },
1400
1401    /**
1402     * Returns the css class for the spacer at the specified depth for
1403     * this node.  If this node's ancestor at the specified depth
1404     * has a next sibling the presentation is different than if it
1405     * does not have a next sibling
1406     *
1407     * @param {int} depth the depth of the ancestor.
1408     * @return {string} the css class for the spacer
1409     */
1410    getDepthStyle: function(depth) {
1411        return (this.getAncestor(depth).nextSibling) ?
1412            "ygtvdepthcell" : "ygtvblankdepthcell";
1413    },
1414
1415    /**
1416     * Get the markup for the node.  This is designed to be overrided so that we can
1417     * support different types of nodes.
1418     *
1419     * @return {string} The HTML that will render this node.
1420     */
1421    getNodeHtml: function() {
1422        return "";
1423    },
1424
1425    /**
1426     * Regenerates the html for this node and its children.  To be used when the
1427     * node is expanded and new children have been added.
1428     */
1429    refresh: function() {
1430        // this.loadComplete();
1431        this.getChildrenEl().innerHTML = this.completeRender();
1432
1433        if (this.hasIcon) {
1434            var el = this.getToggleEl();
1435            if (el) {
1436                el.className = this.getStyle();
1437            }
1438        }
1439    },
1440
1441    /**
1442     * toString
1443     * @return {string} string representation of the node
1444     */
1445    toString: function() {
1446        return "Node (" + this.index + ")";
1447    }
1448
1449};
1450
1451/**
1452 * A custom YAHOO.widget.Node that handles the unique nature of
1453 * the virtual, presentationless root node.
1454 *
1455 * @extends YAHOO.widget.Node
1456 * @constructor
1457 */
1458YAHOO.widget.RootNode = function(oTree) {
1459    // Initialize the node with null params.  The root node is a
1460    // special case where the node has no presentation.  So we have
1461    // to alter the standard properties a bit.
1462    this.init(null, null, true);
1463   
1464    /**
1465     * For the root node, we get the tree reference from as a param
1466     * to the constructor instead of from the parent element.
1467     *
1468     * @type TreeView
1469     */
1470    this.tree = oTree;
1471};
1472
1473YAHOO.widget.RootNode.prototype = new YAHOO.widget.Node();
1474
1475// overrides YAHOO.widget.Node
1476YAHOO.widget.RootNode.prototype.getNodeHtml = function() {
1477    return "";
1478};
1479
1480YAHOO.widget.RootNode.prototype.toString = function() {
1481    return "RootNode";
1482};
1483
1484YAHOO.widget.RootNode.prototype.loadComplete = function() {
1485    this.tree.draw();
1486};
1487/**
1488 * The default node presentation.  The first parameter should be
1489 * either a string that will be used as the node's label, or an object
1490 * that has a string propery called label.  By default, the clicking the
1491 * label will toggle the expanded/collapsed state of the node.  By
1492 * changing the href property of the instance, this behavior can be
1493 * changed so that the label will go to the specified href.
1494 *
1495 * @extends YAHOO.widget.Node
1496 * @constructor
1497 * @param oData {object} a string or object containing the data that will
1498 * be used to render this node
1499 * @param oParent {YAHOO.widget.Node} this node's parent node
1500 * @param expanded {boolean} the initial expanded/collapsed state
1501 */
1502YAHOO.widget.TextNode = function(oData, oParent, expanded, index) {
1503    // this.type = "TextNode";
1504
1505    if (oData) {
1506        this.init(oData, oParent, expanded, index);
1507        this.setUpLabel(oData);
1508    }
1509
1510    /**
1511     * @private
1512     */
1513};
1514
1515YAHOO.widget.TextNode.prototype = new YAHOO.widget.Node();
1516
1517/**
1518 * The CSS class for the label href.  Defaults to ygtvlabel, but can be
1519 * overridden to provide a custom presentation for a specific node.
1520 *
1521 * @type string
1522 */
1523YAHOO.widget.TextNode.prototype.labelStyle = "ygtvlabel";
1524
1525/**
1526 * The derived element id of the label for this node
1527 *
1528 * @type string
1529 */
1530YAHOO.widget.TextNode.prototype.labelElId = null;
1531
1532/**
1533 * The text for the label.  It is assumed that the oData parameter will
1534 * either be a string that will be used as the label, or an object that
1535 * has a property called "label" that we will use.
1536 *
1537 * @type string
1538 */
1539YAHOO.widget.TextNode.prototype.label = null;
1540
1541/**
1542 * Sets up the node label
1543 *
1544 * @param oData string containing the label, or an object with a label property
1545 */
1546YAHOO.widget.TextNode.prototype.setUpLabel = function(oData) {
1547    if (typeof oData == "string") {
1548        oData = { label: oData };
1549    }
1550    this.label = oData.label;
1551   
1552    // update the link
1553    if (oData.href) {
1554        this.href = oData.href;
1555    }
1556
1557    // set the target
1558    if (oData.target) {
1559        this.target = oData.target;
1560    }
1561
1562    if (oData.style) {
1563        this.labelStyle = oData.style;
1564    }
1565
1566    this.labelElId = "ygtvlabelel" + this.index;
1567};
1568
1569/**
1570 * Returns the label element
1571 *
1572 * @return {object} the element
1573 */
1574YAHOO.widget.TextNode.prototype.getLabelEl = function() {
1575    return document.getElementById(this.labelElId);
1576};
1577
1578// overrides YAHOO.widget.Node
1579YAHOO.widget.TextNode.prototype.getNodeHtml = function() {
1580    var sb = [];
1581
1582    sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
1583    sb[sb.length] = '<tr>';
1584   
1585    for (i=0;i<this.depth;++i) {
1586        // sb[sb.length] = '<td class="ygtvdepthcell">&#160;</td>';
1587        sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '">&#160;</td>';
1588    }
1589
1590    var getNode = 'YAHOO.widget.TreeView.getNode(\'' +
1591                    this.tree.id + '\',' + this.index + ')';
1592
1593    sb[sb.length] = '<td';
1594    // sb[sb.length] = ' onselectstart="return false"';
1595    sb[sb.length] = ' id="' + this.getToggleElId() + '"';
1596    sb[sb.length] = ' class="' + this.getStyle() + '"';
1597    if (this.hasChildren(true)) {
1598        sb[sb.length] = ' onmouseover="this.className=';
1599        sb[sb.length] = getNode + '.getHoverStyle()"';
1600        sb[sb.length] = ' onmouseout="this.className=';
1601        sb[sb.length] = getNode + '.getStyle()"';
1602    }
1603    sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '">';
1604
1605    /*
1606    sb[sb.length] = '<img id="' + this.getSpacerId() + '"';
1607    sb[sb.length] = ' alt=""';
1608    sb[sb.length] = ' tabindex=0';
1609    sb[sb.length] = ' src="' + this.spacerPath + '"';
1610    sb[sb.length] = ' title="' + this.getStateText() + '"';
1611    sb[sb.length] = ' class="ygtvspacer"';
1612    // sb[sb.length] = ' onkeypress="return ' + getNode + '".onKeyPress()"';
1613    sb[sb.length] = ' />';
1614    */
1615
1616    sb[sb.length] = '&#160;';
1617
1618    sb[sb.length] = '</td>';
1619    sb[sb.length] = '<td>';
1620    sb[sb.length] = '<a';
1621    sb[sb.length] = ' id="' + this.labelElId + '"';
1622    sb[sb.length] = ' class="' + this.labelStyle + '"';
1623    sb[sb.length] = ' href="' + this.href + '"';
1624    sb[sb.length] = ' target="' + this.target + '"';
1625    sb[sb.length] = ' onclick="return ' + getNode + '.onLabelClick(' + getNode +')"';
1626    if (this.hasChildren(true)) {
1627        sb[sb.length] = ' onmouseover="document.getElementById(\'';
1628        sb[sb.length] = this.getToggleElId() + '\').className=';
1629        sb[sb.length] = getNode + '.getHoverStyle()"';
1630        sb[sb.length] = ' onmouseout="document.getElementById(\'';
1631        sb[sb.length] = this.getToggleElId() + '\').className=';
1632        sb[sb.length] = getNode + '.getStyle()"';
1633    }
1634    sb[sb.length] = ' >';
1635    sb[sb.length] = this.label;
1636    sb[sb.length] = '</a>';
1637    sb[sb.length] = '</td>';
1638    sb[sb.length] = '</tr>';
1639    sb[sb.length] = '</table>';
1640
1641    return sb.join("");
1642};
1643
1644/**
1645 * Executed when the label is clicked
1646 * @param me {Node} this node
1647 * @scope the anchor tag clicked
1648 * @return false to cancel the anchor click
1649 */
1650YAHOO.widget.TextNode.prototype.onLabelClick = function(me) {
1651    //return true;
1652};
1653
1654YAHOO.widget.TextNode.prototype.toString = function() {
1655    return "TextNode (" + this.index + ") " + this.label;
1656};
1657
1658/**
1659 * A menu-specific implementation that differs from TextNode in that only
1660 * one sibling can be expanded at a time.
1661 * @extends YAHOO.widget.TextNode
1662 * @constructor
1663 */
1664YAHOO.widget.MenuNode = function(oData, oParent, expanded) {
1665    if (oData) {
1666        this.init(oData, oParent, expanded);
1667        this.setUpLabel(oData);
1668    }
1669
1670    /**
1671     * Menus usually allow only one branch to be open at a time.
1672     * @type boolean
1673     */
1674    this.multiExpand = false;
1675
1676    /**
1677     * @private
1678     */
1679
1680};
1681
1682YAHOO.widget.MenuNode.prototype = new YAHOO.widget.TextNode();
1683
1684YAHOO.widget.MenuNode.prototype.toString = function() {
1685    return "MenuNode (" + this.index + ") " + this.label;
1686};
1687
1688/**
1689 * This implementation takes either a string or object for the
1690 * oData argument.  If is it a string, we will use it for the display
1691 * of this node (and it can contain any html code).  If the parameter
1692 * is an object, we look for a parameter called "html" that will be
1693 * used for this node's display.
1694 *
1695 * @extends YAHOO.widget.Node
1696 * @constructor
1697 * @param oData {object} a string or object containing the data that will
1698 * be used to render this node
1699 * @param oParent {YAHOO.widget.Node} this node's parent node
1700 * @param expanded {boolean} the initial expanded/collapsed state
1701 * @param hasIcon {boolean} specifies whether or not leaf nodes should
1702 * have an icon
1703 */
1704YAHOO.widget.HTMLNode = function(oData, oParent, expanded, hasIcon) {
1705    if (oData) {
1706        this.init(oData, oParent, expanded);
1707        this.initContent(oData, hasIcon);
1708    }
1709};
1710
1711YAHOO.widget.HTMLNode.prototype = new YAHOO.widget.Node();
1712
1713/**
1714 * The CSS class for the html content container.  Defaults to ygtvhtml, but
1715 * can be overridden to provide a custom presentation for a specific node.
1716 *
1717 * @type string
1718 */
1719YAHOO.widget.HTMLNode.prototype.contentStyle = "ygtvhtml";
1720
1721/**
1722 * The generated id that will contain the data passed in by the implementer.
1723 *
1724 * @type string
1725 */
1726YAHOO.widget.HTMLNode.prototype.contentElId = null;
1727
1728/**
1729 * The HTML content to use for this node's display
1730 *
1731 * @type string
1732 */
1733YAHOO.widget.HTMLNode.prototype.content = null;
1734
1735/**
1736 * Sets up the node label
1737 *
1738 * @param {object} An html string or object containing an html property
1739 * @param {boolean} hasIcon determines if the node will be rendered with an
1740 * icon or not
1741 */
1742YAHOO.widget.HTMLNode.prototype.initContent = function(oData, hasIcon) {
1743    if (typeof oData == "string") {
1744        oData = { html: oData };
1745    }
1746
1747    this.html = oData.html;
1748    this.contentElId = "ygtvcontentel" + this.index;
1749    this.hasIcon = hasIcon;
1750
1751    /**
1752     * @private
1753     */
1754};
1755
1756/**
1757 * Returns the outer html element for this node's content
1758 *
1759 * @return {HTMLElement} the element
1760 */
1761YAHOO.widget.HTMLNode.prototype.getContentEl = function() {
1762    return document.getElementById(this.contentElId);
1763};
1764
1765// overrides YAHOO.widget.Node
1766YAHOO.widget.HTMLNode.prototype.getNodeHtml = function() {
1767    var sb = [];
1768
1769    sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
1770    sb[sb.length] = '<tr>';
1771   
1772    for (i=0;i<this.depth;++i) {
1773        sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '">&#160;</td>';
1774    }
1775
1776    if (this.hasIcon) {
1777        sb[sb.length] = '<td';
1778        sb[sb.length] = ' id="' + this.getToggleElId() + '"';
1779        sb[sb.length] = ' class="' + this.getStyle() + '"';
1780        sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '"';
1781        if (this.hasChildren(true)) {
1782            sb[sb.length] = ' onmouseover="this.className=';
1783            sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
1784            sb[sb.length] = this.tree.id + '\',' + this.index +  ').getHoverStyle()"';
1785            sb[sb.length] = ' onmouseout="this.className=';
1786            sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
1787            sb[sb.length] = this.tree.id + '\',' + this.index +  ').getStyle()"';
1788        }
1789        sb[sb.length] = '>&#160;</td>';
1790    }
1791
1792    sb[sb.length] = '<td';
1793    sb[sb.length] = ' id="' + this.contentElId + '"';
1794    sb[sb.length] = ' class="' + this.contentStyle + '"';
1795    sb[sb.length] = ' >';
1796    sb[sb.length] = this.html;
1797    sb[sb.length] = '</td>';
1798    sb[sb.length] = '</tr>';
1799    sb[sb.length] = '</table>';
1800
1801    return sb.join("");
1802};
1803
1804YAHOO.widget.HTMLNode.prototype.toString = function() {
1805    return "HTMLNode (" + this.index + ")";
1806};
1807
1808/**
1809 * A static factory class for tree view expand/collapse animations
1810 *
1811 * @constructor
1812 */
1813YAHOO.widget.TVAnim = function() {
1814    return {
1815        /**
1816         * Constant for the fade in animation
1817         *
1818         * @type string
1819         */
1820        FADE_IN: "TVFadeIn",
1821
1822        /**
1823         * Constant for the fade out animation
1824         *
1825         * @type string
1826         */
1827        FADE_OUT: "TVFadeOut",
1828
1829        /**
1830         * Returns a ygAnim instance of the given type
1831         *
1832         * @param type {string} the type of animation
1833         * @param el {HTMLElement} the element to element (probably the children div)
1834         * @param callback {function} function to invoke when the animation is done.
1835         * @return {YAHOO.util.Animation} the animation instance
1836         */
1837        getAnim: function(type, el, callback) {
1838            if (YAHOO.widget[type]) {
1839                return new YAHOO.widget[type](el, callback);
1840            } else {
1841                return null;
1842            }
1843        },
1844
1845        /**
1846         * Returns true if the specified animation class is available
1847         *
1848         * @param type {string} the type of animation
1849         * @return {boolean} true if valid, false if not
1850         */
1851        isValid: function(type) {
1852            return (YAHOO.widget[type]);
1853        }
1854    };
1855} ();
1856
1857/**
1858 * A 1/2 second fade-in animation.
1859 *
1860 * @constructor
1861 * @param el {HTMLElement} the element to animate
1862 * @param callback {function} function to invoke when the animation is finished
1863 */
1864YAHOO.widget.TVFadeIn = function(el, callback) {
1865    /**
1866     * The element to animate
1867     * @type HTMLElement
1868     */
1869    this.el = el;
1870
1871    /**
1872     * the callback to invoke when the animation is complete
1873     *
1874     * @type function
1875     */
1876    this.callback = callback;
1877
1878    /**
1879     * @private
1880     */
1881};
1882
1883/**
1884 * Performs the animation
1885 */
1886YAHOO.widget.TVFadeIn.prototype = {
1887    animate: function() {
1888        var tvanim = this;
1889
1890        var s = this.el.style;
1891        s.opacity = 0.1;
1892        s.filter = "alpha(opacity=10)";
1893        s.display = "";
1894
1895        // var dur = ( navigator.userAgent.match(/msie/gi) ) ? 0.05 : 0.4;
1896        var dur = 0.4;
1897        // var a = new ygAnim_Fade(this.el, dur, 1);
1898        // a.setStart(0.1);
1899        // a.onComplete = function() { tvanim.onComplete(); };
1900
1901        // var a = new YAHOO.util.Anim(this.el, 'opacity', 0.1, 1);
1902        var a = new YAHOO.util.Anim(this.el, {opacity: {from: 0.1, to: 1, unit:""}}, dur);
1903        a.onComplete.subscribe( function() { tvanim.onComplete(); } );
1904        a.animate();
1905    },
1906
1907    /**
1908     * Clean up and invoke callback
1909     */
1910    onComplete: function() {
1911        this.callback();
1912    },
1913
1914    toString: function() {
1915        return "TVFadeIn";
1916    }
1917};
1918
1919/**
1920 * A 1/2 second fade out animation.
1921 *
1922 * @constructor
1923 * @param el {HTMLElement} the element to animate
1924 * @param callback {Function} function to invoke when the animation is finished
1925 */
1926YAHOO.widget.TVFadeOut = function(el, callback) {
1927    /**
1928     * The element to animate
1929     * @type HTMLElement
1930     */
1931    this.el = el;
1932
1933    /**
1934     * the callback to invoke when the animation is complete
1935     *
1936     * @type function
1937     */
1938    this.callback = callback;
1939
1940    /**
1941     * @private
1942     */
1943};
1944
1945/**
1946 * Performs the animation
1947 */
1948YAHOO.widget.TVFadeOut.prototype = {
1949    animate: function() {
1950        var tvanim = this;
1951        // var dur = ( navigator.userAgent.match(/msie/gi) ) ? 0.05 : 0.4;
1952        var dur = 0.4;
1953        // var a = new ygAnim_Fade(this.el, dur, 0.1);
1954        // a.onComplete = function() { tvanim.onComplete(); };
1955
1956        // var a = new YAHOO.util.Anim(this.el, 'opacity', 1, 0.1);
1957        var a = new YAHOO.util.Anim(this.el, {opacity: {from: 1, to: 0.1, unit:""}}, dur);
1958        a.onComplete.subscribe( function() { tvanim.onComplete(); } );
1959        a.animate();
1960    },
1961
1962    /**
1963     * Clean up and invoke callback
1964     */
1965    onComplete: function() {
1966        var s = this.el.style;
1967        s.display = "none";
1968        // s.opacity = 1;
1969        s.filter = "alpha(opacity=100)";
1970        this.callback();
1971    },
1972
1973    toString: function() {
1974        return "TVFadeOut";
1975    }
1976};
1977
Note: See TracBrowser for help on using the repository browser.