dzxstatic
Version:
The static files of Discuz! X
1 lines • 3.46 kB
JavaScript
var icon=new Object;function treeNode(e,i,n,t,d,o){var s=new Object;return s.id=e,s.pid=i,s.name=n,s.url=t,s.target=d,s.open=o,s._isOpen=o,s._lastChildId=0,s._pid=0,s}function dzTree(treeName){this.nodes=new Array,this.openIds=getcookie("leftmenu_openids"),this.pushNodes=new Array,this.addNode=function(e,i,n,t,d,o){var s=new treeNode(e,i,n,t,d,o);for(k in this.pushNodes.push(e),this.nodes[i]||(this.nodes[i]=new Array),this.nodes[i]._lastChildId=e,this.nodes)this.openIds&&-1!=this.openIds.indexOf("_"+s.id)&&(s._isOpen=!0),this.nodes[k].pid==e&&(s._lastChildId=this.nodes[k].id);this.nodes[e]=s},this.show=function(){var e='<div class="tree">';e+=this.createTree(this.nodes[0]),e+="</div>",document.write(e)},this.createTree=function(e,i){if(i=i||"",0==e.id)var n="";else n='<img src="'+this.getIcon1(e)+'" onclick="'+treeName+".switchDisplay('"+e.id+'\')" id="icon1_'+e.id+'" style="cursor: pointer;">';var t='<img src="'+this.getIcon2(e)+'" onclick="'+treeName+".switchDisplay('"+e.id+'\')" id="icon2_'+e.id+'" style="cursor: pointer;">',d='<div class="node" id="node_'+e.id+'">'+i+n+t+this.getName(e)+"</div>";for(k in d+='<div class="nodes" id="nodes_'+e.id+'" style="display:'+(e._isOpen?"":"none")+'">',this.pushNodes){var o=this.pushNodes[k],s=this.nodes[o];if(s.pid==e.id){if(0==e.id)var r="";else r=i+(e.id==this.nodes[e.pid]._lastChildId?'<img src="'+icon.empty+'">':'<img src="'+icon.line+'">');if(s._lastChildId)d+=this.createTree(s,r);else{n='<img src="'+this.getIcon1(s)+'" id="icon1_'+s.id+'">',t='<img src="'+this.getIcon2(s)+'" id="icon2_'+s.id+'">';d+='<div class="node" id="node_'+s.id+'">'+r+n+t+this.getName(s)+"</div>"}}}return d+="</div>"},this.getIcon1=function(e){var i=this.nodes[e.pid],n="";if(e._lastChildId)if(e._isOpen){if(0==e.id)return icon.minus;n=e.id==i._lastChildId?icon.minusBottom:icon.minusMiddle}else{if(0==e.id)return icon.plus;n=e.id==i._lastChildId?icon.plusBottom:icon.plusMiddle}else n=e.id==i._lastChildId?icon.lineBottom:icon.lineMiddle;return n},this.getIcon2=function(e){return 0==e.id?icon.root:e._lastChildId?e._isOpen?icon.folderOpen:icon.folder:icon.file},this.getName=function(e){return e.url?'<a href="'+e.url+'" target="'+e.target+'"> '+e.name+"</a>":e.name},this.switchDisplay=function(nodeId){eval("var theTree = "+treeName);var theNode=theTree.nodes[nodeId];"none"==$("nodes_"+nodeId).style.display?(theTree.openIds=updatestring(theTree.openIds,nodeId),setcookie("leftmenu_openids",theTree.openIds,864e7),theNode._isOpen=!0,$("nodes_"+nodeId).style.display="",$("icon1_"+nodeId).src=theTree.getIcon1(theNode),$("icon2_"+nodeId).src=theTree.getIcon2(theNode)):(theTree.openIds=updatestring(theTree.openIds,nodeId,!0),setcookie("leftmenu_openids",theTree.openIds,864e7),theNode._isOpen=!1,$("nodes_"+nodeId).style.display="none",$("icon1_"+nodeId).src=theTree.getIcon1(theNode),$("icon2_"+nodeId).src=theTree.getIcon2(theNode))}}icon.root=IMGDIR+"/tree_root.gif",icon.folder=IMGDIR+"/tree_folder.gif",icon.folderOpen=IMGDIR+"/tree_folderopen.gif",icon.file=IMGDIR+"/tree_file.gif",icon.empty=IMGDIR+"/tree_empty.gif",icon.line=IMGDIR+"/tree_line.gif",icon.lineMiddle=IMGDIR+"/tree_linemiddle.gif",icon.lineBottom=IMGDIR+"/tree_linebottom.gif",icon.plus=IMGDIR+"/tree_plus.gif",icon.plusMiddle=IMGDIR+"/tree_plusmiddle.gif",icon.plusBottom=IMGDIR+"/tree_plusbottom.gif",icon.minus=IMGDIR+"/tree_minus.gif",icon.minusMiddle=IMGDIR+"/tree_minusmiddle.gif",icon.minusBottom=IMGDIR+"/tree_minusbottom.gif";