You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
42 KiB
Plaintext

11 months ago
(function($){var settings={},roots={},caches={},_consts={className:{BUTTON:"button",LEVEL:"level",ICO_LOADING:"ico_loading",SWITCH:"switch"},event:{NODECREATED:"ztree_nodeCreated",CLICK:"ztree_click",EXPAND:"ztree_expand",COLLAPSE:"ztree_collapse",ASYNC_SUCCESS:"ztree_async_success",ASYNC_ERROR:"ztree_async_error"},id:{A:"_a",ICON:"_ico",SPAN:"_span",SWITCH:"_switch",UL:"_ul"},line:{ROOT:"root",ROOTS:"roots",CENTER:"center",BOTTOM:"bottom",NOLINE:"noline",LINE:"line"},folder:{OPEN:"open",CLOSE:"close",DOCU:"docu"},node:{CURSELECTED:"curSelectedNode"}},_setting={treeId:"",treeObj:null,view:{addDiyDom:null,autoCancelSelected:true,dblClickExpand:true,expandSpeed:"fast",fontCss:{},nameIsHTML:false,selectedMulti:true,showIcon:true,showLine:true,showTitle:true},data:{key:{children:"children",name:"name",title:"",url:"url"},simpleData:{enable:false,idKey:"id",pIdKey:"pId",rootPId:null},keep:{parent:false,leaf:false}},async:{enable:false,contentType:"application/x-www-form-urlencoded",type:"post",dataType:"text",url:"",autoParam:[],otherParam:[],dataFilter:null},callback:{beforeAsync:null,beforeClick:null,beforeDblClick:null,beforeRightClick:null,beforeMouseDown:null,beforeMouseUp:null,beforeExpand:null,beforeCollapse:null,beforeRemove:null,onAsyncError:null,onAsyncSuccess:null,onNodeCreated:null,onClick:null,onDblClick:null,onRightClick:null,onMouseDown:null,onMouseUp:null,onExpand:null,onCollapse:null,onRemove:null}},_initRoot=function(setting){var r=data.getRoot(setting);if(!r){r={};data.setRoot(setting,r)}r[setting.data.key.children]=[];r.expandTriggerFlag=false;r.curSelectedList=[];r.noSelection=true;r.createdNodes=[];r.zId=0;r._ver=(new Date()).getTime()},_initCache=function(setting){var c=data.getCache(setting);if(!c){c={};data.setCache(setting,c)}c.nodes=[];c.doms=[]},_bindEvent=function(setting){var o=setting.treeObj,c=consts.event;o.bind(c.NODECREATED,function(event,treeId,node){tools.apply(setting.callback.onNodeCreated,[event,treeId,node])});o.bind(c.CLICK,function(event,srcEvent,treeId,node,clickFlag){tools.apply(setting.callback.onClick,[srcEvent,treeId,node,clickFlag])});o.bind(c.EXPAND,function(event,treeId,node){tools.apply(setting.callback.onExpand,[event,treeId,node])});o.bind(c.COLLAPSE,function(event,treeId,node){tools.apply(setting.callback.onCollapse,[event,treeId,node])});o.bind(c.ASYNC_SUCCESS,function(event,treeId,node,msg){tools.apply(setting.callback.onAsyncSuccess,[event,treeId,node,msg])});o.bind(c.ASYNC_ERROR,function(event,treeId,node,XMLHttpRequest,textStatus,errorThrown){tools.apply(setting.callback.onAsyncError,[event,treeId,node,XMLHttpRequest,textStatus,errorThrown])})},_unbindEvent=function(setting){var o=setting.treeObj,c=consts.event;o.unbind(c.NODECREATED).unbind(c.CLICK).unbind(c.EXPAND).unbind(c.COLLAPSE).unbind(c.ASYNC_SUCCESS).unbind(c.ASYNC_ERROR)},_eventProxy=function(event){var target=event.target,setting=data.getSetting(event.data.treeId),tId="",node=null,nodeEventType="",treeEventType="",nodeEventCallback=null,treeEventCallback=null,tmp=null;if(tools.eqs(event.type,"mousedown")){treeEventType="mousedown"}else{if(tools.eqs(event.type,"mouseup")){treeEventType="mouseup"}else{if(tools.eqs(event.type,"contextmenu")){treeEventType="contextmenu"}else{if(tools.eqs(event.type,"click")){if(tools.eqs(target.tagName,"span")&&target.getAttribute("treeNode"+consts.id.SWITCH)!==null){tId=($(target).parent("li").get(0)||$(target).parentsUntil("li").parent().get(0)).id;nodeEventType="switchNode"}else{tmp=tools.getMDom(setting,target,[{tagName:"a",attrName:"treeNode"+consts.id.A}]);if(tmp){tId=($(tmp).parent("li").get(0)||$(tmp).parentsUntil("li").parent().get(0)).id;nodeEventType="clickNode"}}}else{if(tools.eqs(event.type,"dblclick")){treeEventType="dblclick";tmp=tools.getMDom(setting,target,[{tagName:"a",attrName:"treeNode"+consts.id.A}]);if(tmp){tId=($(tmp).parent("li").get(0)||$(tmp).parentsUntil("li").parent().get(0)).id;nodeEventType="switchNode"}}}}}}if(treeEventType.length>0&&tId.length==0){tmp=tools.getMDom(setting,target,[{tagName:"a",attrName:"treeNode"+consts.id.A}]);if(tmp){tId=($(t
}else{lineClass.push(consts.line.CENTER)}}}}else{lineClass.push(consts.line.NOLINE)}if(node.isParent){lineClass.push(node.open?consts.folder.OPEN:consts.folder.CLOSE)}else{lineClass.push(consts.folder.DOCU)}return view.makeNodeLineClassEx(node)+lineClass.join("_")},makeNodeLineClassEx:function(node){return consts.className.BUTTON+" "+consts.className.LEVEL+node.level+" "+consts.className.SWITCH+" "},makeNodeTarget:function(node){return(node.target||"_blank")},makeNodeUrl:function(setting,node){var urlKey=setting.data.key.url;return node[urlKey]?node[urlKey]:null},makeUlHtml:function(setting,node,html,content){html.push("<ul id='",node.tId,consts.id.UL,"' class='",consts.className.LEVEL,node.level," ",view.makeUlLineClass(setting,node),"' style='display:",(node.open?"block":"none"),"'>");html.push(content);html.push("</ul>")},makeUlLineClass:function(setting,node){return((setting.view.showLine&&!node.isLastNode)?consts.line.LINE:"")},removeChildNodes:function(setting,node){if(!node){return}var childKey=setting.data.key.children,nodes=node[childKey];if(!nodes){return}for(var i=0,l=nodes.length;i<l;i++){data.removeNodeCache(setting,nodes[i])}data.removeSelectedNode(setting);delete node[childKey];if(!setting.data.keep.parent){node.isParent=false;node.open=false;var tmp_switchObj=$("#"+node.tId+consts.id.SWITCH),tmp_icoObj=$("#"+node.tId+consts.id.ICON);view.replaceSwitchClass(node,tmp_switchObj,consts.folder.DOCU);view.replaceIcoClass(node,tmp_icoObj,consts.folder.DOCU);$("#"+node.tId+consts.id.UL).remove()}else{$("#"+node.tId+consts.id.UL).empty()}},setFirstNode:function(setting,parentNode){var childKey=setting.data.key.children,childLength=parentNode[childKey].length;if(childLength>0){parentNode[childKey][0].isFirstNode=true}},setLastNode:function(setting,parentNode){var childKey=setting.data.key.children,childLength=parentNode[childKey].length;if(childLength>0){parentNode[childKey][childLength-1].isLastNode=true}},removeNode:function(setting,node){var root=data.getRoot(setting),childKey=setting.data.key.children,parentNode=(node.parentTId)?node.getParentNode():root;node.isFirstNode=false;node.isLastNode=false;node.getPreNode=function(){return null};node.getNextNode=function(){return null};if(!data.getNodeCache(setting,node.tId)){return}$("#"+node.tId).remove();data.removeNodeCache(setting,node);data.removeSelectedNode(setting,node);for(var i=0,l=parentNode[childKey].length;i<l;i++){if(parentNode[childKey][i].tId==node.tId){parentNode[childKey].splice(i,1);break}}view.setFirstNode(setting,parentNode);view.setLastNode(setting,parentNode);var tmp_ulObj,tmp_switchObj,tmp_icoObj,childLength=parentNode[childKey].length;if(!setting.data.keep.parent&&childLength==0){parentNode.isParent=false;parentNode.open=false;tmp_ulObj=$("#"+parentNode.tId+consts.id.UL);tmp_switchObj=$("#"+parentNode.tId+consts.id.SWITCH);tmp_icoObj=$("#"+parentNode.tId+consts.id.ICON);view.replaceSwitchClass(parentNode,tmp_switchObj,consts.folder.DOCU);view.replaceIcoClass(parentNode,tmp_icoObj,consts.folder.DOCU);tmp_ulObj.css("display","none")}else{if(setting.view.showLine&&childLength>0){var newLast=parentNode[childKey][childLength-1];tmp_ulObj=$("#"+newLast.tId+consts.id.UL);tmp_switchObj=$("#"+newLast.tId+consts.id.SWITCH);tmp_icoObj=$("#"+newLast.tId+consts.id.ICON);if(parentNode==root){if(parentNode[childKey].length==1){view.replaceSwitchClass(newLast,tmp_switchObj,consts.line.ROOT)}else{var tmp_first_switchObj=$("#"+parentNode[childKey][0].tId+consts.id.SWITCH);view.replaceSwitchClass(parentNode[childKey][0],tmp_first_switchObj,consts.line.ROOTS);view.replaceSwitchClass(newLast,tmp_switchObj,consts.line.BOTTOM)}}else{view.replaceSwitchClass(newLast,tmp_switchObj,consts.line.BOTTOM)}tmp_ulObj.removeClass(consts.line.LINE)}}},replaceIcoClass:function(node,obj,newName){if(!obj||node.isAjaxing){return}var tmpName=obj.attr("class");if(tmpName==undefined){return}var tmpList=tmpName.split("_");switch(newName){case consts.folder.OPEN:case consts.folder.CLOSE:case consts.folder.DOCU:tmpList[tmpList.length-1]=newName;break}obj.attr("class",tmpList.join("_"))}