tocmd 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,33 +0,0 @@
1
- /*
2
- * JQuery zTree excheck 3.5.02
3
- * http://zTree.me/
4
- *
5
- * Copyright (c) 2010 Hunter.z
6
- *
7
- * Licensed same as jquery - MIT License
8
- * http://www.opensource.org/licenses/mit-license.php
9
- *
10
- * email: hunter.z@263.net
11
- * Date: 2013-01-28
12
- */
13
- (function(m){var p,q,r,n={event:{CHECK:"ztree_check"},id:{CHECK:"_check"},checkbox:{STYLE:"checkbox",DEFAULT:"chk",DISABLED:"disable",FALSE:"false",TRUE:"true",FULL:"full",PART:"part",FOCUS:"focus"},radio:{STYLE:"radio",TYPE_ALL:"all",TYPE_LEVEL:"level"}},v={check:{enable:!1,autoCheckTrigger:!1,chkStyle:n.checkbox.STYLE,nocheckInherit:!1,chkDisabledInherit:!1,radioType:n.radio.TYPE_LEVEL,chkboxType:{Y:"ps",N:"ps"}},data:{key:{checked:"checked"}},callback:{beforeCheck:null,onCheck:null}};p=function(c,
14
- a){if(a.chkDisabled===!0)return!1;var b=g.getSetting(c.data.treeId),d=b.data.key.checked;if(l.apply(b.callback.beforeCheck,[b.treeId,a],!0)==!1)return!0;a[d]=!a[d];e.checkNodeRelation(b,a);d=m("#"+a.tId+i.id.CHECK);e.setChkClass(b,d,a);e.repairParentChkClassWithSelf(b,a);b.treeObj.trigger(i.event.CHECK,[c,b.treeId,a]);return!0};q=function(c,a){if(a.chkDisabled===!0)return!1;var b=g.getSetting(c.data.treeId),d=m("#"+a.tId+i.id.CHECK);a.check_Focus=!0;e.setChkClass(b,d,a);return!0};r=function(c,a){if(a.chkDisabled===
15
- !0)return!1;var b=g.getSetting(c.data.treeId),d=m("#"+a.tId+i.id.CHECK);a.check_Focus=!1;e.setChkClass(b,d,a);return!0};m.extend(!0,m.fn.zTree.consts,n);m.extend(!0,m.fn.zTree._z,{tools:{},view:{checkNodeRelation:function(c,a){var b,d,h,k=c.data.key.children,j=c.data.key.checked;b=i.radio;if(c.check.chkStyle==b.STYLE){var f=g.getRadioCheckedList(c);if(a[j])if(c.check.radioType==b.TYPE_ALL){for(d=f.length-1;d>=0;d--)b=f[d],b[j]=!1,f.splice(d,1),e.setChkClass(c,m("#"+b.tId+i.id.CHECK),b),b.parentTId!=
16
- a.parentTId&&e.repairParentChkClassWithSelf(c,b);f.push(a)}else{f=a.parentTId?a.getParentNode():g.getRoot(c);for(d=0,h=f[k].length;d<h;d++)b=f[k][d],b[j]&&b!=a&&(b[j]=!1,e.setChkClass(c,m("#"+b.tId+i.id.CHECK),b))}else if(c.check.radioType==b.TYPE_ALL)for(d=0,h=f.length;d<h;d++)if(a==f[d]){f.splice(d,1);break}}else a[j]&&(!a[k]||a[k].length==0||c.check.chkboxType.Y.indexOf("s")>-1)&&e.setSonNodeCheckBox(c,a,!0),!a[j]&&(!a[k]||a[k].length==0||c.check.chkboxType.N.indexOf("s")>-1)&&e.setSonNodeCheckBox(c,
17
- a,!1),a[j]&&c.check.chkboxType.Y.indexOf("p")>-1&&e.setParentNodeCheckBox(c,a,!0),!a[j]&&c.check.chkboxType.N.indexOf("p")>-1&&e.setParentNodeCheckBox(c,a,!1)},makeChkClass:function(c,a){var b=c.data.key.checked,d=i.checkbox,h=i.radio,k="",k=a.chkDisabled===!0?d.DISABLED:a.halfCheck?d.PART:c.check.chkStyle==h.STYLE?a.check_Child_State<1?d.FULL:d.PART:a[b]?a.check_Child_State===2||a.check_Child_State===-1?d.FULL:d.PART:a.check_Child_State<1?d.FULL:d.PART,b=c.check.chkStyle+"_"+(a[b]?d.TRUE:d.FALSE)+
18
- "_"+k,b=a.check_Focus&&a.chkDisabled!==!0?b+"_"+d.FOCUS:b;return"button "+d.DEFAULT+" "+b},repairAllChk:function(c,a){if(c.check.enable&&c.check.chkStyle===i.checkbox.STYLE)for(var b=c.data.key.checked,d=c.data.key.children,h=g.getRoot(c),k=0,j=h[d].length;k<j;k++){var f=h[d][k];f.nocheck!==!0&&f.chkDisabled!==!0&&(f[b]=a);e.setSonNodeCheckBox(c,f,a)}},repairChkClass:function(c,a){if(a&&(g.makeChkFlag(c,a),a.nocheck!==!0)){var b=m("#"+a.tId+i.id.CHECK);e.setChkClass(c,b,a)}},repairParentChkClass:function(c,
19
- a){if(a&&a.parentTId){var b=a.getParentNode();e.repairChkClass(c,b);e.repairParentChkClass(c,b)}},repairParentChkClassWithSelf:function(c,a){if(a){var b=c.data.key.children;a[b]&&a[b].length>0?e.repairParentChkClass(c,a[b][0]):e.repairParentChkClass(c,a)}},repairSonChkDisabled:function(c,a,b,d){if(a){var h=c.data.key.children;if(a.chkDisabled!=b)a.chkDisabled=b;e.repairChkClass(c,a);if(a[h]&&d)for(var k=0,j=a[h].length;k<j;k++)e.repairSonChkDisabled(c,a[h][k],b,d)}},repairParentChkDisabled:function(c,
20
- a,b,d){if(a){if(a.chkDisabled!=b&&d)a.chkDisabled=b;e.repairChkClass(c,a);e.repairParentChkDisabled(c,a.getParentNode(),b,d)}},setChkClass:function(c,a,b){a&&(b.nocheck===!0?a.hide():a.show(),a.removeClass(),a.addClass(e.makeChkClass(c,b)))},setParentNodeCheckBox:function(c,a,b,d){var h=c.data.key.children,k=c.data.key.checked,j=m("#"+a.tId+i.id.CHECK);d||(d=a);g.makeChkFlag(c,a);a.nocheck!==!0&&a.chkDisabled!==!0&&(a[k]=b,e.setChkClass(c,j,a),c.check.autoCheckTrigger&&a!=d&&c.treeObj.trigger(i.event.CHECK,
21
- [null,c.treeId,a]));if(a.parentTId){j=!0;if(!b)for(var h=a.getParentNode()[h],f=0,o=h.length;f<o;f++)if(h[f].nocheck!==!0&&h[f].chkDisabled!==!0&&h[f][k]||(h[f].nocheck===!0||h[f].chkDisabled===!0)&&h[f].check_Child_State>0){j=!1;break}j&&e.setParentNodeCheckBox(c,a.getParentNode(),b,d)}},setSonNodeCheckBox:function(c,a,b,d){if(a){var h=c.data.key.children,k=c.data.key.checked,j=m("#"+a.tId+i.id.CHECK);d||(d=a);var f=!1;if(a[h])for(var o=0,l=a[h].length;o<l&&a.chkDisabled!==!0;o++){var n=a[h][o];
22
- e.setSonNodeCheckBox(c,n,b,d);n.chkDisabled===!0&&(f=!0)}if(a!=g.getRoot(c)&&a.chkDisabled!==!0){f&&a.nocheck!==!0&&g.makeChkFlag(c,a);if(a.nocheck!==!0&&a.chkDisabled!==!0){if(a[k]=b,!f)a.check_Child_State=a[h]&&a[h].length>0?b?2:0:-1}else a.check_Child_State=-1;e.setChkClass(c,j,a);c.check.autoCheckTrigger&&a!=d&&a.nocheck!==!0&&a.chkDisabled!==!0&&c.treeObj.trigger(i.event.CHECK,[null,c.treeId,a])}}}},event:{},data:{getRadioCheckedList:function(c){for(var a=g.getRoot(c).radioCheckedList,b=0,d=
23
- a.length;b<d;b++)g.getNodeCache(c,a[b].tId)||(a.splice(b,1),b--,d--);return a},getCheckStatus:function(c,a){if(!c.check.enable||a.nocheck||a.chkDisabled)return null;var b=c.data.key.checked;return{checked:a[b],half:a.halfCheck?a.halfCheck:c.check.chkStyle==i.radio.STYLE?a.check_Child_State===2:a[b]?a.check_Child_State>-1&&a.check_Child_State<2:a.check_Child_State>0}},getTreeCheckedNodes:function(c,a,b,d){if(!a)return[];for(var h=c.data.key.children,k=c.data.key.checked,e=b&&c.check.chkStyle==i.radio.STYLE&&
24
- c.check.radioType==i.radio.TYPE_ALL,d=!d?[]:d,f=0,o=a.length;f<o;f++){if(a[f].nocheck!==!0&&a[f].chkDisabled!==!0&&a[f][k]==b&&(d.push(a[f]),e))break;g.getTreeCheckedNodes(c,a[f][h],b,d);if(e&&d.length>0)break}return d},getTreeChangeCheckedNodes:function(c,a,b){if(!a)return[];for(var d=c.data.key.children,h=c.data.key.checked,b=!b?[]:b,k=0,e=a.length;k<e;k++)a[k].nocheck!==!0&&a[k].chkDisabled!==!0&&a[k][h]!=a[k].checkedOld&&b.push(a[k]),g.getTreeChangeCheckedNodes(c,a[k][d],b);return b},makeChkFlag:function(c,
25
- a){if(a){var b=c.data.key.children,d=c.data.key.checked,h=-1;if(a[b])for(var e=0,j=a[b].length;e<j;e++){var f=a[b][e],g=-1;if(c.check.chkStyle==i.radio.STYLE)if(g=f.nocheck===!0||f.chkDisabled===!0?f.check_Child_State:f.halfCheck===!0?2:f[d]?2:f.check_Child_State>0?2:0,g==2){h=2;break}else g==0&&(h=0);else if(c.check.chkStyle==i.checkbox.STYLE)if(g=f.nocheck===!0||f.chkDisabled===!0?f.check_Child_State:f.halfCheck===!0?1:f[d]?f.check_Child_State===-1||f.check_Child_State===2?2:1:f.check_Child_State>
26
- 0?1:0,g===1){h=1;break}else if(g===2&&h>-1&&e>0&&g!==h){h=1;break}else if(h===2&&g>-1&&g<2){h=1;break}else g>-1&&(h=g)}a.check_Child_State=h}}}});var n=m.fn.zTree,l=n._z.tools,i=n.consts,e=n._z.view,g=n._z.data;g.exSetting(v);g.addInitBind(function(c){c.treeObj.bind(i.event.CHECK,function(a,b,d,h){l.apply(c.callback.onCheck,[b?b:a,d,h])})});g.addInitUnBind(function(c){c.treeObj.unbind(i.event.CHECK)});g.addInitCache(function(){});g.addInitNode(function(c,a,b,d){if(b){a=c.data.key.checked;typeof b[a]==
27
- "string"&&(b[a]=l.eqs(b[a],"true"));b[a]=!!b[a];b.checkedOld=b[a];if(typeof b.nocheck=="string")b.nocheck=l.eqs(b.nocheck,"true");b.nocheck=!!b.nocheck||c.check.nocheckInherit&&d&&!!d.nocheck;if(typeof b.chkDisabled=="string")b.chkDisabled=l.eqs(b.chkDisabled,"true");b.chkDisabled=!!b.chkDisabled||c.check.chkDisabledInherit&&d&&!!d.chkDisabled;if(typeof b.halfCheck=="string")b.halfCheck=l.eqs(b.halfCheck,"true");b.halfCheck=!!b.halfCheck;b.check_Child_State=-1;b.check_Focus=!1;b.getCheckStatus=function(){return g.getCheckStatus(c,
28
- b)}}});g.addInitProxy(function(c){var a=c.target,b=g.getSetting(c.data.treeId),d="",h=null,e="",j=null;if(l.eqs(c.type,"mouseover")){if(b.check.enable&&l.eqs(a.tagName,"span")&&a.getAttribute("treeNode"+i.id.CHECK)!==null)d=a.parentNode.id,e="mouseoverCheck"}else if(l.eqs(c.type,"mouseout")){if(b.check.enable&&l.eqs(a.tagName,"span")&&a.getAttribute("treeNode"+i.id.CHECK)!==null)d=a.parentNode.id,e="mouseoutCheck"}else if(l.eqs(c.type,"click")&&b.check.enable&&l.eqs(a.tagName,"span")&&a.getAttribute("treeNode"+
29
- i.id.CHECK)!==null)d=a.parentNode.id,e="checkNode";if(d.length>0)switch(h=g.getNodeCache(b,d),e){case "checkNode":j=p;break;case "mouseoverCheck":j=q;break;case "mouseoutCheck":j=r}return{stop:!1,node:h,nodeEventType:e,nodeEventCallback:j,treeEventType:"",treeEventCallback:null}});g.addInitRoot(function(c){g.getRoot(c).radioCheckedList=[]});g.addBeforeA(function(c,a,b){var d=c.data.key.checked;c.check.enable&&(g.makeChkFlag(c,a),c.check.chkStyle==i.radio.STYLE&&c.check.radioType==i.radio.TYPE_ALL&&
30
- a[d]&&g.getRoot(c).radioCheckedList.push(a),b.push("<span ID='",a.tId,i.id.CHECK,"' class='",e.makeChkClass(c,a),"' treeNode",i.id.CHECK,a.nocheck===!0?" style='display:none;'":"","></span>"))});g.addZTreeTools(function(c,a){a.checkNode=function(a,b,g,j){var f=this.setting.data.key.checked;if(a.chkDisabled!==!0&&(b!==!0&&b!==!1&&(b=!a[f]),j=!!j,(a[f]!==b||g)&&!(j&&l.apply(this.setting.callback.beforeCheck,[this.setting.treeId,a],!0)==!1)&&l.uCanDo(this.setting)&&this.setting.check.enable&&a.nocheck!==
31
- !0))a[f]=b,b=m("#"+a.tId+i.id.CHECK),(g||this.setting.check.chkStyle===i.radio.STYLE)&&e.checkNodeRelation(this.setting,a),e.setChkClass(this.setting,b,a),e.repairParentChkClassWithSelf(this.setting,a),j&&c.treeObj.trigger(i.event.CHECK,[null,c.treeId,a])};a.checkAllNodes=function(a){e.repairAllChk(this.setting,!!a)};a.getCheckedNodes=function(a){var b=this.setting.data.key.children;return g.getTreeCheckedNodes(this.setting,g.getRoot(c)[b],a!==!1)};a.getChangeCheckedNodes=function(){var a=this.setting.data.key.children;
32
- return g.getTreeChangeCheckedNodes(this.setting,g.getRoot(c)[a])};a.setChkDisabled=function(a,b,c,g){b=!!b;c=!!c;e.repairSonChkDisabled(this.setting,a,b,!!g);e.repairParentChkDisabled(this.setting,a.getParentNode(),b,c)};var b=a.updateNode;a.updateNode=function(c,h){b&&b.apply(a,arguments);if(c&&this.setting.check.enable&&m("#"+c.tId).get(0)&&l.uCanDo(this.setting)){var g=m("#"+c.tId+i.id.CHECK);(h==!0||this.setting.check.chkStyle===i.radio.STYLE)&&e.checkNodeRelation(this.setting,c);e.setChkClass(this.setting,
33
- g,c);e.repairParentChkClassWithSelf(this.setting,c)}}});var s=e.createNodes;e.createNodes=function(c,a,b,d){s&&s.apply(e,arguments);b&&e.repairParentChkClassWithSelf(c,d)};var t=e.removeNode;e.removeNode=function(c,a){var b=a.getParentNode();t&&t.apply(e,arguments);a&&b&&(e.repairChkClass(c,b),e.repairParentChkClass(c,b))};var u=e.appendNodes;e.appendNodes=function(c,a,b,d,h,i){var j="";u&&(j=u.apply(e,arguments));d&&g.makeChkFlag(c,d);return j}})(jQuery);
@@ -1,1178 +0,0 @@
1
- /*
2
- * JQuery zTree exedit 3.5.02
3
- * http://zTree.me/
4
- *
5
- * Copyright (c) 2010 Hunter.z
6
- *
7
- * Licensed same as jquery - MIT License
8
- * http://www.opensource.org/licenses/mit-license.php
9
- *
10
- * email: hunter.z@263.net
11
- * Date: 2013-01-28
12
- */
13
- (function($){
14
- //default consts of exedit
15
- var _consts = {
16
- event: {
17
- DRAG: "ztree_drag",
18
- DROP: "ztree_drop",
19
- REMOVE: "ztree_remove",
20
- RENAME: "ztree_rename"
21
- },
22
- id: {
23
- EDIT: "_edit",
24
- INPUT: "_input",
25
- REMOVE: "_remove"
26
- },
27
- move: {
28
- TYPE_INNER: "inner",
29
- TYPE_PREV: "prev",
30
- TYPE_NEXT: "next"
31
- },
32
- node: {
33
- CURSELECTED_EDIT: "curSelectedNode_Edit",
34
- TMPTARGET_TREE: "tmpTargetzTree",
35
- TMPTARGET_NODE: "tmpTargetNode"
36
- }
37
- },
38
- //default setting of exedit
39
- _setting = {
40
- edit: {
41
- enable: false,
42
- editNameSelectAll: false,
43
- showRemoveBtn: true,
44
- showRenameBtn: true,
45
- removeTitle: "remove",
46
- renameTitle: "rename",
47
- drag: {
48
- autoExpandTrigger: false,
49
- isCopy: true,
50
- isMove: true,
51
- prev: true,
52
- next: true,
53
- inner: true,
54
- minMoveSize: 5,
55
- borderMax: 10,
56
- borderMin: -5,
57
- maxShowNodeNum: 5,
58
- autoOpenTime: 500
59
- }
60
- },
61
- view: {
62
- addHoverDom: null,
63
- removeHoverDom: null
64
- },
65
- callback: {
66
- beforeDrag:null,
67
- beforeDragOpen:null,
68
- beforeDrop:null,
69
- beforeEditName:null,
70
- beforeRename:null,
71
- onDrag:null,
72
- onDrop:null,
73
- onRename:null
74
- }
75
- },
76
- //default root of exedit
77
- _initRoot = function (setting) {
78
- var r = data.getRoot(setting);
79
- r.curEditNode = null;
80
- r.curEditInput = null;
81
- r.curHoverNode = null;
82
- r.dragFlag = 0;
83
- r.dragNodeShowBefore = [];
84
- r.dragMaskList = new Array();
85
- r.showHoverDom = true;
86
- },
87
- //default cache of exedit
88
- _initCache = function(treeId) {},
89
- //default bind event of exedit
90
- _bindEvent = function(setting) {
91
- var o = setting.treeObj;
92
- var c = consts.event;
93
- o.bind(c.RENAME, function (event, treeId, treeNode) {
94
- tools.apply(setting.callback.onRename, [event, treeId, treeNode]);
95
- });
96
-
97
- o.bind(c.REMOVE, function (event, treeId, treeNode) {
98
- tools.apply(setting.callback.onRemove, [event, treeId, treeNode]);
99
- });
100
-
101
- o.bind(c.DRAG, function (event, srcEvent, treeId, treeNodes) {
102
- tools.apply(setting.callback.onDrag, [srcEvent, treeId, treeNodes]);
103
- });
104
-
105
- o.bind(c.DROP, function (event, srcEvent, treeId, treeNodes, targetNode, moveType, isCopy) {
106
- tools.apply(setting.callback.onDrop, [srcEvent, treeId, treeNodes, targetNode, moveType, isCopy]);
107
- });
108
- },
109
- _unbindEvent = function(setting) {
110
- var o = setting.treeObj;
111
- var c = consts.event;
112
- o.unbind(c.RENAME);
113
- o.unbind(c.REMOVE);
114
- o.unbind(c.DRAG);
115
- o.unbind(c.DROP);
116
- },
117
- //default event proxy of exedit
118
- _eventProxy = function(e) {
119
- var target = e.target,
120
- setting = data.getSetting(e.data.treeId),
121
- relatedTarget = e.relatedTarget,
122
- tId = "", node = null,
123
- nodeEventType = "", treeEventType = "",
124
- nodeEventCallback = null, treeEventCallback = null,
125
- tmp = null;
126
-
127
- if (tools.eqs(e.type, "mouseover")) {
128
- tmp = tools.getMDom(setting, target, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
129
- if (tmp) {
130
- tId = tmp.parentNode.id;
131
- nodeEventType = "hoverOverNode";
132
- }
133
- } else if (tools.eqs(e.type, "mouseout")) {
134
- tmp = tools.getMDom(setting, relatedTarget, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
135
- if (!tmp) {
136
- tId = "remove";
137
- nodeEventType = "hoverOutNode";
138
- }
139
- } else if (tools.eqs(e.type, "mousedown")) {
140
- tmp = tools.getMDom(setting, target, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
141
- if (tmp) {
142
- tId = tmp.parentNode.id;
143
- nodeEventType = "mousedownNode";
144
- }
145
- }
146
- if (tId.length>0) {
147
- node = data.getNodeCache(setting, tId);
148
- switch (nodeEventType) {
149
- case "mousedownNode" :
150
- nodeEventCallback = _handler.onMousedownNode;
151
- break;
152
- case "hoverOverNode" :
153
- nodeEventCallback = _handler.onHoverOverNode;
154
- break;
155
- case "hoverOutNode" :
156
- nodeEventCallback = _handler.onHoverOutNode;
157
- break;
158
- }
159
- }
160
- var proxyResult = {
161
- stop: false,
162
- node: node,
163
- nodeEventType: nodeEventType,
164
- nodeEventCallback: nodeEventCallback,
165
- treeEventType: treeEventType,
166
- treeEventCallback: treeEventCallback
167
- };
168
- return proxyResult
169
- },
170
- //default init node of exedit
171
- _initNode = function(setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
172
- if (!n) return;
173
- n.isHover = false;
174
- n.editNameFlag = false;
175
- },
176
- //update zTreeObj, add method of edit
177
- _zTreeTools = function(setting, zTreeTools) {
178
- zTreeTools.cancelEditName = function(newName) {
179
- var root = data.getRoot(setting),
180
- nameKey = setting.data.key.name,
181
- node = root.curEditNode;
182
- if (!root.curEditNode) return;
183
- view.cancelCurEditNode(setting, newName?newName:node[nameKey]);
184
- }
185
- zTreeTools.copyNode = function(targetNode, node, moveType, isSilent) {
186
- if (!node) return null;
187
- if (targetNode && !targetNode.isParent && setting.data.keep.leaf && moveType === consts.move.TYPE_INNER) return null;
188
- var newNode = tools.clone(node);
189
- if (!targetNode) {
190
- targetNode = null;
191
- moveType = consts.move.TYPE_INNER;
192
- }
193
- if (moveType == consts.move.TYPE_INNER) {
194
- function copyCallback() {
195
- view.addNodes(setting, targetNode, [newNode], isSilent);
196
- }
197
-
198
- if (tools.canAsync(setting, targetNode)) {
199
- view.asyncNode(setting, targetNode, isSilent, copyCallback);
200
- } else {
201
- copyCallback();
202
- }
203
- } else {
204
- view.addNodes(setting, targetNode.parentNode, [newNode], isSilent);
205
- view.moveNode(setting, targetNode, newNode, moveType, false, isSilent);
206
- }
207
- return newNode;
208
- }
209
- zTreeTools.editName = function(node) {
210
- if (!node || !node.tId || node !== data.getNodeCache(setting, node.tId)) return;
211
- if (node.parentTId) view.expandCollapseParentNode(setting, node.getParentNode(), true);
212
- view.editNode(setting, node)
213
- }
214
- zTreeTools.moveNode = function(targetNode, node, moveType, isSilent) {
215
- if (!node) return node;
216
- if (targetNode && !targetNode.isParent && setting.data.keep.leaf && moveType === consts.move.TYPE_INNER) {
217
- return null;
218
- } else if (targetNode && ((node.parentTId == targetNode.tId && moveType == consts.move.TYPE_INNER) || $("#" + node.tId).find("#" + targetNode.tId).length > 0)) {
219
- return null;
220
- } else if (!targetNode) {
221
- targetNode = null;
222
- }
223
- function moveCallback() {
224
- view.moveNode(setting, targetNode, node, moveType, false, isSilent);
225
- }
226
- if (tools.canAsync(setting, targetNode)) {
227
- view.asyncNode(setting, targetNode, isSilent, moveCallback);
228
- } else {
229
- moveCallback();
230
- }
231
- return node;
232
- }
233
- zTreeTools.setEditable = function(editable) {
234
- setting.edit.enable = editable;
235
- return this.refresh();
236
- }
237
- },
238
- //method of operate data
239
- _data = {
240
- setSonNodeLevel: function(setting, parentNode, node) {
241
- if (!node) return;
242
- var childKey = setting.data.key.children;
243
- node.level = (parentNode)? parentNode.level + 1 : 0;
244
- if (!node[childKey]) return;
245
- for (var i = 0, l = node[childKey].length; i < l; i++) {
246
- if (node[childKey][i]) data.setSonNodeLevel(setting, node, node[childKey][i]);
247
- }
248
- }
249
- },
250
- //method of event proxy
251
- _event = {
252
-
253
- },
254
- //method of event handler
255
- _handler = {
256
- onHoverOverNode: function(event, node) {
257
- var setting = data.getSetting(event.data.treeId),
258
- root = data.getRoot(setting);
259
- if (root.curHoverNode != node) {
260
- _handler.onHoverOutNode(event);
261
- }
262
- root.curHoverNode = node;
263
- view.addHoverDom(setting, node);
264
- },
265
- onHoverOutNode: function(event, node) {
266
- var setting = data.getSetting(event.data.treeId),
267
- root = data.getRoot(setting);
268
- if (root.curHoverNode && !data.isSelectedNode(setting, root.curHoverNode)) {
269
- view.removeTreeDom(setting, root.curHoverNode);
270
- root.curHoverNode = null;
271
- }
272
- },
273
- onMousedownNode: function(eventMouseDown, _node) {
274
- var i,l,
275
- setting = data.getSetting(eventMouseDown.data.treeId),
276
- root = data.getRoot(setting);
277
- //right click can't drag & drop
278
- if (eventMouseDown.button == 2 || !setting.edit.enable || (!setting.edit.drag.isCopy && !setting.edit.drag.isMove)) return true;
279
-
280
- //input of edit node name can't drag & drop
281
- var target = eventMouseDown.target,
282
- _nodes = data.getRoot(setting).curSelectedList,
283
- nodes = [];
284
- if (!data.isSelectedNode(setting, _node)) {
285
- nodes = [_node];
286
- } else {
287
- for (i=0, l=_nodes.length; i<l; i++) {
288
- if (_nodes[i].editNameFlag && tools.eqs(target.tagName, "input") && target.getAttribute("treeNode"+consts.id.INPUT) !== null) {
289
- return true;
290
- }
291
- nodes.push(_nodes[i]);
292
- if (nodes[0].parentTId !== _nodes[i].parentTId) {
293
- nodes = [_node];
294
- break;
295
- }
296
- }
297
- }
298
-
299
- view.editNodeBlur = true;
300
- view.cancelCurEditNode(setting, null, true);
301
-
302
-
303
- var doc = $(document), curNode, tmpArrow, tmpTarget,
304
- isOtherTree = false,
305
- targetSetting = setting,
306
- preNode, nextNode,
307
- preTmpTargetNodeId = null,
308
- preTmpMoveType = null,
309
- tmpTargetNodeId = null,
310
- moveType = consts.move.TYPE_INNER,
311
- mouseDownX = eventMouseDown.clientX,
312
- mouseDownY = eventMouseDown.clientY,
313
- startTime = (new Date()).getTime();
314
-
315
- if (tools.uCanDo(setting)) {
316
- doc.bind("mousemove", _docMouseMove);
317
- }
318
- function _docMouseMove(event) {
319
- //avoid start drag after click node
320
- if (root.dragFlag == 0 && Math.abs(mouseDownX - event.clientX) < setting.edit.drag.minMoveSize
321
- && Math.abs(mouseDownY - event.clientY) < setting.edit.drag.minMoveSize) {
322
- return true;
323
- }
324
- var i, l, tmpNode, tmpDom, tmpNodes,
325
- childKey = setting.data.key.children;
326
- $("body").css("cursor", "pointer");
327
-
328
- if (root.dragFlag == 0) {
329
- if (tools.apply(setting.callback.beforeDrag, [setting.treeId, nodes], true) == false) {
330
- _docMouseUp(event);
331
- return true;
332
- }
333
-
334
- for (i=0, l=nodes.length; i<l; i++) {
335
- if (i==0) {
336
- root.dragNodeShowBefore = [];
337
- }
338
- tmpNode = nodes[i];
339
- if (tmpNode.isParent && tmpNode.open) {
340
- view.expandCollapseNode(setting, tmpNode, !tmpNode.open);
341
- root.dragNodeShowBefore[tmpNode.tId] = true;
342
- } else {
343
- root.dragNodeShowBefore[tmpNode.tId] = false;
344
- }
345
- }
346
-
347
- root.dragFlag = 1;
348
- root.showHoverDom = false;
349
- tools.showIfameMask(setting, true);
350
-
351
- //sort
352
- var isOrder = true, lastIndex = -1;
353
- if (nodes.length>1) {
354
- var pNodes = nodes[0].parentTId ? nodes[0].getParentNode()[childKey] : data.getNodes(setting);
355
- tmpNodes = [];
356
- for (i=0, l=pNodes.length; i<l; i++) {
357
- if (root.dragNodeShowBefore[pNodes[i].tId] !== undefined) {
358
- if (isOrder && lastIndex > -1 && (lastIndex+1) !== i) {
359
- isOrder = false;
360
- }
361
- tmpNodes.push(pNodes[i]);
362
- lastIndex = i;
363
- }
364
- if (nodes.length === tmpNodes.length) {
365
- nodes = tmpNodes;
366
- break;
367
- }
368
- }
369
- }
370
- if (isOrder) {
371
- preNode = nodes[0].getPreNode();
372
- nextNode = nodes[nodes.length-1].getNextNode();
373
- }
374
-
375
- //set node in selected
376
- curNode = $("<ul class='zTreeDragUL'></ul>");
377
- for (i=0, l=nodes.length; i<l; i++) {
378
- tmpNode = nodes[i];
379
- tmpNode.editNameFlag = false;
380
- view.selectNode(setting, tmpNode, i>0);
381
- view.removeTreeDom(setting, tmpNode);
382
-
383
- tmpDom = $("<li id='"+ tmpNode.tId +"_tmp'></li>");
384
- tmpDom.append($("#" + tmpNode.tId + consts.id.A).clone());
385
- tmpDom.css("padding", "0");
386
- tmpDom.children("#" + tmpNode.tId + consts.id.A).removeClass(consts.node.CURSELECTED);
387
- curNode.append(tmpDom);
388
- if (i == setting.edit.drag.maxShowNodeNum-1) {
389
- tmpDom = $("<li id='"+ tmpNode.tId +"_moretmp'><a> ... </a></li>");
390
- curNode.append(tmpDom);
391
- break;
392
- }
393
- }
394
- curNode.attr("id", nodes[0].tId + consts.id.UL + "_tmp");
395
- curNode.addClass(setting.treeObj.attr("class"));
396
- curNode.appendTo("body");
397
-
398
- tmpArrow = $("<span class='tmpzTreeMove_arrow'></span>");
399
- tmpArrow.attr("id", "zTreeMove_arrow_tmp");
400
- tmpArrow.appendTo("body");
401
-
402
- setting.treeObj.trigger(consts.event.DRAG, [event, setting.treeId, nodes]);
403
- }
404
-
405
- if (root.dragFlag == 1) {
406
- if (tmpTarget && tmpArrow.attr("id") == event.target.id && tmpTargetNodeId && (event.clientX + doc.scrollLeft()+2) > ($("#" + tmpTargetNodeId + consts.id.A, tmpTarget).offset().left)) {
407
- var xT = $("#" + tmpTargetNodeId + consts.id.A, tmpTarget);
408
- event.target = (xT.length > 0) ? xT.get(0) : event.target;
409
- } else if (tmpTarget) {
410
- tmpTarget.removeClass(consts.node.TMPTARGET_TREE);
411
- if (tmpTargetNodeId) $("#" + tmpTargetNodeId + consts.id.A, tmpTarget).removeClass(consts.node.TMPTARGET_NODE + "_" + consts.move.TYPE_PREV)
412
- .removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_NEXT).removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_INNER);
413
- }
414
- tmpTarget = null;
415
- tmpTargetNodeId = null;
416
-
417
- //judge drag & drop in multi ztree
418
- isOtherTree = false;
419
- targetSetting = setting;
420
- var settings = data.getSettings();
421
- for (var s in settings) {
422
- if (settings[s].treeId && settings[s].edit.enable && settings[s].treeId != setting.treeId
423
- && (event.target.id == settings[s].treeId || $(event.target).parents("#" + settings[s].treeId).length>0)) {
424
- isOtherTree = true;
425
- targetSetting = settings[s];
426
- }
427
- }
428
-
429
- var docScrollTop = doc.scrollTop(),
430
- docScrollLeft = doc.scrollLeft(),
431
- treeOffset = targetSetting.treeObj.offset(),
432
- scrollHeight = targetSetting.treeObj.get(0).scrollHeight,
433
- scrollWidth = targetSetting.treeObj.get(0).scrollWidth,
434
- dTop = (event.clientY + docScrollTop - treeOffset.top),
435
- dBottom = (targetSetting.treeObj.height() + treeOffset.top - event.clientY - docScrollTop),
436
- dLeft = (event.clientX + docScrollLeft - treeOffset.left),
437
- dRight = (targetSetting.treeObj.width() + treeOffset.left - event.clientX - docScrollLeft),
438
- isTop = (dTop < setting.edit.drag.borderMax && dTop > setting.edit.drag.borderMin),
439
- isBottom = (dBottom < setting.edit.drag.borderMax && dBottom > setting.edit.drag.borderMin),
440
- isLeft = (dLeft < setting.edit.drag.borderMax && dLeft > setting.edit.drag.borderMin),
441
- isRight = (dRight < setting.edit.drag.borderMax && dRight > setting.edit.drag.borderMin),
442
- isTreeInner = dTop > setting.edit.drag.borderMin && dBottom > setting.edit.drag.borderMin && dLeft > setting.edit.drag.borderMin && dRight > setting.edit.drag.borderMin,
443
- isTreeTop = (isTop && targetSetting.treeObj.scrollTop() <= 0),
444
- isTreeBottom = (isBottom && (targetSetting.treeObj.scrollTop() + targetSetting.treeObj.height()+10) >= scrollHeight),
445
- isTreeLeft = (isLeft && targetSetting.treeObj.scrollLeft() <= 0),
446
- isTreeRight = (isRight && (targetSetting.treeObj.scrollLeft() + targetSetting.treeObj.width()+10) >= scrollWidth);
447
-
448
- if (event.target.id && targetSetting.treeObj.find("#" + event.target.id).length > 0) {
449
- //get node <li> dom
450
- var targetObj = event.target;
451
- while (targetObj && targetObj.tagName && !tools.eqs(targetObj.tagName, "li") && targetObj.id != targetSetting.treeId) {
452
- targetObj = targetObj.parentNode;
453
- }
454
-
455
- var canMove = true;
456
- //don't move to self or children of self
457
- for (i=0, l=nodes.length; i<l; i++) {
458
- tmpNode = nodes[i];
459
- if (targetObj.id === tmpNode.tId) {
460
- canMove = false;
461
- break;
462
- } else if ($("#" + tmpNode.tId).find("#" + targetObj.id).length > 0) {
463
- canMove = false;
464
- break;
465
- }
466
- }
467
- if (canMove) {
468
- if (event.target.id &&
469
- (event.target.id == (targetObj.id + consts.id.A) || $(event.target).parents("#" + targetObj.id + consts.id.A).length > 0)) {
470
- tmpTarget = $(targetObj);
471
- tmpTargetNodeId = targetObj.id;
472
- }
473
- }
474
- }
475
-
476
- //the mouse must be in zTree
477
- tmpNode = nodes[0];
478
- if (isTreeInner && (event.target.id == targetSetting.treeId || $(event.target).parents("#" + targetSetting.treeId).length>0)) {
479
- //judge mouse move in root of ztree
480
- if (!tmpTarget && (event.target.id == targetSetting.treeId || isTreeTop || isTreeBottom || isTreeLeft || isTreeRight) && (isOtherTree || (!isOtherTree && tmpNode.parentTId))) {
481
- tmpTarget = targetSetting.treeObj;
482
- }
483
- //auto scroll top
484
- if (isTop) {
485
- targetSetting.treeObj.scrollTop(targetSetting.treeObj.scrollTop()-10);
486
- } else if (isBottom) {
487
- targetSetting.treeObj.scrollTop(targetSetting.treeObj.scrollTop()+10);
488
- }
489
- if (isLeft) {
490
- targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft()-10);
491
- } else if (isRight) {
492
- targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft()+10);
493
- }
494
- //auto scroll left
495
- if (tmpTarget && tmpTarget != targetSetting.treeObj && tmpTarget.offset().left < targetSetting.treeObj.offset().left) {
496
- targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft()+ tmpTarget.offset().left - targetSetting.treeObj.offset().left);
497
- }
498
- }
499
-
500
- curNode.css({
501
- "top": (event.clientY + docScrollTop + 3) + "px",
502
- "left": (event.clientX + docScrollLeft + 3) + "px"
503
- });
504
-
505
- var dX = 0;
506
- var dY = 0;
507
- if (tmpTarget && tmpTarget.attr("id")!=targetSetting.treeId) {
508
- var tmpTargetNode = tmpTargetNodeId == null ? null: data.getNodeCache(targetSetting, tmpTargetNodeId),
509
- isCopy = (event.ctrlKey && setting.edit.drag.isMove && setting.edit.drag.isCopy) || (!setting.edit.drag.isMove && setting.edit.drag.isCopy),
510
- isPrev = !!(preNode && tmpTargetNodeId === preNode.tId),
511
- isNext = !!(nextNode && tmpTargetNodeId === nextNode.tId),
512
- isInner = (tmpNode.parentTId && tmpNode.parentTId == tmpTargetNodeId),
513
- canPrev = (isCopy || !isNext) && tools.apply(targetSetting.edit.drag.prev, [targetSetting.treeId, nodes, tmpTargetNode], !!targetSetting.edit.drag.prev),
514
- canNext = (isCopy || !isPrev) && tools.apply(targetSetting.edit.drag.next, [targetSetting.treeId, nodes, tmpTargetNode], !!targetSetting.edit.drag.next),
515
- canInner = (isCopy || !isInner) && !(targetSetting.data.keep.leaf && !tmpTargetNode.isParent) && tools.apply(targetSetting.edit.drag.inner, [targetSetting.treeId, nodes, tmpTargetNode], !!targetSetting.edit.drag.inner);
516
- if (!canPrev && !canNext && !canInner) {
517
- tmpTarget = null;
518
- tmpTargetNodeId = "";
519
- moveType = consts.move.TYPE_INNER;
520
- tmpArrow.css({
521
- "display":"none"
522
- });
523
- if (window.zTreeMoveTimer) {
524
- clearTimeout(window.zTreeMoveTimer);
525
- window.zTreeMoveTargetNodeTId = null
526
- }
527
- } else {
528
- var tmpTargetA = $("#" + tmpTargetNodeId + consts.id.A, tmpTarget),
529
- tmpNextA = tmpTargetNode.isLastNode ? null : $("#" + tmpTargetNode.getNextNode().tId + consts.id.A, tmpTarget.next()),
530
- tmpTop = tmpTargetA.offset().top,
531
- tmpLeft = tmpTargetA.offset().left,
532
- prevPercent = canPrev ? (canInner ? 0.25 : (canNext ? 0.5 : 1) ) : -1,
533
- nextPercent = canNext ? (canInner ? 0.75 : (canPrev ? 0.5 : 0) ) : -1,
534
- dY_percent = (event.clientY + docScrollTop - tmpTop)/tmpTargetA.height();
535
- if ((prevPercent==1 ||dY_percent<=prevPercent && dY_percent>=-.2) && canPrev) {
536
- dX = 1 - tmpArrow.width();
537
- dY = tmpTop - tmpArrow.height()/2;
538
- moveType = consts.move.TYPE_PREV;
539
- } else if ((nextPercent==0 || dY_percent>=nextPercent && dY_percent<=1.2) && canNext) {
540
- dX = 1 - tmpArrow.width();
541
- dY = (tmpNextA == null || (tmpTargetNode.isParent && tmpTargetNode.open)) ? (tmpTop + tmpTargetA.height() - tmpArrow.height()/2) : (tmpNextA.offset().top - tmpArrow.height()/2);
542
- moveType = consts.move.TYPE_NEXT;
543
- }else {
544
- dX = 5 - tmpArrow.width();
545
- dY = tmpTop;
546
- moveType = consts.move.TYPE_INNER;
547
- }
548
- tmpArrow.css({
549
- "display":"block",
550
- "top": dY + "px",
551
- "left": (tmpLeft + dX) + "px"
552
- });
553
- tmpTargetA.addClass(consts.node.TMPTARGET_NODE + "_" + moveType);
554
-
555
- if (preTmpTargetNodeId != tmpTargetNodeId || preTmpMoveType != moveType) {
556
- startTime = (new Date()).getTime();
557
- }
558
- if (tmpTargetNode && tmpTargetNode.isParent && moveType == consts.move.TYPE_INNER) {
559
- var startTimer = true;
560
- if (window.zTreeMoveTimer && window.zTreeMoveTargetNodeTId !== tmpTargetNode.tId) {
561
- clearTimeout(window.zTreeMoveTimer);
562
- window.zTreeMoveTargetNodeTId = null;
563
- } else if (window.zTreeMoveTimer && window.zTreeMoveTargetNodeTId === tmpTargetNode.tId) {
564
- startTimer = false;
565
- }
566
- if (startTimer) {
567
- window.zTreeMoveTimer = setTimeout(function() {
568
- if (moveType != consts.move.TYPE_INNER) return;
569
- if (tmpTargetNode && tmpTargetNode.isParent && !tmpTargetNode.open && (new Date()).getTime() - startTime > targetSetting.edit.drag.autoOpenTime
570
- && tools.apply(targetSetting.callback.beforeDragOpen, [targetSetting.treeId, tmpTargetNode], true)) {
571
- view.switchNode(targetSetting, tmpTargetNode);
572
- if (targetSetting.edit.drag.autoExpandTrigger) {
573
- targetSetting.treeObj.trigger(consts.event.EXPAND, [targetSetting.treeId, tmpTargetNode]);
574
- }
575
- }
576
- }, targetSetting.edit.drag.autoOpenTime+50);
577
- window.zTreeMoveTargetNodeTId = tmpTargetNode.tId;
578
- }
579
- }
580
- }
581
- } else {
582
- moveType = consts.move.TYPE_INNER;
583
- if (tmpTarget && tools.apply(targetSetting.edit.drag.inner, [targetSetting.treeId, nodes, null], !!targetSetting.edit.drag.inner)) {
584
- tmpTarget.addClass(consts.node.TMPTARGET_TREE);
585
- } else {
586
- tmpTarget = null;
587
- }
588
- tmpArrow.css({
589
- "display":"none"
590
- });
591
- if (window.zTreeMoveTimer) {
592
- clearTimeout(window.zTreeMoveTimer);
593
- window.zTreeMoveTargetNodeTId = null;
594
- }
595
- }
596
- preTmpTargetNodeId = tmpTargetNodeId;
597
- preTmpMoveType = moveType;
598
- }
599
- return false;
600
- }
601
-
602
- doc.bind("mouseup", _docMouseUp);
603
- function _docMouseUp(event) {
604
- if (window.zTreeMoveTimer) {
605
- clearTimeout(window.zTreeMoveTimer);
606
- window.zTreeMoveTargetNodeTId = null;
607
- }
608
- preTmpTargetNodeId = null;
609
- preTmpMoveType = null;
610
- doc.unbind("mousemove", _docMouseMove);
611
- doc.unbind("mouseup", _docMouseUp);
612
- doc.unbind("selectstart", _docSelect);
613
- $("body").css("cursor", "auto");
614
- if (tmpTarget) {
615
- tmpTarget.removeClass(consts.node.TMPTARGET_TREE);
616
- if (tmpTargetNodeId) $("#" + tmpTargetNodeId + consts.id.A, tmpTarget).removeClass(consts.node.TMPTARGET_NODE + "_" + consts.move.TYPE_PREV)
617
- .removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_NEXT).removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_INNER);
618
- }
619
- tools.showIfameMask(setting, false);
620
-
621
- root.showHoverDom = true;
622
- if (root.dragFlag == 0) return;
623
- root.dragFlag = 0;
624
-
625
- var i, l, tmpNode;
626
- for (i=0, l=nodes.length; i<l; i++) {
627
- tmpNode = nodes[i];
628
- if (tmpNode.isParent && root.dragNodeShowBefore[tmpNode.tId] && !tmpNode.open) {
629
- view.expandCollapseNode(setting, tmpNode, !tmpNode.open);
630
- delete root.dragNodeShowBefore[tmpNode.tId];
631
- }
632
- }
633
-
634
- if (curNode) curNode.remove();
635
- if (tmpArrow) tmpArrow.remove();
636
-
637
- var isCopy = (event.ctrlKey && setting.edit.drag.isMove && setting.edit.drag.isCopy) || (!setting.edit.drag.isMove && setting.edit.drag.isCopy);
638
- if (!isCopy && tmpTarget && tmpTargetNodeId && nodes[0].parentTId && tmpTargetNodeId==nodes[0].parentTId && moveType == consts.move.TYPE_INNER) {
639
- tmpTarget = null;
640
- }
641
- if (tmpTarget) {
642
- var dragTargetNode = tmpTargetNodeId == null ? null: data.getNodeCache(targetSetting, tmpTargetNodeId);
643
- if (tools.apply(setting.callback.beforeDrop, [targetSetting.treeId, nodes, dragTargetNode, moveType, isCopy], true) == false) return;
644
- var newNodes = isCopy ? tools.clone(nodes) : nodes;
645
-
646
- function dropCallback() {
647
- if (isOtherTree) {
648
- if (!isCopy) {
649
- for(var i=0, l=nodes.length; i<l; i++) {
650
- view.removeNode(setting, nodes[i]);
651
- }
652
- }
653
- if (moveType == consts.move.TYPE_INNER) {
654
- view.addNodes(targetSetting, dragTargetNode, newNodes);
655
- } else {
656
- view.addNodes(targetSetting, dragTargetNode.getParentNode(), newNodes);
657
- if (moveType == consts.move.TYPE_PREV) {
658
- for (i=0, l=newNodes.length; i<l; i++) {
659
- view.moveNode(targetSetting, dragTargetNode, newNodes[i], moveType, false);
660
- }
661
- } else {
662
- for (i=-1, l=newNodes.length-1; i<l; l--) {
663
- view.moveNode(targetSetting, dragTargetNode, newNodes[l], moveType, false);
664
- }
665
- }
666
- }
667
- } else {
668
- if (isCopy && moveType == consts.move.TYPE_INNER) {
669
- view.addNodes(targetSetting, dragTargetNode, newNodes);
670
- } else {
671
- if (isCopy) {
672
- view.addNodes(targetSetting, dragTargetNode.getParentNode(), newNodes);
673
- }
674
- if (moveType != consts.move.TYPE_NEXT) {
675
- for (i=0, l=newNodes.length; i<l; i++) {
676
- view.moveNode(targetSetting, dragTargetNode, newNodes[i], moveType, false);
677
- }
678
- } else {
679
- for (i=-1, l=newNodes.length-1; i<l; l--) {
680
- view.moveNode(targetSetting, dragTargetNode, newNodes[l], moveType, false);
681
- }
682
- }
683
- }
684
- }
685
- for (i=0, l=newNodes.length; i<l; i++) {
686
- view.selectNode(targetSetting, newNodes[i], i>0);
687
- }
688
- $("#" + newNodes[0].tId).focus().blur();
689
-
690
- setting.treeObj.trigger(consts.event.DROP, [event, targetSetting.treeId, newNodes, dragTargetNode, moveType, isCopy]);
691
- }
692
-
693
- if (moveType == consts.move.TYPE_INNER && tools.canAsync(targetSetting, dragTargetNode)) {
694
- view.asyncNode(targetSetting, dragTargetNode, false, dropCallback);
695
- } else {
696
- dropCallback();
697
- }
698
-
699
- } else {
700
- for (i=0, l=nodes.length; i<l; i++) {
701
- view.selectNode(targetSetting, nodes[i], i>0);
702
- }
703
- setting.treeObj.trigger(consts.event.DROP, [event, setting.treeId, nodes, null, null, null]);
704
- }
705
- }
706
-
707
- doc.bind("selectstart", _docSelect);
708
- function _docSelect() {
709
- return false;
710
- }
711
-
712
- //Avoid FireFox's Bug
713
- //If zTree Div CSS set 'overflow', so drag node outside of zTree, and event.target is error.
714
- if(eventMouseDown.preventDefault) {
715
- eventMouseDown.preventDefault();
716
- }
717
- return true;
718
- }
719
- },
720
- //method of tools for zTree
721
- _tools = {
722
- getAbs: function (obj) {
723
- var oRect = obj.getBoundingClientRect();
724
- return [oRect.left,oRect.top]
725
- },
726
- inputFocus: function(inputObj) {
727
- if (inputObj.get(0)) {
728
- inputObj.focus();
729
- tools.setCursorPosition(inputObj.get(0), inputObj.val().length);
730
- }
731
- },
732
- inputSelect: function(inputObj) {
733
- if (inputObj.get(0)) {
734
- inputObj.focus();
735
- inputObj.select();
736
- }
737
- },
738
- setCursorPosition: function(obj, pos){
739
- if(obj.setSelectionRange) {
740
- obj.focus();
741
- obj.setSelectionRange(pos,pos);
742
- } else if (obj.createTextRange) {
743
- var range = obj.createTextRange();
744
- range.collapse(true);
745
- range.moveEnd('character', pos);
746
- range.moveStart('character', pos);
747
- range.select();
748
- }
749
- },
750
- showIfameMask: function(setting, showSign) {
751
- var root = data.getRoot(setting);
752
- //clear full mask
753
- while (root.dragMaskList.length > 0) {
754
- root.dragMaskList[0].remove();
755
- root.dragMaskList.shift();
756
- }
757
- if (showSign) {
758
- //show mask
759
- var iframeList = $("iframe");
760
- for (var i = 0, l = iframeList.length; i < l; i++) {
761
- var obj = iframeList.get(i),
762
- r = tools.getAbs(obj),
763
- dragMask = $("<div id='zTreeMask_" + i + "' class='zTreeMask' style='top:" + r[1] + "px; left:" + r[0] + "px; width:" + obj.offsetWidth + "px; height:" + obj.offsetHeight + "px;'></div>");
764
- dragMask.appendTo("body");
765
- root.dragMaskList.push(dragMask);
766
- }
767
- }
768
- }
769
- },
770
- //method of operate ztree dom
771
- _view = {
772
- addEditBtn: function(setting, node) {
773
- if (node.editNameFlag || $("#" + node.tId + consts.id.EDIT).length > 0) {
774
- return;
775
- }
776
- if (!tools.apply(setting.edit.showRenameBtn, [setting.treeId, node], setting.edit.showRenameBtn)) {
777
- return;
778
- }
779
- var aObj = $("#" + node.tId + consts.id.A),
780
- editStr = "<span class='button edit' id='" + node.tId + consts.id.EDIT + "' title='"+tools.apply(setting.edit.renameTitle, [setting.treeId, node], setting.edit.renameTitle)+"' treeNode"+consts.id.EDIT+" style='display:none;'></span>";
781
- aObj.append(editStr);
782
-
783
- $("#" + node.tId + consts.id.EDIT).bind('click',
784
- function() {
785
- if (!tools.uCanDo(setting) || tools.apply(setting.callback.beforeEditName, [setting.treeId, node], true) == false) return false;
786
- view.editNode(setting, node);
787
- return false;
788
- }
789
- ).show();
790
- },
791
- addRemoveBtn: function(setting, node) {
792
- if (node.editNameFlag || $("#" + node.tId + consts.id.REMOVE).length > 0) {
793
- return;
794
- }
795
- if (!tools.apply(setting.edit.showRemoveBtn, [setting.treeId, node], setting.edit.showRemoveBtn)) {
796
- return;
797
- }
798
- var aObj = $("#" + node.tId + consts.id.A),
799
- removeStr = "<span class='button remove' id='" + node.tId + consts.id.REMOVE + "' title='"+tools.apply(setting.edit.removeTitle, [setting.treeId, node], setting.edit.removeTitle)+"' treeNode"+consts.id.REMOVE+" style='display:none;'></span>";
800
- aObj.append(removeStr);
801
-
802
- $("#" + node.tId + consts.id.REMOVE).bind('click',
803
- function() {
804
- if (!tools.uCanDo(setting) || tools.apply(setting.callback.beforeRemove, [setting.treeId, node], true) == false) return false;
805
- view.removeNode(setting, node);
806
- setting.treeObj.trigger(consts.event.REMOVE, [setting.treeId, node]);
807
- return false;
808
- }
809
- ).bind('mousedown',
810
- function(eventMouseDown) {
811
- return true;
812
- }
813
- ).show();
814
- },
815
- addHoverDom: function(setting, node) {
816
- if (data.getRoot(setting).showHoverDom) {
817
- node.isHover = true;
818
- if (setting.edit.enable) {
819
- view.addEditBtn(setting, node);
820
- view.addRemoveBtn(setting, node);
821
- }
822
- tools.apply(setting.view.addHoverDom, [setting.treeId, node]);
823
- }
824
- },
825
- cancelCurEditNode: function (setting, forceName) {
826
- var root = data.getRoot(setting),
827
- nameKey = setting.data.key.name,
828
- node = root.curEditNode;
829
-
830
- if (node) {
831
- var inputObj = root.curEditInput;
832
- var newName = forceName ? forceName:inputObj.val();
833
- if (!forceName && tools.apply(setting.callback.beforeRename, [setting.treeId, node, newName], true) === false) {
834
- return false;
835
- } else {
836
- node[nameKey] = newName ? newName:inputObj.val();
837
- if (!forceName) {
838
- setting.treeObj.trigger(consts.event.RENAME, [setting.treeId, node]);
839
- }
840
- }
841
- var aObj = $("#" + node.tId + consts.id.A);
842
- aObj.removeClass(consts.node.CURSELECTED_EDIT);
843
- inputObj.unbind();
844
- view.setNodeName(setting, node);
845
- node.editNameFlag = false;
846
- root.curEditNode = null;
847
- root.curEditInput = null;
848
- view.selectNode(setting, node, false);
849
- }
850
- root.noSelection = true;
851
- return true;
852
- },
853
- editNode: function(setting, node) {
854
- var root = data.getRoot(setting);
855
- view.editNodeBlur = false;
856
- if (data.isSelectedNode(setting, node) && root.curEditNode == node && node.editNameFlag) {
857
- setTimeout(function() {tools.inputFocus(root.curEditInput);}, 0);
858
- return;
859
- }
860
- var nameKey = setting.data.key.name;
861
- node.editNameFlag = true;
862
- view.removeTreeDom(setting, node);
863
- view.cancelCurEditNode(setting);
864
- view.selectNode(setting, node, false);
865
- $("#" + node.tId + consts.id.SPAN).html("<input type=text class='rename' id='" + node.tId + consts.id.INPUT + "' treeNode" + consts.id.INPUT + " >");
866
- var inputObj = $("#" + node.tId + consts.id.INPUT);
867
- inputObj.attr("value", node[nameKey]);
868
- if (setting.edit.editNameSelectAll) {
869
- tools.inputSelect(inputObj);
870
- } else {
871
- tools.inputFocus(inputObj);
872
- }
873
-
874
- inputObj.bind('blur', function(event) {
875
- if (!view.editNodeBlur) {
876
- view.cancelCurEditNode(setting);
877
- }
878
- }).bind('keydown', function(event) {
879
- if (event.keyCode=="13") {
880
- view.editNodeBlur = true;
881
- view.cancelCurEditNode(setting, null, true);
882
- } else if (event.keyCode=="27") {
883
- view.cancelCurEditNode(setting, node[nameKey]);
884
- }
885
- }).bind('click', function(event) {
886
- return false;
887
- }).bind('dblclick', function(event) {
888
- return false;
889
- });
890
-
891
- $("#" + node.tId + consts.id.A).addClass(consts.node.CURSELECTED_EDIT);
892
- root.curEditInput = inputObj;
893
- root.noSelection = false;
894
- root.curEditNode = node;
895
- },
896
- moveNode: function(setting, targetNode, node, moveType, animateFlag, isSilent) {
897
- var root = data.getRoot(setting),
898
- childKey = setting.data.key.children;
899
- if (targetNode == node) return;
900
- if (setting.data.keep.leaf && targetNode && !targetNode.isParent && moveType == consts.move.TYPE_INNER) return;
901
- var oldParentNode = (node.parentTId ? node.getParentNode(): root),
902
- targetNodeIsRoot = (targetNode === null || targetNode == root);
903
- if (targetNodeIsRoot && targetNode === null) targetNode = root;
904
- if (targetNodeIsRoot) moveType = consts.move.TYPE_INNER;
905
- var targetParentNode = (targetNode.parentTId ? targetNode.getParentNode() : root);
906
-
907
- if (moveType != consts.move.TYPE_PREV && moveType != consts.move.TYPE_NEXT) {
908
- moveType = consts.move.TYPE_INNER;
909
- }
910
-
911
- if (moveType == consts.move.TYPE_INNER) {
912
- if (targetNodeIsRoot) {
913
- //parentTId of root node is null
914
- node.parentTId = null;
915
- } else {
916
- if (!targetNode.isParent) {
917
- targetNode.isParent = true;
918
- targetNode.open = !!targetNode.open;
919
- view.setNodeLineIcos(setting, targetNode);
920
- }
921
- node.parentTId = targetNode.tId;
922
- }
923
- }
924
-
925
- //move node Dom
926
- var targetObj, target_ulObj;
927
- if (targetNodeIsRoot) {
928
- targetObj = setting.treeObj;
929
- target_ulObj = targetObj;
930
- } else {
931
- if (!isSilent && moveType == consts.move.TYPE_INNER) {
932
- view.expandCollapseNode(setting, targetNode, true, false);
933
- } else if (!isSilent) {
934
- view.expandCollapseNode(setting, targetNode.getParentNode(), true, false);
935
- }
936
- targetObj = $("#" + targetNode.tId);
937
- target_ulObj = $("#" + targetNode.tId + consts.id.UL);
938
- if (!!targetObj.get(0) && !target_ulObj.get(0)) {
939
- var ulstr = [];
940
- view.makeUlHtml(setting, targetNode, ulstr, '');
941
- targetObj.append(ulstr.join(''));
942
- }
943
- target_ulObj = $("#" + targetNode.tId + consts.id.UL);
944
- }
945
- var nodeDom = $("#" + node.tId);
946
- if (!nodeDom.get(0)) {
947
- nodeDom = view.appendNodes(setting, node.level, [node], null, false, true).join('');
948
- } else if (!targetObj.get(0)) {
949
- nodeDom.remove();
950
- }
951
- if (target_ulObj.get(0) && moveType == consts.move.TYPE_INNER) {
952
- target_ulObj.append(nodeDom);
953
- } else if (targetObj.get(0) && moveType == consts.move.TYPE_PREV) {
954
- targetObj.before(nodeDom);
955
- } else if (targetObj.get(0) && moveType == consts.move.TYPE_NEXT) {
956
- targetObj.after(nodeDom);
957
- }
958
-
959
- //repair the data after move
960
- var i,l,
961
- tmpSrcIndex = -1,
962
- tmpTargetIndex = 0,
963
- oldNeighbor = null,
964
- newNeighbor = null,
965
- oldLevel = node.level;
966
- if (node.isFirstNode) {
967
- tmpSrcIndex = 0;
968
- if (oldParentNode[childKey].length > 1 ) {
969
- oldNeighbor = oldParentNode[childKey][1];
970
- oldNeighbor.isFirstNode = true;
971
- }
972
- } else if (node.isLastNode) {
973
- tmpSrcIndex = oldParentNode[childKey].length -1;
974
- oldNeighbor = oldParentNode[childKey][tmpSrcIndex - 1];
975
- oldNeighbor.isLastNode = true;
976
- } else {
977
- for (i = 0, l = oldParentNode[childKey].length; i < l; i++) {
978
- if (oldParentNode[childKey][i].tId == node.tId) {
979
- tmpSrcIndex = i;
980
- break;
981
- }
982
- }
983
- }
984
- if (tmpSrcIndex >= 0) {
985
- oldParentNode[childKey].splice(tmpSrcIndex, 1);
986
- }
987
- if (moveType != consts.move.TYPE_INNER) {
988
- for (i = 0, l = targetParentNode[childKey].length; i < l; i++) {
989
- if (targetParentNode[childKey][i].tId == targetNode.tId) tmpTargetIndex = i;
990
- }
991
- }
992
- if (moveType == consts.move.TYPE_INNER) {
993
- if (!targetNode[childKey]) targetNode[childKey] = new Array();
994
- if (targetNode[childKey].length > 0) {
995
- newNeighbor = targetNode[childKey][targetNode[childKey].length - 1];
996
- newNeighbor.isLastNode = false;
997
- }
998
- targetNode[childKey].splice(targetNode[childKey].length, 0, node);
999
- node.isLastNode = true;
1000
- node.isFirstNode = (targetNode[childKey].length == 1);
1001
- } else if (targetNode.isFirstNode && moveType == consts.move.TYPE_PREV) {
1002
- targetParentNode[childKey].splice(tmpTargetIndex, 0, node);
1003
- newNeighbor = targetNode;
1004
- newNeighbor.isFirstNode = false;
1005
- node.parentTId = targetNode.parentTId;
1006
- node.isFirstNode = true;
1007
- node.isLastNode = false;
1008
-
1009
- } else if (targetNode.isLastNode && moveType == consts.move.TYPE_NEXT) {
1010
- targetParentNode[childKey].splice(tmpTargetIndex + 1, 0, node);
1011
- newNeighbor = targetNode;
1012
- newNeighbor.isLastNode = false;
1013
- node.parentTId = targetNode.parentTId;
1014
- node.isFirstNode = false;
1015
- node.isLastNode = true;
1016
-
1017
- } else {
1018
- if (moveType == consts.move.TYPE_PREV) {
1019
- targetParentNode[childKey].splice(tmpTargetIndex, 0, node);
1020
- } else {
1021
- targetParentNode[childKey].splice(tmpTargetIndex + 1, 0, node);
1022
- }
1023
- node.parentTId = targetNode.parentTId;
1024
- node.isFirstNode = false;
1025
- node.isLastNode = false;
1026
- }
1027
- data.fixPIdKeyValue(setting, node);
1028
- data.setSonNodeLevel(setting, node.getParentNode(), node);
1029
-
1030
- //repair node what been moved
1031
- view.setNodeLineIcos(setting, node);
1032
- view.repairNodeLevelClass(setting, node, oldLevel)
1033
-
1034
- //repair node's old parentNode dom
1035
- if (!setting.data.keep.parent && oldParentNode[childKey].length < 1) {
1036
- //old parentNode has no child nodes
1037
- oldParentNode.isParent = false;
1038
- oldParentNode.open = false;
1039
- var tmp_ulObj = $("#" + oldParentNode.tId + consts.id.UL),
1040
- tmp_switchObj = $("#" + oldParentNode.tId + consts.id.SWITCH),
1041
- tmp_icoObj = $("#" + oldParentNode.tId + consts.id.ICON);
1042
- view.replaceSwitchClass(oldParentNode, tmp_switchObj, consts.folder.DOCU);
1043
- view.replaceIcoClass(oldParentNode, tmp_icoObj, consts.folder.DOCU);
1044
- tmp_ulObj.css("display", "none");
1045
-
1046
- } else if (oldNeighbor) {
1047
- //old neigbor node
1048
- view.setNodeLineIcos(setting, oldNeighbor);
1049
- }
1050
-
1051
- //new neigbor node
1052
- if (newNeighbor) {
1053
- view.setNodeLineIcos(setting, newNeighbor);
1054
- }
1055
-
1056
- //repair checkbox / radio
1057
- if (!!setting.check && setting.check.enable && view.repairChkClass) {
1058
- view.repairChkClass(setting, oldParentNode);
1059
- view.repairParentChkClassWithSelf(setting, oldParentNode);
1060
- if (oldParentNode != node.parent)
1061
- view.repairParentChkClassWithSelf(setting, node);
1062
- }
1063
-
1064
- //expand parents after move
1065
- if (!isSilent) {
1066
- view.expandCollapseParentNode(setting, node.getParentNode(), true, animateFlag);
1067
- }
1068
- },
1069
- removeEditBtn: function(node) {
1070
- $("#" + node.tId + consts.id.EDIT).unbind().remove();
1071
- },
1072
- removeRemoveBtn: function(node) {
1073
- $("#" + node.tId + consts.id.REMOVE).unbind().remove();
1074
- },
1075
- removeTreeDom: function(setting, node) {
1076
- node.isHover = false;
1077
- view.removeEditBtn(node);
1078
- view.removeRemoveBtn(node);
1079
- tools.apply(setting.view.removeHoverDom, [setting.treeId, node]);
1080
- },
1081
- repairNodeLevelClass: function(setting, node, oldLevel) {
1082
- if (oldLevel === node.level) return;
1083
- var liObj = $("#" + node.tId),
1084
- aObj = $("#" + node.tId + consts.id.A),
1085
- ulObj = $("#" + node.tId + consts.id.UL),
1086
- oldClass = "level" + oldLevel,
1087
- newClass = "level" + node.level;
1088
- liObj.removeClass(oldClass);
1089
- liObj.addClass(newClass);
1090
- aObj.removeClass(oldClass);
1091
- aObj.addClass(newClass);
1092
- ulObj.removeClass(oldClass);
1093
- ulObj.addClass(newClass);
1094
- }
1095
- },
1096
-
1097
- _z = {
1098
- tools: _tools,
1099
- view: _view,
1100
- event: _event,
1101
- data: _data
1102
- };
1103
- $.extend(true, $.fn.zTree.consts, _consts);
1104
- $.extend(true, $.fn.zTree._z, _z);
1105
-
1106
- var zt = $.fn.zTree,
1107
- tools = zt._z.tools,
1108
- consts = zt.consts,
1109
- view = zt._z.view,
1110
- data = zt._z.data,
1111
- event = zt._z.event;
1112
-
1113
- data.exSetting(_setting);
1114
- data.addInitBind(_bindEvent);
1115
- data.addInitUnBind(_unbindEvent);
1116
- data.addInitCache(_initCache);
1117
- data.addInitNode(_initNode);
1118
- data.addInitProxy(_eventProxy);
1119
- data.addInitRoot(_initRoot);
1120
- data.addZTreeTools(_zTreeTools);
1121
-
1122
- var _cancelPreSelectedNode = view.cancelPreSelectedNode;
1123
- view.cancelPreSelectedNode = function (setting, node) {
1124
- var list = data.getRoot(setting).curSelectedList;
1125
- for (var i=0, j=list.length; i<j; i++) {
1126
- if (!node || node === list[i]) {
1127
- view.removeTreeDom(setting, list[i]);
1128
- if (node) break;
1129
- }
1130
- }
1131
- if (_cancelPreSelectedNode) _cancelPreSelectedNode.apply(view, arguments);
1132
- }
1133
-
1134
- var _createNodes = view.createNodes;
1135
- view.createNodes = function(setting, level, nodes, parentNode) {
1136
- if (_createNodes) {
1137
- _createNodes.apply(view, arguments);
1138
- }
1139
- if (!nodes) return;
1140
- if (view.repairParentChkClassWithSelf) {
1141
- view.repairParentChkClassWithSelf(setting, parentNode);
1142
- }
1143
- }
1144
-
1145
- var _makeNodeUrl = view.makeNodeUrl;
1146
- view.makeNodeUrl = function(setting, node) {
1147
- return setting.edit.enable ? null : (_makeNodeUrl.apply(view, arguments));
1148
- }
1149
-
1150
- var _removeNode = view.removeNode;
1151
- view.removeNode = function(setting, node) {
1152
- var root = data.getRoot(setting);
1153
- if (root.curEditNode === node) root.curEditNode = null;
1154
- if (_removeNode) {
1155
- _removeNode.apply(view, arguments);
1156
- }
1157
- }
1158
-
1159
- var _selectNode = view.selectNode;
1160
- view.selectNode = function(setting, node, addFlag) {
1161
- var root = data.getRoot(setting);
1162
- if (data.isSelectedNode(setting, node) && root.curEditNode == node && node.editNameFlag) {
1163
- return false;
1164
- }
1165
- if (_selectNode) _selectNode.apply(view, arguments);
1166
- view.addHoverDom(setting, node);
1167
- return true;
1168
- }
1169
-
1170
- var _uCanDo = tools.uCanDo;
1171
- tools.uCanDo = function(setting, e) {
1172
- var root = data.getRoot(setting);
1173
- if (e && (tools.eqs(e.type, "mouseover") || tools.eqs(e.type, "mouseout") || tools.eqs(e.type, "mousedown") || tools.eqs(e.type, "mouseup"))) {
1174
- return true;
1175
- }
1176
- return (!root.curEditNode) && (_uCanDo ? _uCanDo.apply(view, arguments) : true);
1177
- }
1178
- })(jQuery);