source: temp/branches/ec-cube-beta/html/test/kakinaka/js/treeview/treeview.js @ 11387

Revision 11387, 52.6 KB checked in by kaki, 18 years ago (diff)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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   
507   
508    YAHOO.widget.TreeView.getNode('treeDiv1',1).toggle();
509   
510    return (t) ? t.getNodeByIndex(nodeIndex) : null;
511};
512
513/**
514 * Adds an event.  Replace with event manager when available
515 *
516 * @param el the elment to bind the handler to
517 * @param {string} sType the type of event handler
518 * @param {function} fn the callback to invoke
519 * @param {boolean} capture if true event is capture phase, bubble otherwise
520 */
521YAHOO.widget.TreeView.addHandler = function (el, sType, fn, capture) {
522    capture = (capture) ? true : false;
523    if (el.addEventListener) {
524        el.addEventListener(sType, fn, capture);
525    } else if (el.attachEvent) {
526        el.attachEvent("on" + sType, fn);
527    } else {
528        el["on" + sType] = fn;
529    }
530};
531
532/**
533 * Attempts to preload the images defined in the styles used to draw the tree by
534 * rendering off-screen elements that use the styles.
535 */
536YAHOO.widget.TreeView.preload = function(prefix) {
537    prefix = prefix || "ygtv";
538    var styles = ["tn","tm","tmh","tp","tph","ln","lm","lmh","lp","lph","loading"];
539
540    var sb = [];
541   
542    for (var i = 0; i < styles.length; ++i) {
543        sb[sb.length] = '<span class="' + prefix + styles[i] + '">&#160;</span>';
544    }
545
546    var f = document.createElement("DIV");
547    var s = f.style;
548    s.position = "absolute";
549    s.top = "-1000px";
550    s.left = "-1000px";
551    f.innerHTML = sb.join("");
552
553    document.body.appendChild(f);
554};
555
556YAHOO.widget.TreeView.addHandler(window,
557                "load", YAHOO.widget.TreeView.preload);
558
559/**
560 * The base class for all tree nodes.  The node's presentation and behavior in
561 * response to mouse events is handled in Node subclasses.
562 *
563 * @param oData {object} a string or object containing the data that will
564 * be used to render this node
565 * @param oParent {Node} this node's parent node
566 * @param expanded {boolean} the initial expanded/collapsed state
567 * @constructor
568 */
569YAHOO.widget.Node = function(oData, oParent, expanded) {
570    if (oData) { this.init(oData, oParent, expanded); }
571};
572
573YAHOO.widget.Node.prototype = {
574
575    /**
576     * The index for this instance obtained from global counter in YAHOO.widget.TreeView.
577     *
578     * @type int
579     */
580    index: 0,
581
582    /**
583     * This node's child node collection.
584     *
585     * @type Node[]
586     */
587    children: null,
588
589    /**
590     * Tree instance this node is part of
591     *
592     * @type TreeView
593     */
594    tree: null,
595
596    /**
597     * The data linked to this node.  This can be any object or primitive
598     * value, and the data can be used in getNodeHtml().
599     *
600     * @type object
601     */
602    data: null,
603
604    /**
605     * Parent node
606     *
607     * @type Node
608     */
609    parent: null,
610
611    /**
612     * The depth of this node.  We start at -1 for the root node.
613     *
614     * @type int
615     */
616    depth: -1,
617
618    /**
619     * The href for the node's label.  If one is not specified, the href will
620     * be set so that it toggles the node.
621     *
622     * @type string
623     */
624    href: null,
625
626    /**
627     * The label href target, defaults to current window
628     *
629     * @type string
630     */
631    target: "_self",
632
633    /**
634     * The node's expanded/collapsed state
635     *
636     * @type boolean
637     */
638    expanded: false,
639
640    /**
641     * Can multiple children be expanded at once?
642     *
643     * @type boolean
644     */
645    multiExpand: true,
646
647    /**
648     * Should we render children for a collapsed node?  It is possible that the
649     * implementer will want to render the hidden data...  @todo verify that we
650     * need this, and implement it if we do.
651     *
652     * @type boolean
653     */
654    renderHidden: false,
655
656    /**
657     * This flag is set to true when the html is generated for this node's
658     * children, and set to false when new children are added.
659     * @type boolean
660     */
661    childrenRendered: false,
662
663    /**
664     * Dynamically loaded nodes only fetch the data the first time they are
665     * expanded.  This flag is set to true once the data has been fetched.
666     * @type boolean
667     */
668    dynamicLoadComplete: false,
669
670    /**
671     * This node's previous sibling
672     *
673     * @type Node
674     */
675    previousSibling: null,
676
677    /**
678     * This node's next sibling
679     *
680     * @type Node
681     */
682    nextSibling: null,
683
684    /**
685     * We can set the node up to call an external method to get the child
686     * data dynamically.
687     *
688     * @type boolean
689     * @private
690     */
691    _dynLoad: false,
692
693    /**
694     * Function to execute when we need to get this node's child data.
695     *
696     * @type function
697     */
698    dataLoader: null,
699
700    /**
701     * This is true for dynamically loading nodes while waiting for the
702     * callback to return.
703     *
704     * @type boolean
705     */
706    isLoading: false,
707
708    /**
709     * The toggle/branch icon will not show if this is set to false.  This
710     * could be useful if the implementer wants to have the child contain
711     * extra info about the parent, rather than an actual node.
712     *
713     * @type boolean
714     */
715    hasIcon: true,
716
717    /**
718     * Used to configure what happens when a dynamic load node is expanded
719     * and we discover that it does not have children.  By default, it is
720     * treated as if it still could have children (plus/minus icon).  Set
721     * iconMode to have it display like a leaf node instead.
722     * @type int
723     */
724    iconMode: 0,
725
726    /**
727     * The node type
728     * @private
729     */
730    _type: "Node",
731
732    /*
733    spacerPath: "http://us.i1.yimg.com/us.yimg.com/i/space.gif",
734    expandedText: "Expanded",
735    collapsedText: "Collapsed",
736    loadingText: "Loading",
737    */
738
739    /**
740     * Initializes this node, gets some of the properties from the parent
741     *
742     * @param oData {object} a string or object containing the data that will
743     * be used to render this node
744     * @param oParent {Node} this node's parent node
745     * @param expanded {boolean} the initial expanded/collapsed state
746     */
747    init: function(oData, oParent, expanded, index) {
748        this.data       = oData;
749        this.children   = [];
750       
751        if(typeof index == "number"){
752            this.index      = index;
753        }else{
754            this.index      = YAHOO.widget.TreeView.nodeCount;
755            ++YAHOO.widget.TreeView.nodeCount;
756        }
757        this.expanded   = expanded;
758       
759
760        // oParent should never be null except when we create the root node.
761        if (oParent) {
762            this.parent_id = oParent.index
763            oParent.appendChild(this);
764        }
765    },
766
767    /**
768     * Certain properties for the node cannot be set until the parent
769     * is known. This is called after the node is inserted into a tree.
770     * the parent is also applied to this node's children in order to
771     * make it possible to move a branch from one tree to another.
772     * @param {Node} parentNode this node's parent node
773     * @return {boolean} true if the application was successful
774     */
775    applyParent: function(parentNode) {
776        if (!parentNode) {
777            return false;
778        }
779
780        this.tree   = parentNode.tree;
781        this.parent = parentNode;
782        this.depth  = parentNode.depth + 1;
783
784        if (! this.href) {
785            this.href = "javascript:" + this.getToggleLink();
786        }
787
788        if (! this.multiExpand) {
789            this.multiExpand = parentNode.multiExpand;
790        }
791
792        this.tree.regNode(this);
793        parentNode.childrenRendered = false;
794
795        // cascade update existing children
796        for (var i=0, len=this.children.length;i<len;++i) {
797            this.children[i].applyParent(this);
798        }
799
800        return true;
801    },
802
803    /**
804     * Appends a node to the child collection.
805     *
806     * @param childNode {Node} the new node
807     * @return {Node} the child node
808     * @private
809     */
810    appendChild: function(childNode) {
811        if (this.hasChildren()) {
812            var sib = this.children[this.children.length - 1];
813            sib.nextSibling = childNode;
814            childNode.previousSibling = sib;
815        }
816        this.children[this.children.length] = childNode;
817        childNode.applyParent(this);
818
819        return childNode;
820    },
821
822    /**
823     * Appends this node to the supplied node's child collection
824     * @param parentNode {Node} the node to append to.
825     * @return {Node} The appended node
826     */
827    appendTo: function(parentNode) {
828        return parentNode.appendChild(this);
829    },
830
831    /**
832    * Inserts this node before this supplied node
833    *
834    * @param node {Node} the node to insert this node before
835    * @return {Node} the inserted node
836    */
837    insertBefore: function(node) {
838        var p = node.parent;
839        if (p) {
840
841            if (this.tree) {
842                this.tree.popNode(this);
843            }
844
845            var refIndex = node.isChildOf(p);
846            p.children.splice(refIndex, 0, this);
847            if (node.previousSibling) {
848                node.previousSibling.nextSibling = this;
849            }
850            this.previousSibling = node.previousSibling;
851            this.nextSibling = node;
852            node.previousSibling = this;
853
854            this.applyParent(p);
855        }
856
857        return this;
858    },
859 
860    /**
861    * Inserts this node after the supplied node
862    *
863    * @param node {Node} the node to insert after
864    * @return {Node} the inserted node
865    */
866    insertAfter: function(node) {
867        var p = node.parent;
868        if (p) {
869
870            if (this.tree) {
871                this.tree.popNode(this);
872            }
873
874            var refIndex = node.isChildOf(p);
875
876            if (!node.nextSibling) {
877                return this.appendTo(p);
878            }
879
880            p.children.splice(refIndex + 1, 0, this);
881
882            node.nextSibling.previousSibling = this;
883            this.previousSibling = node;
884            this.nextSibling = node.nextSibling;
885            node.nextSibling = this;
886
887            this.applyParent(p);
888        }
889
890        return this;
891    },
892
893    /**
894    * Returns true if the Node is a child of supplied Node
895    *
896    * @param parentNode {Node} the Node to check
897    * @return {boolean} The node index if this Node is a child of
898    *                   supplied Node, else -1.
899    * @private
900    */
901    isChildOf: function(parentNode) {
902        if (parentNode && parentNode.children) {
903            for (var i=0, len=parentNode.children.length; i<len ; ++i) {
904                if (parentNode.children[i] === this) {
905                    return i;
906                }
907            }
908        }
909
910        return -1;
911    },
912
913    /**
914     * Returns a node array of this node's siblings, null if none.
915     *
916     * @return Node[]
917     */
918    getSiblings: function() {
919        return this.parent.children;
920    },
921
922    /**
923     * Shows this node's children
924     */
925    showChildren: function() {
926        if (!this.tree.animateExpand(this.getChildrenEl())) {
927            if (this.hasChildren()) {
928                this.getChildrenEl().style.display = "";
929            }
930        }
931    },
932
933    /**
934     * Hides this node's children
935     */
936    hideChildren: function() {
937
938        if (!this.tree.animateCollapse(this.getChildrenEl())) {
939            this.getChildrenEl().style.display = "none";
940        }
941    },
942
943    /**
944     * Returns the id for this node's container div
945     *
946     * @return {string} the element id
947     */
948    getElId: function() {
949        return "ygtv" + this.index;
950    },
951
952    /**
953     * Returns the id for this node's children div
954     *
955     * @return {string} the element id for this node's children div
956     */
957    getChildrenElId: function() {
958        return "ygtvc" + this.index;
959    },
960
961    /**
962     * Returns the id for this node's toggle element
963     *
964     * @return {string} the toggel element id
965     */
966    getToggleElId: function() {
967        return "ygtvt" + this.index;
968    },
969
970    /**
971     * Returns the id for this node's spacer image.  The spacer is positioned
972     * over the toggle and provides feedback for screen readers.
973     * @return {string} the id for the spacer image
974     */
975    /*
976    getSpacerId: function() {
977        return "ygtvspacer" + this.index;
978    },
979    */
980
981    /**
982     * Returns this node's container html element
983     * @return {HTMLElement} the container html element
984     */
985    getEl: function() {
986        return document.getElementById(this.getElId());
987    },
988
989    /**
990     * Returns the div that was generated for this node's children
991     * @return {HTMLElement} this node's children div
992     */
993    getChildrenEl: function() {
994        return document.getElementById(this.getChildrenElId());
995    },
996
997    /**
998     * Returns the element that is being used for this node's toggle.
999     * @return {HTMLElement} this node's toggle html element
1000     */
1001    getToggleEl: function() {
1002        return document.getElementById(this.getToggleElId());
1003    },
1004
1005    /**
1006     * Returns the element that is being used for this node's spacer.
1007     * @return {HTMLElement} this node's spacer html element
1008     */
1009    /*
1010    getSpacer: function() {
1011        return document.getElementById( this.getSpacerId() ) || {};
1012    },
1013    */
1014
1015    /*
1016    getStateText: function() {
1017        if (this.isLoading) {
1018            return this.loadingText;
1019        } else if (this.hasChildren(true)) {
1020            if (this.expanded) {
1021                return this.expandedText;
1022            } else {
1023                return this.collapsedText;
1024            }
1025        } else {
1026            return "";
1027        }
1028    },
1029    */
1030
1031    /**
1032     * Generates the link that will invoke this node's toggle method
1033     * @return {string} the javascript url for toggling this node
1034     */
1035    getToggleLink: function() {
1036        return "YAHOO.widget.TreeView.getNode(\'" + this.tree.id + "\'," +
1037            this.index + ").toggle()";
1038    },
1039
1040    /**
1041     * Hides this nodes children (creating them if necessary), changes the
1042     * toggle style.
1043     */
1044    collapse: function() {
1045        // Only collapse if currently expanded
1046        if (!this.expanded) { return; }
1047
1048        // fire the collapse event handler
1049        var ret = this.tree.onCollapse(this);
1050
1051        if ("undefined" != typeof ret && !ret) {
1052            return;
1053        }
1054
1055        if (!this.getEl()) {
1056            this.expanded = false;
1057            return;
1058        }
1059
1060        // hide the child div
1061        this.hideChildren();
1062        this.expanded = false;
1063
1064        if (this.hasIcon) {
1065            this.getToggleEl().className = this.getStyle();
1066        }
1067
1068        // this.getSpacer().title = this.getStateText();
1069
1070    },
1071
1072    /**
1073     * Shows this nodes children (creating them if necessary), changes the
1074     * toggle style, and collapses its siblings if multiExpand is not set.
1075     */
1076    expand: function() {
1077        // Only expand if currently collapsed.
1078        if (this.expanded) { return; }
1079
1080        // fire the expand event handler
1081        var ret = this.tree.onExpand(this);
1082
1083        if ("undefined" != typeof ret && !ret) {
1084            return;
1085        }
1086
1087        if (!this.getEl()) {
1088            this.expanded = true;
1089            return;
1090        }
1091
1092        if (! this.childrenRendered) {
1093            this.getChildrenEl().innerHTML = this.renderChildren();
1094        } else {
1095        }
1096
1097        this.expanded = true;
1098        if (this.hasIcon) {
1099            this.getToggleEl().className = this.getStyle();
1100        }
1101
1102        // this.getSpacer().title = this.getStateText();
1103
1104        // We do an extra check for children here because the lazy
1105        // load feature can expose nodes that have no children.
1106
1107        // if (!this.hasChildren()) {
1108        if (this.isLoading) {
1109            this.expanded = false;
1110            return;
1111        }
1112
1113        if (! this.multiExpand) {
1114            var sibs = this.getSiblings();
1115            for (var i=0; i<sibs.length; ++i) {
1116                if (sibs[i] != this && sibs[i].expanded) {
1117                    sibs[i].collapse();
1118                }
1119            }
1120        }
1121
1122        this.showChildren();
1123    },
1124
1125    /**
1126     * Returns the css style name for the toggle
1127     *
1128     * @return {string} the css class for this node's toggle
1129     */
1130    getStyle: function() {
1131        if (this.isLoading) {
1132            return "ygtvloading";
1133        } else {
1134            // location top or bottom, middle nodes also get the top style
1135            var loc = (this.nextSibling) ? "t" : "l";
1136
1137            // type p=plus(expand), m=minus(collapase), n=none(no children)
1138            var type = "n";
1139            if (this.hasChildren(true) || (this.isDynamic() && !this.getIconMode())) {
1140            // if (this.hasChildren(true)) {
1141                type = (this.expanded) ? "m" : "p";
1142            }
1143
1144            return "ygtv" + loc + type;
1145        }
1146    },
1147
1148    /**
1149     * Returns the hover style for the icon
1150     * @return {string} the css class hover state
1151     */
1152    getHoverStyle: function() {
1153        var s = this.getStyle();
1154        if (this.hasChildren(true) && !this.isLoading) {
1155            s += "h";
1156        }
1157        return s;
1158    },
1159
1160    /**
1161     * Recursively expands all of this node's children.
1162     */
1163    expandAll: function() {
1164        for (var i=0;i<this.children.length;++i) {
1165            var c = this.children[i];
1166            if (c.isDynamic()) {
1167                alert("Not supported (lazy load + expand all)");
1168                break;
1169            } else if (! c.multiExpand) {
1170                alert("Not supported (no multi-expand + expand all)");
1171                break;
1172            } else {
1173                c.expand();
1174                c.expandAll();
1175            }
1176        }
1177    },
1178
1179    /**
1180     * Recursively collapses all of this node's children.
1181     */
1182    collapseAll: function() {
1183        for (var i=0;i<this.children.length;++i) {
1184            this.children[i].collapse();
1185            this.children[i].collapseAll();
1186        }
1187    },
1188
1189    /**
1190     * Configures this node for dynamically obtaining the child data
1191     * when the node is first expanded.  Calling it without the callback
1192     * will turn off dynamic load for the node.
1193     *
1194     * @param fmDataLoader {function} the function that will be used to get the data.
1195     * @param iconMode {int} configures the icon that is displayed when a dynamic
1196     * load node is expanded the first time without children.  By default, the
1197     * "collapse" icon will be used.  If set to 1, the leaf node icon will be
1198     * displayed.
1199     */
1200    setDynamicLoad: function(fnDataLoader, iconMode) {
1201        if (fnDataLoader) {
1202            this.dataLoader = fnDataLoader;
1203            this._dynLoad = true;
1204        } else {
1205            this.dataLoader = null;
1206            this._dynLoad = false;
1207        }
1208
1209        if (iconMode) {
1210            this.iconMode = iconMode;
1211        }
1212    },
1213
1214    /**
1215     * Evaluates if this node is the root node of the tree
1216     *
1217     * @return {boolean} true if this is the root node
1218     */
1219    isRoot: function() {
1220        return (this == this.tree.root);
1221    },
1222
1223    /**
1224     * Evaluates if this node's children should be loaded dynamically.  Looks for
1225     * the property both in this instance and the root node.  If the tree is
1226     * defined to load all children dynamically, the data callback function is
1227     * defined in the root node
1228     *
1229     * @return {boolean} true if this node's children are to be loaded dynamically
1230     */
1231    isDynamic: function() {
1232        var lazy = (!this.isRoot() && (this._dynLoad || this.tree.root._dynLoad));
1233        return lazy;
1234    },
1235
1236    getIconMode: function() {
1237        return (this.iconMode || this.tree.root.iconMode);
1238    },
1239
1240    /**
1241     * Checks if this node has children.  If this node is lazy-loading and the
1242     * children have not been rendered, we do not know whether or not there
1243     * are actual children.  In most cases, we need to assume that there are
1244     * children (for instance, the toggle needs to show the expandable
1245     * presentation state).  In other times we want to know if there are rendered
1246     * children.  For the latter, "checkForLazyLoad" should be false.
1247     *
1248     * @param checkForLazyLoad {boolean} should we check for unloaded children?
1249     * @return {boolean} true if this has children or if it might and we are
1250     * checking for this condition.
1251     */
1252    hasChildren: function(checkForLazyLoad) {
1253        return ( this.children.length > 0 ||
1254                (checkForLazyLoad && this.isDynamic() && !this.dynamicLoadComplete) );
1255    },
1256
1257    /**
1258     * Expands if node is collapsed, collapses otherwise.
1259     */
1260    toggle: function() {
1261        if (!this.tree.locked && ( this.hasChildren(true) || this.isDynamic()) ) {
1262            if (this.expanded) { this.collapse(); } else { this.expand(); }
1263        }
1264    },
1265
1266    /**
1267     * Returns the markup for this node and its children.
1268     *
1269     * @return {string} the markup for this node and its expanded children.
1270     */
1271    getHtml: function() {
1272        var sb = [];
1273        sb[sb.length] = '<div class="ygtvitem" id="' + this.getElId() + '">';
1274        sb[sb.length] = this.getNodeHtml();
1275        sb[sb.length] = this.getChildrenHtml();
1276        sb[sb.length] = '</div>';
1277        return sb.join("");
1278    },
1279
1280    /**
1281     * Called when first rendering the tree.  We always build the div that will
1282     * contain this nodes children, but we don't render the children themselves
1283     * unless this node is expanded.
1284     *
1285     * @return {string} the children container div html and any expanded children
1286     * @private
1287     */
1288    getChildrenHtml: function() {
1289
1290        var sb = [];
1291        sb[sb.length] = '<div class="ygtvchildren"';
1292        sb[sb.length] = ' id="' + this.getChildrenElId() + '"';
1293        if (!this.expanded) {
1294            sb[sb.length] = ' style="display:none;"';
1295        }
1296        sb[sb.length] = '>';
1297
1298        // Don't render the actual child node HTML unless this node is expanded.
1299        if ( (this.hasChildren(true) && this.expanded) ||
1300                (this.renderHidden && !this.isDynamic()) ) {
1301            sb[sb.length] = this.renderChildren();
1302        }
1303
1304        sb[sb.length] = '</div>';
1305
1306        return sb.join("");
1307    },
1308
1309    /**
1310     * Generates the markup for the child nodes.  This is not done until the node
1311     * is expanded.
1312     *
1313     * @return {string} the html for this node's children
1314     * @private
1315     */
1316    renderChildren: function() {
1317
1318
1319        var node = this;
1320
1321        if (this.isDynamic() && !this.dynamicLoadComplete) {
1322            this.isLoading = true;
1323            this.tree.locked = true;
1324
1325            if (this.dataLoader) {
1326
1327                setTimeout(
1328                    function() {
1329                        node.dataLoader(node,
1330                            function() {
1331                                node.loadComplete();
1332                            });
1333                    }, 10);
1334               
1335            } else if (this.tree.root.dataLoader) {
1336
1337                setTimeout(
1338                    function() {
1339                        node.tree.root.dataLoader(node,
1340                            function() {
1341                                node.loadComplete();
1342                            });
1343                    }, 10);
1344
1345            } else {
1346                return "Error: data loader not found or not specified.";
1347            }
1348
1349            return "";
1350
1351        } else {
1352            return this.completeRender();
1353        }
1354    },
1355
1356    /**
1357     * Called when we know we have all the child data.
1358     * @return {string} children html
1359     */
1360    completeRender: function() {
1361        var sb = [];
1362
1363        for (var i=0; i < this.children.length; ++i) {
1364            this.children[i].childrenRendered = false;
1365            sb[sb.length] = this.children[i].getHtml();
1366        }
1367       
1368        this.childrenRendered = true;
1369
1370        return sb.join("");
1371    },
1372
1373    /**
1374     * Load complete is the callback function we pass to the data provider
1375     * in dynamic load situations.
1376     */
1377    loadComplete: function() {
1378        this.getChildrenEl().innerHTML = this.completeRender();
1379        this.dynamicLoadComplete = true;
1380        this.isLoading = false;
1381        this.expand();
1382        this.tree.locked = false;
1383    },
1384
1385    /**
1386     * Returns this node's ancestor at the specified depth.
1387     *
1388     * @param {int} depth the depth of the ancestor.
1389     * @return {Node} the ancestor
1390     */
1391    getAncestor: function(depth) {
1392        if (depth >= this.depth || depth < 0)  {
1393            return null;
1394        }
1395
1396        var p = this.parent;
1397       
1398        while (p.depth > depth) {
1399            p = p.parent;
1400        }
1401
1402        return p;
1403    },
1404
1405    /**
1406     * Returns the css class for the spacer at the specified depth for
1407     * this node.  If this node's ancestor at the specified depth
1408     * has a next sibling the presentation is different than if it
1409     * does not have a next sibling
1410     *
1411     * @param {int} depth the depth of the ancestor.
1412     * @return {string} the css class for the spacer
1413     */
1414    getDepthStyle: function(depth) {
1415        return (this.getAncestor(depth).nextSibling) ?
1416            "ygtvdepthcell" : "ygtvblankdepthcell";
1417    },
1418
1419    /**
1420     * Get the markup for the node.  This is designed to be overrided so that we can
1421     * support different types of nodes.
1422     *
1423     * @return {string} The HTML that will render this node.
1424     */
1425    getNodeHtml: function() {
1426        return "";
1427    },
1428
1429    /**
1430     * Regenerates the html for this node and its children.  To be used when the
1431     * node is expanded and new children have been added.
1432     */
1433    refresh: function() {
1434        // this.loadComplete();
1435        this.getChildrenEl().innerHTML = this.completeRender();
1436
1437        if (this.hasIcon) {
1438            var el = this.getToggleEl();
1439            if (el) {
1440                el.className = this.getStyle();
1441            }
1442        }
1443    },
1444
1445    /**
1446     * toString
1447     * @return {string} string representation of the node
1448     */
1449    toString: function() {
1450        return "Node (" + this.index + ")";
1451    }
1452
1453};
1454
1455/**
1456 * A custom YAHOO.widget.Node that handles the unique nature of
1457 * the virtual, presentationless root node.
1458 *
1459 * @extends YAHOO.widget.Node
1460 * @constructor
1461 */
1462YAHOO.widget.RootNode = function(oTree) {
1463    // Initialize the node with null params.  The root node is a
1464    // special case where the node has no presentation.  So we have
1465    // to alter the standard properties a bit.
1466    this.init(null, null, true);
1467   
1468    /**
1469     * For the root node, we get the tree reference from as a param
1470     * to the constructor instead of from the parent element.
1471     *
1472     * @type TreeView
1473     */
1474    this.tree = oTree;
1475};
1476
1477YAHOO.widget.RootNode.prototype = new YAHOO.widget.Node();
1478
1479// overrides YAHOO.widget.Node
1480YAHOO.widget.RootNode.prototype.getNodeHtml = function() {
1481    return "";
1482};
1483
1484YAHOO.widget.RootNode.prototype.toString = function() {
1485    return "RootNode";
1486};
1487
1488YAHOO.widget.RootNode.prototype.loadComplete = function() {
1489    this.tree.draw();
1490};
1491/**
1492 * The default node presentation.  The first parameter should be
1493 * either a string that will be used as the node's label, or an object
1494 * that has a string propery called label.  By default, the clicking the
1495 * label will toggle the expanded/collapsed state of the node.  By
1496 * changing the href property of the instance, this behavior can be
1497 * changed so that the label will go to the specified href.
1498 *
1499 * @extends YAHOO.widget.Node
1500 * @constructor
1501 * @param oData {object} a string or object containing the data that will
1502 * be used to render this node
1503 * @param oParent {YAHOO.widget.Node} this node's parent node
1504 * @param expanded {boolean} the initial expanded/collapsed state
1505 */
1506YAHOO.widget.TextNode = function(oData, oParent, expanded, index) {
1507    // this.type = "TextNode";
1508
1509    if (oData) {
1510        this.init(oData, oParent, expanded, index);
1511        this.setUpLabel(oData);
1512    }
1513
1514    /**
1515     * @private
1516     */
1517};
1518
1519YAHOO.widget.TextNode.prototype = new YAHOO.widget.Node();
1520
1521/**
1522 * The CSS class for the label href.  Defaults to ygtvlabel, but can be
1523 * overridden to provide a custom presentation for a specific node.
1524 *
1525 * @type string
1526 */
1527YAHOO.widget.TextNode.prototype.labelStyle = "ygtvlabel";
1528
1529/**
1530 * The derived element id of the label for this node
1531 *
1532 * @type string
1533 */
1534YAHOO.widget.TextNode.prototype.labelElId = null;
1535
1536/**
1537 * The text for the label.  It is assumed that the oData parameter will
1538 * either be a string that will be used as the label, or an object that
1539 * has a property called "label" that we will use.
1540 *
1541 * @type string
1542 */
1543YAHOO.widget.TextNode.prototype.label = null;
1544
1545/**
1546 * Sets up the node label
1547 *
1548 * @param oData string containing the label, or an object with a label property
1549 */
1550YAHOO.widget.TextNode.prototype.setUpLabel = function(oData) {
1551    if (typeof oData == "string") {
1552        oData = { label: oData };
1553    }
1554    this.label = oData.label;
1555   
1556    // update the link
1557    if (oData.href) {
1558        this.href = oData.href;
1559    }
1560
1561    // set the target
1562    if (oData.target) {
1563        this.target = oData.target;
1564    }
1565
1566    if (oData.style) {
1567        this.labelStyle = oData.style;
1568    }
1569
1570    this.labelElId = "ygtvlabelel" + this.index;
1571};
1572
1573/**
1574 * Returns the label element
1575 *
1576 * @return {object} the element
1577 */
1578YAHOO.widget.TextNode.prototype.getLabelEl = function() {
1579    return document.getElementById(this.labelElId);
1580};
1581
1582// overrides YAHOO.widget.Node
1583YAHOO.widget.TextNode.prototype.getNodeHtml = function() {
1584    var sb = [];
1585
1586    sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
1587    sb[sb.length] = '<tr>';
1588   
1589    for (i=0;i<this.depth;++i) {
1590        // sb[sb.length] = '<td class="ygtvdepthcell">&#160;</td>';
1591        sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '">&#160;</td>';
1592    }
1593
1594    var getNode = 'YAHOO.widget.TreeView.getNode(\'' +
1595                    this.tree.id + '\',' + this.index + ')';
1596
1597    sb[sb.length] = '<td';
1598    // sb[sb.length] = ' onselectstart="return false"';
1599    sb[sb.length] = ' id="' + this.getToggleElId() + '"';
1600    sb[sb.length] = ' class="' + this.getStyle() + '"';
1601    if (this.hasChildren(true)) {
1602        sb[sb.length] = ' onmouseover="this.className=';
1603        sb[sb.length] = getNode + '.getHoverStyle()"';
1604        sb[sb.length] = ' onmouseout="this.className=';
1605        sb[sb.length] = getNode + '.getStyle()"';
1606    }
1607    sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '">';
1608
1609    /*
1610    sb[sb.length] = '<img id="' + this.getSpacerId() + '"';
1611    sb[sb.length] = ' alt=""';
1612    sb[sb.length] = ' tabindex=0';
1613    sb[sb.length] = ' src="' + this.spacerPath + '"';
1614    sb[sb.length] = ' title="' + this.getStateText() + '"';
1615    sb[sb.length] = ' class="ygtvspacer"';
1616    // sb[sb.length] = ' onkeypress="return ' + getNode + '".onKeyPress()"';
1617    sb[sb.length] = ' />';
1618    */
1619
1620    sb[sb.length] = '&#160;';
1621
1622    sb[sb.length] = '</td>';
1623    sb[sb.length] = '<td>';
1624    sb[sb.length] = '<a';
1625    sb[sb.length] = ' id="' + this.labelElId + '"';
1626    sb[sb.length] = ' class="' + this.labelStyle + '"';
1627    sb[sb.length] = ' href="' + this.href + '"';
1628    sb[sb.length] = ' target="' + this.target + '"';
1629    sb[sb.length] = ' onclick="return ' + getNode + '.onLabelClick(' + getNode +')"';
1630    if (this.hasChildren(true)) {
1631        sb[sb.length] = ' onmouseover="document.getElementById(\'';
1632        sb[sb.length] = this.getToggleElId() + '\').className=';
1633        sb[sb.length] = getNode + '.getHoverStyle()"';
1634        sb[sb.length] = ' onmouseout="document.getElementById(\'';
1635        sb[sb.length] = this.getToggleElId() + '\').className=';
1636        sb[sb.length] = getNode + '.getStyle()"';
1637    }
1638    sb[sb.length] = ' >';
1639    sb[sb.length] = this.label;
1640    sb[sb.length] = '</a>';
1641    sb[sb.length] = '</td>';
1642    sb[sb.length] = '</tr>';
1643    sb[sb.length] = '</table>';
1644
1645    return sb.join("");
1646};
1647
1648/**
1649 * Executed when the label is clicked
1650 * @param me {Node} this node
1651 * @scope the anchor tag clicked
1652 * @return false to cancel the anchor click
1653 */
1654YAHOO.widget.TextNode.prototype.onLabelClick = function(me) {
1655    //return true;
1656};
1657
1658YAHOO.widget.TextNode.prototype.toString = function() {
1659    return "TextNode (" + this.index + ") " + this.label;
1660};
1661
1662/**
1663 * A menu-specific implementation that differs from TextNode in that only
1664 * one sibling can be expanded at a time.
1665 * @extends YAHOO.widget.TextNode
1666 * @constructor
1667 */
1668YAHOO.widget.MenuNode = function(oData, oParent, expanded) {
1669    if (oData) {
1670        this.init(oData, oParent, expanded);
1671        this.setUpLabel(oData);
1672    }
1673
1674    /**
1675     * Menus usually allow only one branch to be open at a time.
1676     * @type boolean
1677     */
1678    this.multiExpand = false;
1679
1680    /**
1681     * @private
1682     */
1683
1684};
1685
1686YAHOO.widget.MenuNode.prototype = new YAHOO.widget.TextNode();
1687
1688YAHOO.widget.MenuNode.prototype.toString = function() {
1689    return "MenuNode (" + this.index + ") " + this.label;
1690};
1691
1692/**
1693 * This implementation takes either a string or object for the
1694 * oData argument.  If is it a string, we will use it for the display
1695 * of this node (and it can contain any html code).  If the parameter
1696 * is an object, we look for a parameter called "html" that will be
1697 * used for this node's display.
1698 *
1699 * @extends YAHOO.widget.Node
1700 * @constructor
1701 * @param oData {object} a string or object containing the data that will
1702 * be used to render this node
1703 * @param oParent {YAHOO.widget.Node} this node's parent node
1704 * @param expanded {boolean} the initial expanded/collapsed state
1705 * @param hasIcon {boolean} specifies whether or not leaf nodes should
1706 * have an icon
1707 */
1708YAHOO.widget.HTMLNode = function(oData, oParent, expanded, hasIcon) {
1709    if (oData) {
1710        this.init(oData, oParent, expanded);
1711        this.initContent(oData, hasIcon);
1712    }
1713};
1714
1715YAHOO.widget.HTMLNode.prototype = new YAHOO.widget.Node();
1716
1717/**
1718 * The CSS class for the html content container.  Defaults to ygtvhtml, but
1719 * can be overridden to provide a custom presentation for a specific node.
1720 *
1721 * @type string
1722 */
1723YAHOO.widget.HTMLNode.prototype.contentStyle = "ygtvhtml";
1724
1725/**
1726 * The generated id that will contain the data passed in by the implementer.
1727 *
1728 * @type string
1729 */
1730YAHOO.widget.HTMLNode.prototype.contentElId = null;
1731
1732/**
1733 * The HTML content to use for this node's display
1734 *
1735 * @type string
1736 */
1737YAHOO.widget.HTMLNode.prototype.content = null;
1738
1739/**
1740 * Sets up the node label
1741 *
1742 * @param {object} An html string or object containing an html property
1743 * @param {boolean} hasIcon determines if the node will be rendered with an
1744 * icon or not
1745 */
1746YAHOO.widget.HTMLNode.prototype.initContent = function(oData, hasIcon) {
1747    if (typeof oData == "string") {
1748        oData = { html: oData };
1749    }
1750
1751    this.html = oData.html;
1752    this.contentElId = "ygtvcontentel" + this.index;
1753    this.hasIcon = hasIcon;
1754
1755    /**
1756     * @private
1757     */
1758};
1759
1760/**
1761 * Returns the outer html element for this node's content
1762 *
1763 * @return {HTMLElement} the element
1764 */
1765YAHOO.widget.HTMLNode.prototype.getContentEl = function() {
1766    return document.getElementById(this.contentElId);
1767};
1768
1769// overrides YAHOO.widget.Node
1770YAHOO.widget.HTMLNode.prototype.getNodeHtml = function() {
1771    var sb = [];
1772
1773    sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
1774    sb[sb.length] = '<tr>';
1775   
1776    for (i=0;i<this.depth;++i) {
1777        sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '">&#160;</td>';
1778    }
1779
1780    if (this.hasIcon) {
1781        sb[sb.length] = '<td';
1782        sb[sb.length] = ' id="' + this.getToggleElId() + '"';
1783        sb[sb.length] = ' class="' + this.getStyle() + '"';
1784        sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '"';
1785        if (this.hasChildren(true)) {
1786            sb[sb.length] = ' onmouseover="this.className=';
1787            sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
1788            sb[sb.length] = this.tree.id + '\',' + this.index +  ').getHoverStyle()"';
1789            sb[sb.length] = ' onmouseout="this.className=';
1790            sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
1791            sb[sb.length] = this.tree.id + '\',' + this.index +  ').getStyle()"';
1792        }
1793        sb[sb.length] = '>&#160;</td>';
1794    }
1795
1796    sb[sb.length] = '<td';
1797    sb[sb.length] = ' id="' + this.contentElId + '"';
1798    sb[sb.length] = ' class="' + this.contentStyle + '"';
1799    sb[sb.length] = ' >';
1800    sb[sb.length] = this.html;
1801    sb[sb.length] = '</td>';
1802    sb[sb.length] = '</tr>';
1803    sb[sb.length] = '</table>';
1804
1805    return sb.join("");
1806};
1807
1808YAHOO.widget.HTMLNode.prototype.toString = function() {
1809    return "HTMLNode (" + this.index + ")";
1810};
1811
1812/**
1813 * A static factory class for tree view expand/collapse animations
1814 *
1815 * @constructor
1816 */
1817YAHOO.widget.TVAnim = function() {
1818    return {
1819        /**
1820         * Constant for the fade in animation
1821         *
1822         * @type string
1823         */
1824        FADE_IN: "TVFadeIn",
1825
1826        /**
1827         * Constant for the fade out animation
1828         *
1829         * @type string
1830         */
1831        FADE_OUT: "TVFadeOut",
1832
1833        /**
1834         * Returns a ygAnim instance of the given type
1835         *
1836         * @param type {string} the type of animation
1837         * @param el {HTMLElement} the element to element (probably the children div)
1838         * @param callback {function} function to invoke when the animation is done.
1839         * @return {YAHOO.util.Animation} the animation instance
1840         */
1841        getAnim: function(type, el, callback) {
1842            if (YAHOO.widget[type]) {
1843                return new YAHOO.widget[type](el, callback);
1844            } else {
1845                return null;
1846            }
1847        },
1848
1849        /**
1850         * Returns true if the specified animation class is available
1851         *
1852         * @param type {string} the type of animation
1853         * @return {boolean} true if valid, false if not
1854         */
1855        isValid: function(type) {
1856            return (YAHOO.widget[type]);
1857        }
1858    };
1859} ();
1860
1861/**
1862 * A 1/2 second fade-in animation.
1863 *
1864 * @constructor
1865 * @param el {HTMLElement} the element to animate
1866 * @param callback {function} function to invoke when the animation is finished
1867 */
1868YAHOO.widget.TVFadeIn = function(el, callback) {
1869    /**
1870     * The element to animate
1871     * @type HTMLElement
1872     */
1873    this.el = el;
1874
1875    /**
1876     * the callback to invoke when the animation is complete
1877     *
1878     * @type function
1879     */
1880    this.callback = callback;
1881
1882    /**
1883     * @private
1884     */
1885};
1886
1887/**
1888 * Performs the animation
1889 */
1890YAHOO.widget.TVFadeIn.prototype = {
1891    animate: function() {
1892        var tvanim = this;
1893
1894        var s = this.el.style;
1895        s.opacity = 0.1;
1896        s.filter = "alpha(opacity=10)";
1897        s.display = "";
1898
1899        // var dur = ( navigator.userAgent.match(/msie/gi) ) ? 0.05 : 0.4;
1900        var dur = 0.4;
1901        // var a = new ygAnim_Fade(this.el, dur, 1);
1902        // a.setStart(0.1);
1903        // a.onComplete = function() { tvanim.onComplete(); };
1904
1905        // var a = new YAHOO.util.Anim(this.el, 'opacity', 0.1, 1);
1906        var a = new YAHOO.util.Anim(this.el, {opacity: {from: 0.1, to: 1, unit:""}}, dur);
1907        a.onComplete.subscribe( function() { tvanim.onComplete(); } );
1908        a.animate();
1909    },
1910
1911    /**
1912     * Clean up and invoke callback
1913     */
1914    onComplete: function() {
1915        this.callback();
1916    },
1917
1918    toString: function() {
1919        return "TVFadeIn";
1920    }
1921};
1922
1923/**
1924 * A 1/2 second fade out animation.
1925 *
1926 * @constructor
1927 * @param el {HTMLElement} the element to animate
1928 * @param callback {Function} function to invoke when the animation is finished
1929 */
1930YAHOO.widget.TVFadeOut = function(el, callback) {
1931    /**
1932     * The element to animate
1933     * @type HTMLElement
1934     */
1935    this.el = el;
1936
1937    /**
1938     * the callback to invoke when the animation is complete
1939     *
1940     * @type function
1941     */
1942    this.callback = callback;
1943
1944    /**
1945     * @private
1946     */
1947};
1948
1949/**
1950 * Performs the animation
1951 */
1952YAHOO.widget.TVFadeOut.prototype = {
1953    animate: function() {
1954        var tvanim = this;
1955        // var dur = ( navigator.userAgent.match(/msie/gi) ) ? 0.05 : 0.4;
1956        var dur = 0.4;
1957        // var a = new ygAnim_Fade(this.el, dur, 0.1);
1958        // a.onComplete = function() { tvanim.onComplete(); };
1959
1960        // var a = new YAHOO.util.Anim(this.el, 'opacity', 1, 0.1);
1961        var a = new YAHOO.util.Anim(this.el, {opacity: {from: 1, to: 0.1, unit:""}}, dur);
1962        a.onComplete.subscribe( function() { tvanim.onComplete(); } );
1963        a.animate();
1964    },
1965
1966    /**
1967     * Clean up and invoke callback
1968     */
1969    onComplete: function() {
1970        var s = this.el.style;
1971        s.display = "none";
1972        // s.opacity = 1;
1973        s.filter = "alpha(opacity=100)";
1974        this.callback();
1975    },
1976
1977    toString: function() {
1978        return "TVFadeOut";
1979    }
1980};
1981
Note: See TracBrowser for help on using the repository browser.