1 line
17 KiB
JavaScript
1 line
17 KiB
JavaScript
|
|
/* Copyright (c) 2006, Yahoo! Inc. All rights reserved.Code licensed under the BSD License:http://developer.yahoo.net/yui/license.txt version: 0.12.0 */ YAHOO.widget.TreeView=function(id){if(id){this.init(id);}};YAHOO.widget.TreeView.prototype={id:null,_el:null,_nodes:null,locked:false,_expandAnim:null,_collapseAnim:null,_animCount:0,maxAnim:2,setExpandAnim:function(_2){if(YAHOO.widget.TVAnim.isValid(_2)){this._expandAnim=_2;}},setCollapseAnim:function(_3){if(YAHOO.widget.TVAnim.isValid(_3)){this._collapseAnim=_3;}},animateExpand:function(el,_5){if(this._expandAnim&&this._animCount<this.maxAnim){var _6=this;var a=YAHOO.widget.TVAnim.getAnim(this._expandAnim,el,function(){_6.expandComplete(_5);});if(a){++this._animCount;this.fireEvent("animStart",{"node":_5,"type":"expand"});a.animate();}return true;}return false;},animateCollapse:function(el,_8){if(this._collapseAnim&&this._animCount<this.maxAnim){var _9=this;var a=YAHOO.widget.TVAnim.getAnim(this._collapseAnim,el,function(){_9.collapseComplete(_8);});if(a){++this._animCount;this.fireEvent("animStart",{"node":_8,"type":"collapse"});a.animate();}return true;}return false;},expandComplete:function(_10){--this._animCount;this.fireEvent("animComplete",{"node":_10,"type":"expand"});},collapseComplete:function(_11){--this._animCount;this.fireEvent("animComplete",{"node":_11,"type":"collapse"});},init:function(id){this.id=id;if("string"!==typeof id){this._el=id;this.id=this.generateId(id);}this.createEvent("animStart",this);this.createEvent("animComplete",this);this.createEvent("collapse",this);this.createEvent("expand",this);this._nodes=[];YAHOO.widget.TreeView.trees[this.id]=this;this.root=new YAHOO.widget.RootNode(this);},draw:function(){var _12=this.root.getHtml();this.getEl().innerHTML=_12;this.firstDraw=false;},getEl:function(){if(!this._el){this._el=document.getElementById(this.id);}return this._el;},regNode:function(_13){this._nodes[_13.index]=_13;},getRoot:function(){return this.root;},setDynamicLoad:function(_14,_15){this.root.setDynamicLoad(_14,_15);},expandAll:function(){if(!this.locked){this.root.expandAll();}},collapseAll:function(){if(!this.locked){this.root.collapseAll();}},getNodeByIndex:function(_16){var n=this._nodes[_16];return (n)?n:null;},getNodeByProperty:function(_18,_19){for(var i in this._nodes){var n=this._nodes[i];if(n.data&&_19==n.data[_18]){return n;}}return null;},getNodesByProperty:function(_21,_22){var _23=[];for(var i in this._nodes){var n=this._nodes[i];if(n.data&&_22==n.data[_21]){_23.push(n);}}return (_23.length)?_23:null;},removeNode:function(_24,_25){if(_24.isRoot()){return false;}var p=_24.parent;if(p.parent){p=p.parent;}this._deleteNode(_24);if(_25&&p&&p.childrenRendered){p.refresh();}return true;},removeChildren:function(_27){while(_27.children.length){this._deleteNode(_27.children[0]);}_27.childrenRendered=false;_27.dynamicLoadComplete=false;if(_27.expanded){_27.collapse();}else{_27.updateIcon();}},_deleteNode:function(_28){this.removeChildren(_28);this.popNode(_28);},popNode:function(_29){var p=_29.parent;var a=[];for(var i=0,len=p.children.length;i<len;++i){if(p.children[i]!=_29){a[a.length]=p.children[i];}}p.children=a;p.childrenRendered=false;if(_29.previousSibling){_29.previousSibling.nextSibling=_29.nextSibling;}if(_29.nextSibling){_29.nextSibling.previousSibling=_29.previousSibling;}_29.parent=null;_29.previousSibling=null;_29.nextSibling=null;_29.tree=null;delete this._nodes[_29.index];},toString:function(){return "TreeView "+this.id;},generateId:function(el){var id=el.id;if(!id){id="yui-tv-auto-id-"+YAHOO.widget.TreeView.counter;++YAHOO.widget.TreeView.counter;}return id;},onExpand:function(_30){},onCollapse:function(_31){}};YAHOO.augment(YAHOO.widget.TreeView,YAHOO.util.EventProvider);YAHOO.widget.TreeView.nodeCount=0;YAHOO.widget.TreeView.trees=[];YAHOO.widget.TreeView.counter=0;YAHOO.widget.TreeView.getTree=function(_32){var t=YAHOO.widget.TreeView.trees[_32];return (t)?t:null;};YAHOO.widget.TreeView.getNode=function(_34,_35){var t=YAHOO.widget.TreeView.getTree(_34);return (t)?t.getNodeByIndex(_35):null;};YAHOO.widget.Tree
|