?? treeview-min.js
字號:
/* Copyright (c) 2006, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 0.10.0 */ YAHOO.widget.TreeView=function(id){if(id){this.init(id);}};YAHOO.widget.TreeView.nodeCount=0;YAHOO.widget.TreeView.prototype={id: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){if(this._expandAnim&&this._animCount<this.maxAnim){var _5=this;var a=YAHOO.widget.TVAnim.getAnim(this._expandAnim,el,function(){_5.expandComplete();});if(a){++this._animCount;a.animate();}return true;}return false;},animateCollapse:function(el){if(this._collapseAnim&&this._animCount<this.maxAnim){var _7=this;var a=YAHOO.widget.TVAnim.getAnim(this._collapseAnim,el,function(){_7.collapseComplete();});if(a){++this._animCount;a.animate();}return true;}return false;},expandComplete:function(){--this._animCount;},collapseComplete:function(){--this._animCount;},init:function(id){this.id=id;this._nodes=[];YAHOO.widget.TreeView.trees[id]=this;this.root=new YAHOO.widget.RootNode(this);},draw:function(){var _8=this.root.getHtml();document.getElementById(this.id).innerHTML=_8;this.firstDraw=false;},regNode:function(_9){this._nodes[_9.index]=_9;},getRoot:function(){return this.root;},setDynamicLoad:function(_10,_11){this.root.setDynamicLoad(_10,_11);},expandAll:function(){if(!this.locked){this.root.expandAll();}},collapseAll:function(){if(!this.locked){this.root.collapseAll();}},getNodeByIndex:function(_12){var n=this._nodes[_12];return (n)?n:null;},getNodeByProperty:function(_14,_15){for(var i in this._nodes){var n=this._nodes[i];if(n.data&&_15==n.data[_14]){return n;}}return null;},removeNode:function(_17,_18){if(_17.isRoot()){return false;}var p=_17.parent;if(p.parent){p=p.parent;}this._deleteNode(_17);if(_18&&p&&p.childrenRendered){p.refresh();}return true;},removeChildren:function(_20){for(var i=0,len=_20.children.length;i<len;++i){this._deleteNode(_20.children[i]);}_20.childrenRendered=false;_20.dynamicLoadComplete=false;_20.collapse();},_deleteNode:function(_21){var p=_21.parent;this.removeChildren(_21);var a=[];for(i=0,len=p.children.length;i<len;++i){if(p.children[i]!=_21){a[a.length]=p.children[i];}}p.children=a;p.childrenRendered=false;if(_21.previousSibling){_21.previousSibling.nextSibling=_21.nextSibling;}if(_21.nextSibling){_21.nextSibling.previousSibling=_21.previousSibling;}delete this._nodes[_21.index];},onExpand:function(_22){},onCollapse:function(_23){}};YAHOO.widget.TreeView.trees=[];YAHOO.widget.TreeView.getTree=function(_24){var t=YAHOO.widget.TreeView.trees[_24];return (t)?t:null;};YAHOO.widget.TreeView.getNode=function(_26,_27){var t=YAHOO.widget.TreeView.getTree(_26);return (t)?t.getNodeByIndex(_27):null;};YAHOO.widget.TreeView.addHandler=function(el,_28,fn,_30){_30=(_30)?true:false;if(el.addEventListener){el.addEventListener(_28,fn,_30);}else{if(el.attachEvent){el.attachEvent("on"+_28,fn);}else{el["on"+_28]=fn;}}};YAHOO.widget.TreeView.preload=function(){var _31=["ygtvtn","ygtvtm","ygtvtmh","ygtvtp","ygtvtph","ygtvln","ygtvlm","ygtvlmh","ygtvlp","ygtvlph","ygtvloading"];var sb=[];for(var i=0;i<_31.length;++i){sb[sb.length]="<span class=\""+_31[i]+"\"> </span>";}var f=document.createElement("div");var s=f.style;s.position="absolute";s.top="-1000px";s.left="-1000px";f.innerHTML=sb.join("");document.body.appendChild(f);};YAHOO.widget.TreeView.addHandler(window,"load",YAHOO.widget.TreeView.preload);YAHOO.widget.Node=function(_35,_36,_37){if(_36){this.init(_35,_36,_37);}};YAHOO.widget.Node.prototype={index:0,children:null,tree:null,data:null,parent:null,depth:-1,href:null,target:"_self",expanded:false,multiExpand:true,renderHidden:false,childrenRendered:false,dynamicLoadComplete:false,previousSibling:null,nextSibling:null,_dynLoad:false,dataLoader:null,isLoading:false,hasIcon:true,iconMode:0,_type:"Node",init:function(_38,_39,_40){this.data=_38;this.children=[];this.index=YAHOO.widget.TreeView.nodeCount;++YAHOO.widget.TreeView.nodeCount;this.expanded=_40;if(_39){this.tree=_39.tree;this.parent=_39;this.href="javascript:"+this.getToggleLink();this.depth=_39.depth+1;this.multiExpand=_39.multiExpand;_39.appendChild(this);}},appendChild:function(_41){if(this.hasChildren()){var sib=this.children[this.children.length-1];sib.nextSibling=_41;_41.previousSibling=sib;}this.tree.regNode(_41);this.children[this.children.length]=_41;this.childrenRendered=false;return _41;},getSiblings:function(){return this.parent.children;},showChildren:function(){if(!this.tree.animateExpand(this.getChildrenEl())){if(this.hasChildren()){this.getChildrenEl().style.display="";}}},hideChildren:function(){if(!this.tree.animateCollapse(this.getChildrenEl())){this.getChildrenEl().style.display="none";}},getElId:function(){return "ygtv"+this.index;},getChildrenElId:function(){return "ygtvc"+this.index;},getToggleElId:function(){return "ygtvt"+this.index;},getEl:function(){return document.getElementById(this.getElId());},getChildrenEl:function(){return document.getElementById(this.getChildrenElId());},getToggleEl:function(){return document.getElementById(this.getToggleElId());},getToggleLink:function(){return "YAHOO.widget.TreeView.getNode('"+this.tree.id+"',"+this.index+").toggle()";},collapse:function(){if(!this.expanded){return;}var ret=this.tree.onCollapse(this);if("undefined"!=typeof ret&&!ret){return;}if(!this.getEl()){this.expanded=false;return;}this.hideChildren();this.expanded=false;if(this.hasIcon){this.getToggleEl().className=this.getStyle();}},expand:function(){if(this.expanded){return;}var ret=this.tree.onExpand(this);if("undefined"!=typeof ret&&!ret){return;}if(!this.getEl()){this.expanded=true;return;}if(!this.childrenRendered){this.getChildrenEl().innerHTML=this.renderChildren();}else{}this.expanded=true;if(this.hasIcon){this.getToggleEl().className=this.getStyle();}if(this.isLoading){this.expanded=false;return;}if(!this.multiExpand){var _44=this.getSiblings();for(var i=0;i<_44.length;++i){if(_44[i]!=this&&_44[i].expanded){_44[i].collapse();}}}this.showChildren();},getStyle:function(){if(this.isLoading){return "ygtvloading";}else{var loc=(this.nextSibling)?"t":"l";var _46="n";if(this.hasChildren(true)||(this.isDynamic()&&!this.getIconMode())){_46=(this.expanded)?"m":"p";}return "ygtv"+loc+_46;}},getHoverStyle:function(){var s=this.getStyle();if(this.hasChildren(true)&&!this.isLoading){s+="h";}return s;},expandAll:function(){for(var i=0;i<this.children.length;++i){var c=this.children[i];if(c.isDynamic()){alert("Not supported (lazy load + expand all)");break;}else{if(!c.multiExpand){alert("Not supported (no multi-expand + expand all)");break;}else{c.expand();c.expandAll();}}}},collapseAll:function(){for(var i=0;i<this.children.length;++i){this.children[i].collapse();this.children[i].collapseAll();}},setDynamicLoad:function(_48,_49){if(_48){this.dataLoader=_48;this._dynLoad=true;}else{this.dataLoader=null;this._dynLoad=false;}if(_49){this.iconMode=_49;}},isRoot:function(){return (this==this.tree.root);},isDynamic:function(){var _50=(!this.isRoot()&&(this._dynLoad||this.tree.root._dynLoad));return _50;},getIconMode:function(){return (this.iconMode||this.tree.root.iconMode);},hasChildren:function(_51){return (this.children.length>0||(_51&&this.isDynamic()&&!this.dynamicLoadComplete));},toggle:function(){if(!this.tree.locked&&(this.hasChildren(true)||this.isDynamic())){if(this.expanded){this.collapse();}else{this.expand();}}},getHtml:function(){var sb=[];sb[sb.length]="<div class=\"ygtvitem\" id=\""+this.getElId()+"\">";sb[sb.length]=this.getNodeHtml();sb[sb.length]=this.getChildrenHtml();sb[sb.length]="</div>";return sb.join("");},getChildrenHtml:function(){var sb=[];sb[sb.length]="<div class=\"ygtvchildren\"";sb[sb.length]=" id=\""+this.getChildrenElId()+"\"";if(!this.expanded){sb[sb.length]=" style=\"display:none;\"";}sb[sb.length]=">";if((this.hasChildren(true)&&this.expanded)||(this.renderHidden&&!this.isDynamic())){sb[sb.length]=this.renderChildren();}sb[sb.length]="</div>";return sb.join("");},renderChildren:function(){var _52=this;if(this.isDynamic()&&!this.dynamicLoadComplete){this.isLoading=true;this.tree.locked=true;if(this.dataLoader){setTimeout(function(){_52.dataLoader(_52,function(){_52.loadComplete();});},10);}else{if(this.tree.root.dataLoader){setTimeout(function(){_52.tree.root.dataLoader(_52,function(){_52.loadComplete();});},10);}else{return "Error: data loader not found or not specified.";}}return "";}else{return this.completeRender();}},completeRender:function(){var sb=[];for(var i=0;i<this.children.length;++i){this.children[i].childrenRendered=false;sb[sb.length]=this.children[i].getHtml();}this.childrenRendered=true;return sb.join("");},loadComplete:function(){this.getChildrenEl().innerHTML=this.completeRender();this.dynamicLoadComplete=true;this.isLoading=false;this.expand();this.tree.locked=false;},getAncestor:function(_53){if(_53>=this.depth||_53<0){return null;}var p=this.parent;while(p.depth>_53){p=p.parent;}return p;},getDepthStyle:function(_54){return (this.getAncestor(_54).nextSibling)?"ygtvdepthcell":"ygtvblankdepthcell";},getNodeHtml:function(){return "";},refresh:function(){this.getChildrenEl().innerHTML=this.completeRender();if(this.hasIcon){var el=this.getToggleEl();if(el){el.className=this.getStyle();}}}};YAHOO.widget.RootNode=function(_55){this.init(null,null,true);this.tree=_55;};YAHOO.widget.RootNode.prototype=new YAHOO.widget.Node();YAHOO.widget.RootNode.prototype.getNodeHtml=function(){return "";};YAHOO.widget.TextNode=function(_56,_57,_58){this.type="TextNode";if(_57){this.init(_56,_57,_58);this.setUpLabel(_56);}};YAHOO.widget.TextNode.prototype=new YAHOO.widget.Node();YAHOO.widget.TextNode.prototype.labelStyle="ygtvlabel";YAHOO.widget.TextNode.prototype.labelElId=null;YAHOO.widget.TextNode.prototype.label=null;YAHOO.widget.TextNode.prototype.setUpLabel=function(_59){if(typeof _59=="string"){_59={label:_59};}this.label=_59.label;if(_59.href){this.href=_59.href;}if(_59.target){this.target=_59.target;}if(_59.style){this.labelStyle=_59.style;}this.labelElId="ygtvlabelel"+this.index;};YAHOO.widget.TextNode.prototype.getLabelEl=function(){return document.getElementById(this.labelElId);};YAHOO.widget.TextNode.prototype.getNodeHtml=function(){var sb=[];sb[sb.length]="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";sb[sb.length]="<tr>";for(i=0;i<this.depth;++i){sb[sb.length]="<td class=\""+this.getDepthStyle(i)+"\"> </td>";}var _60="YAHOO.widget.TreeView.getNode('"+this.tree.id+"',"+this.index+")";sb[sb.length]="<td";sb[sb.length]=" id=\""+this.getToggleElId()+"\"";sb[sb.length]=" class=\""+this.getStyle()+"\"";if(this.hasChildren(true)){sb[sb.length]=" onmouseover=\"this.className=";sb[sb.length]=_60+".getHoverStyle()\"";sb[sb.length]=" onmouseout=\"this.className=";sb[sb.length]=_60+".getStyle()\"";}sb[sb.length]=" onclick=\"javascript:"+this.getToggleLink()+"\">";sb[sb.length]=" ";sb[sb.length]="</td>";sb[sb.length]="<td>";sb[sb.length]="<a";sb[sb.length]=" id=\""+this.labelElId+"\"";sb[sb.length]=" class=\""+this.labelStyle+"\"";sb[sb.length]=" href=\""+this.href+"\"";sb[sb.length]=" target=\""+this.target+"\"";sb[sb.length]=" onclick=\"return "+_60+".onLabelClick("+_60+")\"";if(this.hasChildren(true)){sb[sb.length]=" onmouseover=\"document.getElementById('";sb[sb.length]=this.getToggleElId()+"').className=";sb[sb.length]=_60+".getHoverStyle()\"";sb[sb.length]=" onmouseout=\"document.getElementById('";sb[sb.length]=this.getToggleElId()+"').className=";sb[sb.length]=_60+".getStyle()\"";}sb[sb.length]=" >";sb[sb.length]=this.label;sb[sb.length]="</a>";sb[sb.length]="</td>";sb[sb.length]="</tr>";sb[sb.length]="</table>";return sb.join("");};YAHOO.widget.TextNode.prototype.onLabelClick=function(me){};YAHOO.widget.MenuNode=function(_62,_63,_64){if(_63){this.init(_62,_63,_64);this.setUpLabel(_62);}this.multiExpand=false;};YAHOO.widget.MenuNode.prototype=new YAHOO.widget.TextNode();YAHOO.widget.HTMLNode=function(_65,_66,_67,_68){if(_66){this.init(_65,_66,_67);this.initContent(_65,_68);}};YAHOO.widget.HTMLNode.prototype=new YAHOO.widget.Node();YAHOO.widget.HTMLNode.prototype.contentStyle="ygtvhtml";YAHOO.widget.HTMLNode.prototype.contentElId=null;YAHOO.widget.HTMLNode.prototype.content=null;YAHOO.widget.HTMLNode.prototype.initContent=function(_69,_70){if(typeof _69=="string"){_69={html:_69};}this.html=_69.html;this.contentElId="ygtvcontentel"+this.index;this.hasIcon=_70;};YAHOO.widget.HTMLNode.prototype.getContentEl=function(){return document.getElementById(this.contentElId);};YAHOO.widget.HTMLNode.prototype.getNodeHtml=function(){var sb=[];sb[sb.length]="<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";sb[sb.length]="<tr>";for(i=0;i<this.depth;++i){sb[sb.length]="<td class=\""+this.getDepthStyle(i)+"\"> </td>";}if(this.hasIcon){sb[sb.length]="<td";sb[sb.length]=" id=\""+this.getToggleElId()+"\"";sb[sb.length]=" class=\""+this.getStyle()+"\"";sb[sb.length]=" onclick=\"javascript:"+this.getToggleLink()+"\"";if(this.hasChildren(true)){sb[sb.length]=" onmouseover=\"this.className=";sb[sb.length]="YAHOO.widget.TreeView.getNode('";sb[sb.length]=this.tree.id+"',"+this.index+").getHoverStyle()\"";sb[sb.length]=" onmouseout=\"this.className=";sb[sb.length]="YAHOO.widget.TreeView.getNode('";sb[sb.length]=this.tree.id+"',"+this.index+").getStyle()\"";}sb[sb.length]="> </td>";}sb[sb.length]="<td";sb[sb.length]=" id=\""+this.contentElId+"\"";sb[sb.length]=" class=\""+this.contentStyle+"\"";sb[sb.length]=" >";sb[sb.length]=this.html;sb[sb.length]="</td>";sb[sb.length]="</tr>";sb[sb.length]="</table>";return sb.join("");};YAHOO.widget.TVAnim=function(){return {FADE_IN:"TVFadeIn",FADE_OUT:"TVFadeOut",getAnim:function(_71,el,_72){if(YAHOO.widget[_71]){return new YAHOO.widget[_71](el,_72);}else{return null;}},isValid:function(_73){return (YAHOO.widget[_73]);}};}();YAHOO.widget.TVFadeIn=function(el,_74){this.el=el;this.callback=_74;};YAHOO.widget.TVFadeIn.prototype={animate:function(){var _75=this;var s=this.el.style;s.opacity=0.1;s.filter="alpha(opacity=10)";s.display="";var dur=0.4;var a=new YAHOO.util.Anim(this.el,{opacity:{from:0.1,to:1,unit:""}},dur);a.onComplete.subscribe(function(){_75.onComplete();});a.animate();},onComplete:function(){this.callback();}};YAHOO.widget.TVFadeOut=function(el,_77){this.el=el;this.callback=_77;};YAHOO.widget.TVFadeOut.prototype={animate:function(){var _78=this;var dur=0.4;var a=new YAHOO.util.Anim(this.el,{opacity:{from:1,to:0.1,unit:""}},dur);a.onComplete.subscribe(function(){_78.onComplete();});a.animate();},onComplete:function(){var s=this.el.style;s.display="none";s.filter="alpha(opacity=100)";this.callback();}};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -