/*
 * JQuery zTree exedit 3.0 beta
 * http://code.google.com/p/jquerytree/
 *
 * Copyright (c) 2010 Hunter.z (baby666.cn)
 *
 * Licensed same as jquery - MIT License
 * http://www.opensource.org/licenses/mit-license.php
 *
 * email: hunter.z@263.net
 * Date: 2011-09-01
 */
define(function(require){return function(l){var C={onHoverOverNode:function(b,a){var c=o.getSetting(b.data.treeId),d=o.getRoot(c);if(d.curHoverNode!=a)C.onHoverOutNode(b);d.curHoverNode=a;g.addHoverDom(c,a)},onHoverOutNode:function(b){var b=o.getSetting(b.data.treeId),a=o.getRoot(b);if(a.curHoverNode&&!o.isSelectedNode(b,a.curHoverNode))g.removeTreeDom(b,a.curHoverNode),a.curHoverNode=null},onMousedownNode:function(b,a){function c(b){if(!j.uCanDo(f))return!0;if(A.dragFlag==0&&Math.abs(H-b.clientX)<f.edit.drag.minMoveSize&&Math.abs(I-
b.clientY)<f.edit.drag.minMoveSize)return!0;var a,c,e,h,i;i=f.data.key.childs;j.noSel(f);l("body").css("cursor","pointer");if(A.dragFlag==0){if(j.apply(f.callback.beforeDrag,[f.treeId,n],!0)==!1)return m(b),!0;for(a=0,c=n.length;a<c;a++){if(a==0)A.dragNodeShowBefore=[];e=n[a];e.isParent&&e.open?(g.expandCollapseNode(f,e,!e.open),A.dragNodeShowBefore[e.tId]=!0):A.dragNodeShowBefore[e.tId]=!1}A.dragFlag=1;A.showHoverDom=!1;j.showIfameMask(f,!0);e=!0;h=-1;if(n.length>1){var t=n[0].parentTId?n[0].getParentNode()[i]:
o.getNodes(f);i=[];for(a=0,c=t.length;a<c;a++)if(A.dragNodeShowBefore[t[a].tId]!==void 0&&(e&&h>-1&&h+1!==a&&(e=!1),i.push(t[a]),h=a),n.length===i.length){n=i;break}}e&&(C=n[0].getPreNode(),K=n[n.length-1].getNextNode());x=l("<ul class='zTreeDragUL'></ul>");for(a=0,c=n.length;a<c;a++)if(e=n[a],e.editNameFlag=!1,g.selectNode(f,e,a>0),g.removeTreeDom(f,e),h=l("<li id='"+e.tId+"_tmp'></li>"),h.append(l("#"+e.tId+d.id.A).clone()),h.css("padding","0"),h.children("#"+e.tId+d.id.A).removeClass(d.node.CURSELECTED),
x.append(h),a==f.edit.drag.maxShowNodeNum-1){h=l("<li id='"+e.tId+"_moretmp'><a>  ...  </a></li>");x.append(h);break}x.attr("id",n[0].tId+d.id.UL+"_tmp");x.addClass(f.treeObj.attr("class"));x.appendTo("body");v=l("<button class='tmpzTreeMove_arrow'></button>");v.attr("id","zTreeMove_arrow_tmp");v.appendTo("body");f.treeObj.trigger(d.event.DRAG,[f.treeId,n])}if(A.dragFlag==1&&v.attr("id")!=b.target.id){p&&(p.removeClass(d.node.TMPTARGET_TREE),w&&l("#"+w+d.id.A,p).removeClass(d.node.TMPTARGET_NODE));
w=p=null;D=!1;k=f;e=o.getSettings();for(var r in e)if(e[r].edit.enable&&e[r].treeId!=f.treeId&&(b.target.id==e[r].treeId||l(b.target).parents("#"+e[r].treeId).length>0))D=!0,k=e[r];r=y.scrollTop();h=y.scrollLeft();i=k.treeObj.offset();a=k.treeObj.get(0).scrollHeight;e=k.treeObj.get(0).scrollWidth;c=b.clientY+r-i.top;var E=k.treeObj.height()+i.top-b.clientY-r,F=b.clientX+h-i.left,q=k.treeObj.width()+i.left-b.clientX-h;i=c<f.edit.drag.borderMax&&c>f.edit.drag.borderMin;var t=E<f.edit.drag.borderMax&&
E>f.edit.drag.borderMin,s=F<f.edit.drag.borderMax&&F>f.edit.drag.borderMin,O=q<f.edit.drag.borderMax&&q>f.edit.drag.borderMin,E=c>f.edit.drag.borderMin&&E>f.edit.drag.borderMin&&F>f.edit.drag.borderMin&&q>f.edit.drag.borderMin,F=i&&k.treeObj.scrollTop()<=0,q=t&&k.treeObj.scrollTop()+k.treeObj.height()+10>=a,J=s&&k.treeObj.scrollLeft()<=0,P=O&&k.treeObj.scrollLeft()+k.treeObj.width()+10>=e;if(b.target.id&&k.treeObj.find("#"+b.target.id).length>0){for(var B=b.target;B&&B.tagName&&!j.eqs(B.tagName,"li")&&
B.id!=k.treeId;)B=B.parentNode;var L=!0;for(a=0,c=n.length;a<c;a++)if(e=n[a],B.id===e.tId){L=!1;break}else if(l("#"+e.tId).find("#"+B.id).length>0){L=!1;break}if(L&&b.target.id&&(b.target.id==B.id+d.id.A||l(b.target).parents("#"+B.id+d.id.A).length>0))p=l(B),w=B.id}e=n[0];if(E&&(b.target.id==k.treeId||l(b.target).parents("#"+k.treeId).length>0)){if(!p&&(b.target.id==k.treeId||F||q||J||P)&&(D||!D&&e.parentTId))p=k.treeObj;i?k.treeObj.scrollTop(k.treeObj.scrollTop()-10):t&&k.treeObj.scrollTop(k.treeObj.scrollTop()+
10);s?k.treeObj.scrollLeft(k.treeObj.scrollLeft()-10):O&&k.treeObj.scrollLeft(k.treeObj.scrollLeft()+10);p&&p!=k.treeObj&&p.offset().left<k.treeObj.offset().left&&k.treeObj.scrollLeft(k.treeObj.scrollLeft()+p.offset().left-k.treeObj.offset().left)}x.css({top:b.clientY+r+3+"px",left:b.clientX+h+3+"px"});h=a=0;if(p&&p.attr("id")!=k.treeId){var z=w==null?null:o.getNodeCache(k,w);c=b.ctrlKey&&f.edit.drag.isMove&&f.edit.drag.isCopy||!f.edit.drag.isMove&&f.edit.drag.isCopy;a=!!(C&&w===C.tId);i=!!(K&&w===
K.tId);h=e.parentTId&&e.parentTId==w;e=(c||!i)&&j.apply(k.edit.drag.prev,[k.treeId,z],!!k.edit.drag.prev);a=(c||!a)&&j.apply(k.edit.drag.next,[k.treeId,z],!!k.edit.drag.next);i=(c||!h)&&!(k.data.keep.leaf&&!z.isParent)&&j.apply(k.edit.drag.inner,[k.treeId,z],!!k.edit.drag.inner);if(!e&&!a&&!i){if(p=null,w="",u=d.move.TYPE_INNER,v.css({display:"none"}),window.zTreeMoveTimer)clearTimeout(window.zTreeMoveTimer),window.zTreeMoveTargetNodeTId=null}else{c=l("#"+w+d.id.A,p);c.addClass(d.node.TMPTARGET_NODE);
h=e?i?0.25:a?0.5:1:-1;i=a?i?0.75:e?0.5:0:-1;b=(b.clientY+r-c.offset().top)/c.height();(h==1||b<=h&&b>=-0.2)&&e?(a=1-v.width(),h=0-v.height()/2,u=d.move.TYPE_PREV):(i==0||b>=i&&b<=1.2)&&a?(a=1-v.width(),h=c.height()-v.height()/2,u=d.move.TYPE_NEXT):(a=5-v.width(),h=0,u=d.move.TYPE_INNER);v.css({display:"block",top:c.offset().top+h+"px",left:c.offset().left+a+"px"});if(M!=w||N!=u)G=(new Date).getTime();if(z&&z.isParent&&u==d.move.TYPE_INNER&&(b=!0,window.zTreeMoveTimer&&window.zTreeMoveTargetNodeTId!==
z.tId?(clearTimeout(window.zTreeMoveTimer),window.zTreeMoveTargetNodeTId=null):window.zTreeMoveTimer&&window.zTreeMoveTargetNodeTId===z.tId&&(b=!1),b))window.zTreeMoveTimer=setTimeout(function(){u==d.move.TYPE_INNER&&z&&z.isParent&&!z.open&&(new Date).getTime()-G>k.edit.drag.autoOpenTime&&j.apply(k.callback.beforeDragOpen,[k.treeId,z],!0)&&g.switchNode(k,z)},k.edit.drag.autoOpenTime+50),window.zTreeMoveTargetNodeTId=z.tId}}else if(u=d.move.TYPE_INNER,p&&j.apply(k.edit.drag.inner,[k.treeId,z],!!k.edit.drag.inner)?
p.addClass(d.node.TMPTARGET_TREE):p=null,v.css({display:"none"}),window.zTreeMoveTimer)clearTimeout(window.zTreeMoveTimer),window.zTreeMoveTargetNodeTId=null;M=w;N=u}return!1}function m(b){if(window.zTreeMoveTimer)clearTimeout(window.zTreeMoveTimer),window.zTreeMoveTargetNodeTId=null;N=M=null;y.unbind("mousemove",c);y.unbind("mouseup",m);y.unbind("selectstart",e);l("body").css("cursor","auto");p&&(p.removeClass(d.node.TMPTARGET_TREE),w&&l("#"+w+d.id.A,p).removeClass(d.node.TMPTARGET_NODE));j.showIfameMask(f,
!1);A.showHoverDom=!0;if(A.dragFlag!=0){A.dragFlag=0;var a,h,i,q=f.data.key.childs;for(a=0,h=n.length;a<h;a++)i=n[a],i.isParent&&A.dragNodeShowBefore[i.tId]&&!i.open&&(g.expandCollapseNode(f,i,!i.open),delete A.dragNodeShowBefore[i.tId]);x&&x.remove();v&&v.remove();var s=b.ctrlKey&&f.edit.drag.isMove&&f.edit.drag.isCopy||!f.edit.drag.isMove&&f.edit.drag.isCopy;!s&&p&&w&&n[0].parentTId&&w==n[0].parentTId&&u==d.move.TYPE_INNER&&(p=null);if(p){var t=w==null?null:o.getNodeCache(k,w);if(j.apply(f.callback.beforeDrop,
[k.treeId,n,t,u],!0)!=!1){var r=s?j.clone(n):n,b=function(){if(D){if(!s)for(var b=0,a=n.length;b<a;b++)g.removeNode(f,n[b]);if(u==d.move.TYPE_INNER)g.addNodes(k,t,r);else if(g.addNodes(k,t.getParentNode(),r),u==d.move.TYPE_PREV)for(b=0,a=r.length;b<a;b++)g.moveNode(k,t,r[b],u,!1);else for(b=-1,a=r.length-1;b<a;a--)g.moveNode(k,t,r[a],u,!1)}else if(s&&u==d.move.TYPE_INNER)g.addNodes(k,t,r);else if(s&&g.addNodes(k,t.getParentNode(),r),u==d.move.TYPE_PREV)for(b=0,a=r.length;b<a;b++)g.moveNode(k,t,r[b],
u,!1);else for(b=-1,a=r.length-1;b<a;a--)g.moveNode(k,t,r[a],u,!1);for(b=0,a=r.length;b<a;b++)g.selectNode(k,r[b],b>0);l("#"+r[0].tId+d.id.ICON).focus().blur()};u==d.move.TYPE_INNER&&k.async.enable&&t&&t.isParent&&(!t[q]||t[q].length===0)?g.asyncNode(k,t,!1,b):b();f.treeObj.trigger(d.event.DROP,[k.treeId,r,t,u])}}else{for(a=0,h=n.length;a<h;a++)g.selectNode(k,n[a],a>0);f.treeObj.trigger(d.event.DROP,[f.treeId,null,null,null])}}}function e(){return!1}var h,i,f=o.getSetting(b.data.treeId),A=o.getRoot(f);
if(b.button==2||!f.edit.enable||!f.edit.drag.isCopy&&!f.edit.drag.isMove)return!0;var s=b.target,q=o.getRoot(f).curSelectedList,n=[];if(o.isSelectedNode(f,a))for(h=0,i=q.length;h<i;h++){if(q[h].editNameFlag&&j.eqs(s.tagName,"input")&&s.getAttribute("treeNode"+d.id.INPUT)!==null)return!0;n.push(q[h]);if(n[0].parentTId!==q[h].parentTId){n=[a];break}}else n=[a];var y=l(document),x,v,p,D=!1,k=f,C,K,M=null,N=null,w=null,u=d.move.TYPE_INNER,H=b.clientX,I=b.clientY,G=(new Date).getTime();y.bind("mousemove",
c);y.bind("mouseup",m);y.bind("selectstart",e);return!0}},s={tools:{getAbs:function(b){b=b.getBoundingClientRect();return[b.left,b.top]},inputFocus:function(b){b.get(0)&&(b.focus(),j.setCursorPosition(b.get(0),b.val().length))},setCursorPosition:function(b,a){if(b.setSelectionRange)b.focus(),b.setSelectionRange(a,a);else if(b.createTextRange){var c=b.createTextRange();c.collapse(!0);c.moveEnd("character",a);c.moveStart("character",a);c.select()}},showIfameMask:function(b,a){for(var c=o.getRoot(b);c.dragMaskList.length>
0;)c.dragMaskList[0].remove(),c.dragMaskList.shift();if(a)for(var d=l("iframe"),e=0,h=d.length;e<h;e++){var g=d.get(e),f=j.getAbs(g),g=l("<div id='zTreeMask_"+e+"' class='zTreeMask' style='background-color:yellow;opacity: 0.3;filter: alpha(opacity=30);    top:"+f[1]+"px; left:"+f[0]+"px; width:"+g.offsetWidth+"px; height:"+g.offsetHeight+"px;'></div>");g.appendTo("body");c.dragMaskList.push(g)}}},view:{addEditBtn:function(b,a){if(!(a.editNameFlag||l("#"+a.tId+d.id.EDIT).length>0)&&j.apply(b.edit.showRenameBtn,
[b.treeId,a],b.edit.showRenameBtn)){var c=l("#"+a.tId+d.id.A),m="<button type='button' class='edit' id='"+a.tId+d.id.EDIT+"' title='"+j.apply(b.edit.renameTitle,[b.treeId,a],b.edit.renameTitle)+"' treeNode"+d.id.EDIT+" onfocus='this.blur();' style='display:none;'></button>";c.append(m);l("#"+a.tId+d.id.EDIT).bind("click",function(){if(!j.uCanDo(b))return!0;g.editNode(b,a);return!1}).show()}},addRemoveBtn:function(b,a){if(!(a.editNameFlag||l("#"+a.tId+d.id.REMOVE).length>0)&&j.apply(b.edit.showRemoveBtn,
[b.treeId,a],b.edit.showRemoveBtn)){var c=l("#"+a.tId+d.id.A),m="<button type='button' class='remove' id='"+a.tId+d.id.REMOVE+"' title='"+j.apply(b.edit.removeTitle,[b.treeId,a],b.edit.removeTitle)+"' treeNode"+d.id.REMOVE+" onfocus='this.blur();' style='display:none;'></button>";c.append(m);l("#"+a.tId+d.id.REMOVE).bind("click",function(){if(!j.uCanDo(b)||j.apply(b.callback.beforeRemove,[b.treeId,a],!0)==!1)return!0;g.removeNode(b,a);b.treeObj.trigger(d.event.REMOVE,[b.treeId,a]);return!1}).bind("mousedown",
function(){return!0}).show()}},addHoverDom:function(b,a){if(o.getRoot(b).showHoverDom)a.isHover=!0,b.edit.enable&&(g.addEditBtn(b,a),g.addRemoveBtn(b,a)),j.apply(b.view.addHoverDom,[b.treeId,a])},cancelCurEditNode:function(b,a){var c=o.getRoot(b),m=b.data.key.name,e=c.curEditNode;if(e){var h=c.curEditInput,a=a?a:h.val();if(a!==e[m])if(j.apply(b.callback.beforeRename,[b.treeId,e,a],!0)===!1)return e.editNameStatus=!0,j.inputFocus(h),!1;else e[m]=a?a:h.val(),b.treeObj.trigger(d.event.RENAME,[b.treeId,
e]);l("#"+e.tId+d.id.A).removeClass(d.node.CURSELECTED_EDIT);h.unbind();g.setNodeName(b,e);e.editNameFlag=!1;c.curEditNode=null;c.curEditInput=null;g.selectNode(b,e,!1)}return c.noSelection=!0},editNode:function(b,a){var c=o.getRoot(b);if(!o.isSelectedNode(b,a)||!(c.curEditNode==a&&a.editNameFlag)){var m=b.data.key.name;a.editNameFlag=!0;g.removeTreeDom(b,a);g.cancelCurEditNode(b);g.selectNode(b,a,!1);l("#"+a.tId+d.id.SPAN).html("<input type=text class='rename' id='"+a.tId+d.id.INPUT+"' treeNode"+
d.id.INPUT+" >");var e=l("#"+a.tId+d.id.INPUT);e.attr("value",a[m]);j.inputFocus(e);e.bind("blur",function(){g.cancelCurEditNode(b)}).bind("keyup",function(c){c.keyCode=="13"?g.cancelCurEditNode(b):c.keyCode=="27"&&g.cancelCurEditNode(b,a[m])}).bind("click",function(){return!1}).bind("dblclick",function(){return!1});l("#"+a.tId+d.id.A).addClass(d.node.CURSELECTED_EDIT);c.curEditInput=e;c.noSelection=!1;c.curEditNode=a}},moveNode:function(b,a,c,m,e,h){var i=o.getRoot(b),f=b.data.key.childs;if(a!=c&&
(!b.data.keep.leaf||!a||a.isParent||m!=d.move.TYPE_INNER)){var j=c.parentTId?c.getParentNode():i,s=a===null||a==i;s&&a===null&&(a=i);if(s)m=d.move.TYPE_INNER;i=a.parentTId?a.getParentNode():i;if(m!=d.move.TYPE_PREV&&m!=d.move.TYPE_NEXT)m=d.move.TYPE_INNER;var q,n;s?n=q=b.treeObj:h||(m==d.move.TYPE_INNER?g.expandCollapseNode(b,a,!0,!1):g.expandCollapseNode(b,a.getParentNode(),!0,!1),q=l("#"+a.tId),n=l("#"+a.tId+d.id.UL));var y=l("#"+c.tId).remove();n&&m==d.move.TYPE_INNER?n.append(y):q&&m==d.move.TYPE_PREV?
q.before(y):q&&m==d.move.TYPE_NEXT&&q.after(y);var x=-1,v=0,p=null;q=null;var C=c.level;if(c.isFirstNode){if(x=0,j[f].length>1)p=j[f][1],p.isFirstNode=!0}else if(c.isLastNode)x=j[f].length-1,p=j[f][x-1],p.isLastNode=!0;else for(n=0,y=j[f].length;n<y;n++)if(j[f][n].tId==c.tId){x=n;break}x>=0&&j[f].splice(x,1);if(m!=d.move.TYPE_INNER)for(n=0,y=i[f].length;n<y;n++)i[f][n].tId==a.tId&&(v=n);if(m==d.move.TYPE_INNER){s?c.parentTId=null:(a.isParent=!0,a.open=!1,c.parentTId=a.tId);a[f]||(a[f]=[]);if(a[f].length>
0)q=a[f][a[f].length-1],q.isLastNode=!1;a[f].splice(a[f].length,0,c);c.isLastNode=!0;c.isFirstNode=a[f].length==1}else a.isFirstNode&&m==d.move.TYPE_PREV?(i[f].splice(v,0,c),q=a,q.isFirstNode=!1,c.parentTId=a.parentTId,c.isFirstNode=!0,c.isLastNode=!1):a.isLastNode&&m==d.move.TYPE_NEXT?(i[f].splice(v+1,0,c),q=a,q.isLastNode=!1,c.parentTId=a.parentTId,c.isFirstNode=!1,c.isLastNode=!0):(m==d.move.TYPE_PREV?i[f].splice(v,0,c):i[f].splice(v+1,0,c),c.parentTId=a.parentTId,c.isFirstNode=!1,c.isLastNode=
!1);o.fixPIdKeyValue(b,c);o.setSonNodeLevel(b,c.getParentNode(),c);g.setNodeLineIcos(b,c);g.repairNodeLevelClass(b,c,C);!b.data.keep.parent&&j[f].length<1?(j.isParent=!1,j.open=!1,a=l("#"+j.tId+d.id.UL),m=l("#"+j.tId+d.id.SWITCH),f=l("#"+j.tId+d.id.ICON),g.replaceSwitchClass(m,d.folder.DOCU),g.replaceIcoClass(j,f,d.folder.DOCU),a.css("display","none")):p&&g.setNodeLineIcos(b,p);q&&g.setNodeLineIcos(b,q);b.checkable&&(g.repairChkClass(b,j),g.repairParentChkClassWithSelf(b,j),j!=c.parent&&g.repairParentChkClassWithSelf(b,
c));h||g.expandCollapseParentNode(b,c.getParentNode(),!0,e)}},removeChilds:function(b,a){if(a){var c=b.data.key.childs,m=a[c];if(m){l("#"+a.tId+d.id.UL).remove();for(var e=0,h=m.length;e<h;e++)o.removeNodeCache(b,m[e]);o.removeSelectedNode(b);delete a[c];if(!b.data.keep.parent)a.isParent=!1,a.open=!1,c=l("#"+a.tId+d.id.SWITCH),m=l("#"+a.tId+d.id.ICON),g.replaceSwitchClass(c,d.folder.DOCU),g.replaceIcoClass(a,m,d.folder.DOCU)}}},removeEditBtn:function(b){l("#"+b.tId+d.id.EDIT).unbind().remove()},removeNode:function(b,
a){var c=o.getRoot(b),m=b.data.key.childs,e=a.parentTId?a.getParentNode():c;if(c.curEditNode===a)c.curEditNode=null;l("#"+a.tId).remove();o.removeNodeCache(b,a);o.removeSelectedNode(b,a);for(var h=0,i=e[m].length;h<i;h++)if(e[m][h].tId==a.tId){e[m].splice(h,1);break}if(!b.data.keep.parent&&e[m].length<1)e.isParent=!1,e.open=!1,h=l("#"+e.tId+d.id.UL),i=l("#"+e.tId+d.id.SWITCH),c=l("#"+e.tId+d.id.ICON),g.replaceSwitchClass(i,d.folder.DOCU),g.replaceIcoClass(e,c,d.folder.DOCU),h.css("display","none");
else if(b.view.showLine&&e[m].length>0){var f=e[m][e[m].length-1];f.isLastNode=!0;f.isFirstNode=e[m].length==1;h=l("#"+f.tId+d.id.UL);i=l("#"+f.tId+d.id.SWITCH);l("#"+f.tId+d.id.ICON);e==c?e[m].length==1?g.replaceSwitchClass(i,d.line.ROOT):(e=l("#"+e[m][0].tId+d.id.SWITCH),g.replaceSwitchClass(e,d.line.ROOTS),g.replaceSwitchClass(i,d.line.BOTTOM)):g.replaceSwitchClass(i,d.line.BOTTOM);h.removeClass(d.line.LINE)}},removeRemoveBtn:function(b){l("#"+b.tId+d.id.REMOVE).unbind().remove()},removeTreeDom:function(b,
a){a.isHover=!1;g.removeEditBtn(a);g.removeRemoveBtn(a);j.apply(b.view.removeHoverDom,[b.treeId,a])},repairNodeLevelClass:function(b,a,c){if(c!==a.level){var b=l("#"+a.tId),m=l("#"+a.tId+d.id.A),e=l("#"+a.tId+d.id.UL),c="level"+c,a="level"+a.level;b.removeClass(c);b.addClass(a);m.removeClass(c);m.addClass(a);e.removeClass(c);e.addClass(a)}}},event:s,data:{setSonNodeLevel:function(b,a,c){if(c){var d=b.data.key.childs;c.level=a?a.level+1:0;if(c[d])for(var a=0,e=c[d].length;a<e;a++)c[d][a]&&o.setSonNodeLevel(b,
c,c[d][a])}}}};l.extend(!0,l.fn.zTree.consts,{event:{DRAG:"ztree_drag",DROP:"ztree_drop",REMOVE:"ztree_remove",RENAME:"ztree_rename"},id:{EDIT:"_edit",INPUT:"_input",REMOVE:"_remove"},move:{TYPE_INNER:"inner",TYPE_PREV:"prev",TYPE_NEXT:"next"},node:{CURSELECTED_EDIT:"curSelectedNode_Edit",TMPTARGET_TREE:"tmpTargetzTree",TMPTARGET_NODE:"tmpTargetNode"}});l.extend(!0,l.fn.zTree._z,s);var s=l.fn.zTree,j=s._z.tools,d=s.consts,g=s._z.view,o=s._z.data,s=s._z.event;o.exSetting({edit:{enable:!1,showRemoveBtn:!0,
showRenameBtn:!0,removeTitle:"remove",renameTitle:"rename",drag:{isCopy:!0,isMove:!0,prev:!0,next:!0,inner:!0,minMoveSize:5,borderMax:10,borderMin:-5,maxShowNodeNum:5,autoOpenTime:500}},view:{addHoverDom:null,removeHoverDom:null},callback:{beforeDrag:null,beforeDragOpen:null,beforeDrop:null,beforeRemove:null,beforeRename:null,onDrag:null,onDrop:null,onRemove:null,onRename:null}});o.addInitBind(function(b){var a=b.treeObj,c=d.event;a.unbind(c.RENAME);a.bind(c.RENAME,function(a,c,d){j.apply(b.callback.onRename,
[a,c,d])});a.unbind(c.REMOVE);a.bind(c.REMOVE,function(a,c,d){j.apply(b.callback.onRemove,[a,c,d])});a.unbind(c.DRAG);a.bind(c.DRAG,function(a,c,d){j.apply(b.callback.onDrag,[a,c,d])});a.unbind(c.DROP);a.bind(c.DROP,function(a,c,d,g,f){j.apply(b.callback.onDrop,[a,c,d,g,f])})});o.addInitCache(function(){});o.addInitNode(function(b,a,c){if(c)c.isHover=!1,c.editNameFlag=!1});o.addInitProxy(function(b){var a=b.target,c=o.getSetting(b.data.treeId),g=b.relatedTarget,e="",h=null,i="",f=null,l=null;if(j.eqs(b.type,
"mouseover")){if(l=j.getMDom(c,a,[{tagName:"a",attrName:"treeNode"+d.id.A}]))e=l.parentNode.id,i="hoverOverNode"}else if(j.eqs(b.type,"mouseout"))l=j.getMDom(c,g,[{tagName:"a",attrName:"treeNode"+d.id.A}]),l||(e="remove",i="hoverOutNode");else if(j.eqs(b.type,"mousedown")&&(l=j.getMDom(c,a,[{tagName:"a",attrName:"treeNode"+d.id.A}])))e=l.parentNode.id,i="mousedownNode";if(e.length>0)switch(h=o.getNodeCache(c,e),i){case "mousedownNode":f=C.onMousedownNode;break;case "hoverOverNode":f=C.onHoverOverNode;
break;case "hoverOutNode":f=C.onHoverOutNode}return{stop:!1,node:h,nodeEventType:i,nodeEventCallback:f,treeEventType:"",treeEventCallback:null}});o.addInitRoot(function(b){b=o.getRoot(b);b.curEditNode=null;b.curEditInput=null;b.curHoverNode=null;b.dragFlag=0;b.dragNodeShowBefore=[];b.dragMaskList=[];b.showHoverDom=!0});o.addZTreeTools(function(b,a){a.addNodes=function(a,d,e){function h(){g.addNodes(b,a,f,e==!0)}if(!d)return null;a||(a=null);if(a&&!a.isParent&&b.data.keep.leaf)return null;var i=b.data.key.childs,
f=j.clone(j.isArray(d)?d:[d]);this.setting.async.enable&&a&&a.isParent&&(!a[i]||a[i].length===0)?g.asyncNode(b,a,e,h):h();return f};a.cancelEditName=function(a){var d=o.getRoot(b),e=b.data.key.name,h=d.curEditNode;d.curEditNode&&g.cancelCurEditNode(b,a?a:h[e])};a.copyNode=function(a,m,e,h){if(!m)return null;if(a&&!a.isParent&&b.data.keep.leaf&&e===d.move.TYPE_INNER)return null;var i=b.data.key.childs,f=j.clone(m);if(!a)a=null,e=d.move.TYPE_INNER;e==d.move.TYPE_INNER?(m=function(){g.addNodes(b,a,[f],
h)},b.async.enable&&a&&a.isParent&&(!a[i]||a[i].length===0)?g.asyncNode(b,a,h,m):m()):(g.addNodes(b,a.parentNode,[f],h),g.moveNode(b,a,f,e,!1,h));return f};a.editName=function(a){a&&a.tId&&a===o.getNodeCache(b,a.tId)&&j.uCanDo(b)&&(g.expandCollapseParentNode(b,a,!0),g.editNode(b,a))};a.moveNode=function(a,m,e,h){function i(){g.moveNode(b,a,m,e,!1,h)}if(!m)return m;if(a&&!a.isParent&&b.data.keep.leaf&&e===d.move.TYPE_INNER)return null;else if(a&&(m.parentTId==a.tId&&e==d.move.TYPE_INNER||l("#"+m.tId).find("#"+
a.tId).length>0))return null;else a||(a=null);var f=b.data.key.childs;b.async.enable&&a&&a.isParent&&(!a[f]||a[f].length===0)?g.asyncNode(b,a,h,i):i();return m};a.removeNode=function(a){a&&j.apply(b.callback.beforeRemove,[b.treeId,a],!0)!=!1&&(g.removeNode(b,a),this.setting.treeObj.trigger(d.event.REMOVE,[b.treeId,a]))};a.removeChilds=function(a){if(!a)return null;var d=a[b.data.key.childs];g.removeChilds(b,a);return d?d:null};a.setEditable=function(a){b.edit.enable=a;return this.refresh()}});var H=
g.cancelPreSelectedNode;g.cancelPreSelectedNode=function(b,a){for(var c=o.getRoot(b).curSelectedList,d=0,e=c.length;d<e;d++)if(!a||a===c[d])if(g.removeTreeDom(b,c[d]),a)break;H&&H.apply(g,arguments)};var I=g.createNodes;g.createNodes=function(b,a,c,d){I&&I.apply(g,arguments);c&&g.repairParentChkClassWithSelf(b,d)};g.makeNodeUrl=function(b,a){return a.url&&!b.edit.enable?a.url:null};var G=g.selectNode;g.selectNode=function(b,a,c){var d=o.getRoot(b);if(o.isSelectedNode(b,a)&&d.curEditNode==a&&a.editNameFlag)return!1;
G&&G.apply(g,arguments);g.addHoverDom(b,a);return!0};var J=j.uCanDo;j.uCanDo=function(b,a){var c=o.getRoot(b);return a&&(j.eqs(a.type,"mouseover")||j.eqs(a.type,"mouseout")||j.eqs(a.type,"mousedown")||j.eqs(a.type,"mouseup"))?!0:!c.curEditNode&&(J?J.apply(g,arguments):!0)}}});
