tocmd 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/bin/tocmd +70 -0
  3. data/lib/mdpreview/markdown_render.rb +45 -0
  4. data/lib/mdpreview/translator.rb +237 -0
  5. data/lib/mdpreview/version.rb +3 -0
  6. data/lib/mdpreview.rb +18 -0
  7. data/test/mdptest.rb +100 -0
  8. data/vendor/cur.file +6 -0
  9. data/vendor/meta.js +1 -0
  10. data/vendor/template.html +0 -0
  11. data/vendor/toc/css/demo.css +33 -0
  12. data/vendor/toc/css/zTreeStyle/img/diy/1_close.png +0 -0
  13. data/vendor/toc/css/zTreeStyle/img/diy/1_open.png +0 -0
  14. data/vendor/toc/css/zTreeStyle/img/diy/2.png +0 -0
  15. data/vendor/toc/css/zTreeStyle/img/diy/3.png +0 -0
  16. data/vendor/toc/css/zTreeStyle/img/diy/4.png +0 -0
  17. data/vendor/toc/css/zTreeStyle/img/diy/5.png +0 -0
  18. data/vendor/toc/css/zTreeStyle/img/diy/6.png +0 -0
  19. data/vendor/toc/css/zTreeStyle/img/diy/7.png +0 -0
  20. data/vendor/toc/css/zTreeStyle/img/diy/8.png +0 -0
  21. data/vendor/toc/css/zTreeStyle/img/diy/9.png +0 -0
  22. data/vendor/toc/css/zTreeStyle/img/line_conn.gif +0 -0
  23. data/vendor/toc/css/zTreeStyle/img/loading.gif +0 -0
  24. data/vendor/toc/css/zTreeStyle/img/zTreeStandard.gif +0 -0
  25. data/vendor/toc/css/zTreeStyle/img/zTreeStandard.png +0 -0
  26. data/vendor/toc/css/zTreeStyle/zTreeStyle.css +97 -0
  27. data/vendor/toc/js/jquery-1.4.4.min.js +167 -0
  28. data/vendor/toc/js/jquery.ztree.all-3.5.js +3447 -0
  29. data/vendor/toc/js/jquery.ztree.all-3.5.min.js +157 -0
  30. data/vendor/toc/js/jquery.ztree.core-3.5.js +1644 -0
  31. data/vendor/toc/js/jquery.ztree.core-3.5.min.js +68 -0
  32. data/vendor/toc/js/jquery.ztree.excheck-3.5.js +624 -0
  33. data/vendor/toc/js/jquery.ztree.excheck-3.5.min.js +33 -0
  34. data/vendor/toc/js/jquery.ztree.exedit-3.5.js +1178 -0
  35. data/vendor/toc/js/jquery.ztree.exedit-3.5.min.js +52 -0
  36. data/vendor/toc/js/jquery.ztree.exhide-3.5.js +362 -0
  37. data/vendor/toc/js/jquery.ztree.exhide-3.5.min.js +22 -0
  38. data/vendor/toc/js/jquery.ztree_toc.js +224 -0
  39. data/vendor/toc/js/jquery.ztree_toc.min.js +4 -0
  40. data/vendor/toc/style/Clearness Dark.css +146 -0
  41. data/vendor/toc/style/Clearness.css +147 -0
  42. data/vendor/toc/style/GitHub.css +90 -0
  43. data/vendor/toc/style/GitHub2.css +297 -0
  44. data/vendor/toc/style/github-bf51422f4bb36427d391e4b75a1daa083c2d840e.css +1 -0
  45. data/vendor/toc/style/github2-d731afd4f624c99a4b19ad69f3083cd6d02b81d5.css +1 -0
  46. data/vendor/toc/style/makedownpad.css +285 -0
  47. metadata +90 -0
@@ -0,0 +1,1644 @@
1
+ /*
2
+ * JQuery zTree core 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
+ var settings = {}, roots = {}, caches = {},
15
+ //default consts of core
16
+ _consts = {
17
+ event: {
18
+ NODECREATED: "ztree_nodeCreated",
19
+ CLICK: "ztree_click",
20
+ EXPAND: "ztree_expand",
21
+ COLLAPSE: "ztree_collapse",
22
+ ASYNC_SUCCESS: "ztree_async_success",
23
+ ASYNC_ERROR: "ztree_async_error"
24
+ },
25
+ id: {
26
+ A: "_a",
27
+ ICON: "_ico",
28
+ SPAN: "_span",
29
+ SWITCH: "_switch",
30
+ UL: "_ul"
31
+ },
32
+ line: {
33
+ ROOT: "root",
34
+ ROOTS: "roots",
35
+ CENTER: "center",
36
+ BOTTOM: "bottom",
37
+ NOLINE: "noline",
38
+ LINE: "line"
39
+ },
40
+ folder: {
41
+ OPEN: "open",
42
+ CLOSE: "close",
43
+ DOCU: "docu"
44
+ },
45
+ node: {
46
+ CURSELECTED: "curSelectedNode"
47
+ }
48
+ },
49
+ //default setting of core
50
+ _setting = {
51
+ treeId: "",
52
+ treeObj: null,
53
+ view: {
54
+ addDiyDom: null,
55
+ autoCancelSelected: true,
56
+ dblClickExpand: true,
57
+ expandSpeed: "fast",
58
+ fontCss: {},
59
+ nameIsHTML: false,
60
+ selectedMulti: true,
61
+ showIcon: true,
62
+ showLine: true,
63
+ showTitle: true
64
+ },
65
+ data: {
66
+ key: {
67
+ children: "children",
68
+ name: "name",
69
+ title: "",
70
+ url: "url"
71
+ },
72
+ simpleData: {
73
+ enable: false,
74
+ idKey: "id",
75
+ pIdKey: "pId",
76
+ rootPId: null
77
+ },
78
+ keep: {
79
+ parent: false,
80
+ leaf: false
81
+ }
82
+ },
83
+ async: {
84
+ enable: false,
85
+ contentType: "application/x-www-form-urlencoded",
86
+ type: "post",
87
+ dataType: "text",
88
+ url: "",
89
+ autoParam: [],
90
+ otherParam: [],
91
+ dataFilter: null
92
+ },
93
+ callback: {
94
+ beforeAsync:null,
95
+ beforeClick:null,
96
+ beforeDblClick:null,
97
+ beforeRightClick:null,
98
+ beforeMouseDown:null,
99
+ beforeMouseUp:null,
100
+ beforeExpand:null,
101
+ beforeCollapse:null,
102
+ beforeRemove:null,
103
+
104
+ onAsyncError:null,
105
+ onAsyncSuccess:null,
106
+ onNodeCreated:null,
107
+ onClick:null,
108
+ onDblClick:null,
109
+ onRightClick:null,
110
+ onMouseDown:null,
111
+ onMouseUp:null,
112
+ onExpand:null,
113
+ onCollapse:null,
114
+ onRemove:null
115
+ }
116
+ },
117
+ //default root of core
118
+ //zTree use root to save full data
119
+ _initRoot = function (setting) {
120
+ var r = data.getRoot(setting);
121
+ if (!r) {
122
+ r = {};
123
+ data.setRoot(setting, r);
124
+ }
125
+ r[setting.data.key.children] = [];
126
+ r.expandTriggerFlag = false;
127
+ r.curSelectedList = [];
128
+ r.noSelection = true;
129
+ r.createdNodes = [];
130
+ r.zId = 0;
131
+ r._ver = (new Date()).getTime();
132
+ },
133
+ //default cache of core
134
+ _initCache = function(setting) {
135
+ var c = data.getCache(setting);
136
+ if (!c) {
137
+ c = {};
138
+ data.setCache(setting, c);
139
+ }
140
+ c.nodes = [];
141
+ c.doms = [];
142
+ },
143
+ //default bindEvent of core
144
+ _bindEvent = function(setting) {
145
+ var o = setting.treeObj,
146
+ c = consts.event;
147
+ o.bind(c.NODECREATED, function (event, treeId, node) {
148
+ tools.apply(setting.callback.onNodeCreated, [event, treeId, node]);
149
+ });
150
+
151
+ o.bind(c.CLICK, function (event, srcEvent, treeId, node, clickFlag) {
152
+ tools.apply(setting.callback.onClick, [srcEvent, treeId, node, clickFlag]);
153
+ });
154
+
155
+ o.bind(c.EXPAND, function (event, treeId, node) {
156
+ tools.apply(setting.callback.onExpand, [event, treeId, node]);
157
+ });
158
+
159
+ o.bind(c.COLLAPSE, function (event, treeId, node) {
160
+ tools.apply(setting.callback.onCollapse, [event, treeId, node]);
161
+ });
162
+
163
+ o.bind(c.ASYNC_SUCCESS, function (event, treeId, node, msg) {
164
+ tools.apply(setting.callback.onAsyncSuccess, [event, treeId, node, msg]);
165
+ });
166
+
167
+ o.bind(c.ASYNC_ERROR, function (event, treeId, node, XMLHttpRequest, textStatus, errorThrown) {
168
+ tools.apply(setting.callback.onAsyncError, [event, treeId, node, XMLHttpRequest, textStatus, errorThrown]);
169
+ });
170
+ },
171
+ _unbindEvent = function(setting) {
172
+ var o = setting.treeObj,
173
+ c = consts.event;
174
+ o.unbind(c.NODECREATED)
175
+ .unbind(c.CLICK)
176
+ .unbind(c.EXPAND)
177
+ .unbind(c.COLLAPSE)
178
+ .unbind(c.ASYNC_SUCCESS)
179
+ .unbind(c.ASYNC_ERROR);
180
+ },
181
+ //default event proxy of core
182
+ _eventProxy = function(event) {
183
+ var target = event.target,
184
+ setting = data.getSetting(event.data.treeId),
185
+ tId = "", node = null,
186
+ nodeEventType = "", treeEventType = "",
187
+ nodeEventCallback = null, treeEventCallback = null,
188
+ tmp = null;
189
+
190
+ if (tools.eqs(event.type, "mousedown")) {
191
+ treeEventType = "mousedown";
192
+ } else if (tools.eqs(event.type, "mouseup")) {
193
+ treeEventType = "mouseup";
194
+ } else if (tools.eqs(event.type, "contextmenu")) {
195
+ treeEventType = "contextmenu";
196
+ } else if (tools.eqs(event.type, "click")) {
197
+ if (tools.eqs(target.tagName, "span") && target.getAttribute("treeNode"+ consts.id.SWITCH) !== null) {
198
+ tId = ($(target).parent("li").get(0) || $(target).parentsUntil("li").parent().get(0)).id;
199
+ nodeEventType = "switchNode";
200
+ } else {
201
+ tmp = tools.getMDom(setting, target, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
202
+ if (tmp) {
203
+ tId = ($(tmp).parent("li").get(0) || $(tmp).parentsUntil("li").parent().get(0)).id;
204
+ nodeEventType = "clickNode";
205
+ }
206
+ }
207
+ } else if (tools.eqs(event.type, "dblclick")) {
208
+ treeEventType = "dblclick";
209
+ tmp = tools.getMDom(setting, target, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
210
+ if (tmp) {
211
+ tId = ($(tmp).parent("li").get(0) || $(tmp).parentsUntil("li").parent().get(0)).id;
212
+ nodeEventType = "switchNode";
213
+ }
214
+ }
215
+ if (treeEventType.length > 0 && tId.length == 0) {
216
+ tmp = tools.getMDom(setting, target, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
217
+ if (tmp) {tId = ($(tmp).parent("li").get(0) || $(tmp).parentsUntil("li").parent().get(0)).id;}
218
+ }
219
+ // event to node
220
+ if (tId.length>0) {
221
+ node = data.getNodeCache(setting, tId);
222
+ switch (nodeEventType) {
223
+ case "switchNode" :
224
+ if (!node.isParent) {
225
+ nodeEventType = "";
226
+ } else if (tools.eqs(event.type, "click")
227
+ || (tools.eqs(event.type, "dblclick") && tools.apply(setting.view.dblClickExpand, [setting.treeId, node], setting.view.dblClickExpand))) {
228
+ nodeEventCallback = handler.onSwitchNode;
229
+ } else {
230
+ nodeEventType = "";
231
+ }
232
+ break;
233
+ case "clickNode" :
234
+ nodeEventCallback = handler.onClickNode;
235
+ break;
236
+ }
237
+ }
238
+ // event to zTree
239
+ switch (treeEventType) {
240
+ case "mousedown" :
241
+ treeEventCallback = handler.onZTreeMousedown;
242
+ break;
243
+ case "mouseup" :
244
+ treeEventCallback = handler.onZTreeMouseup;
245
+ break;
246
+ case "dblclick" :
247
+ treeEventCallback = handler.onZTreeDblclick;
248
+ break;
249
+ case "contextmenu" :
250
+ treeEventCallback = handler.onZTreeContextmenu;
251
+ break;
252
+ }
253
+ var proxyResult = {
254
+ stop: false,
255
+ node: node,
256
+ nodeEventType: nodeEventType,
257
+ nodeEventCallback: nodeEventCallback,
258
+ treeEventType: treeEventType,
259
+ treeEventCallback: treeEventCallback
260
+ };
261
+ return proxyResult
262
+ },
263
+ //default init node of core
264
+ _initNode = function(setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
265
+ if (!n) return;
266
+ var r = data.getRoot(setting),
267
+ childKey = setting.data.key.children;
268
+ n.level = level;
269
+ n.tId = setting.treeId + "_" + (++r.zId);
270
+ n.parentTId = parentNode ? parentNode.tId : null;
271
+ if (n[childKey] && n[childKey].length > 0) {
272
+ if (typeof n.open == "string") n.open = tools.eqs(n.open, "true");
273
+ n.open = !!n.open;
274
+ n.isParent = true;
275
+ n.zAsync = true;
276
+ } else {
277
+ n.open = false;
278
+ if (typeof n.isParent == "string") n.isParent = tools.eqs(n.isParent, "true");
279
+ n.isParent = !!n.isParent;
280
+ n.zAsync = !n.isParent;
281
+ }
282
+ n.isFirstNode = isFirstNode;
283
+ n.isLastNode = isLastNode;
284
+ n.getParentNode = function() {return data.getNodeCache(setting, n.parentTId);};
285
+ n.getPreNode = function() {return data.getPreNode(setting, n);};
286
+ n.getNextNode = function() {return data.getNextNode(setting, n);};
287
+ n.isAjaxing = false;
288
+ data.fixPIdKeyValue(setting, n);
289
+ },
290
+ _init = {
291
+ bind: [_bindEvent],
292
+ unbind: [_unbindEvent],
293
+ caches: [_initCache],
294
+ nodes: [_initNode],
295
+ proxys: [_eventProxy],
296
+ roots: [_initRoot],
297
+ beforeA: [],
298
+ afterA: [],
299
+ innerBeforeA: [],
300
+ innerAfterA: [],
301
+ zTreeTools: []
302
+ },
303
+ //method of operate data
304
+ data = {
305
+ addNodeCache: function(setting, node) {
306
+ data.getCache(setting).nodes[data.getNodeCacheId(node.tId)] = node;
307
+ },
308
+ getNodeCacheId: function(tId) {
309
+ return tId.substring(tId.lastIndexOf("_")+1);
310
+ },
311
+ addAfterA: function(afterA) {
312
+ _init.afterA.push(afterA);
313
+ },
314
+ addBeforeA: function(beforeA) {
315
+ _init.beforeA.push(beforeA);
316
+ },
317
+ addInnerAfterA: function(innerAfterA) {
318
+ _init.innerAfterA.push(innerAfterA);
319
+ },
320
+ addInnerBeforeA: function(innerBeforeA) {
321
+ _init.innerBeforeA.push(innerBeforeA);
322
+ },
323
+ addInitBind: function(bindEvent) {
324
+ _init.bind.push(bindEvent);
325
+ },
326
+ addInitUnBind: function(unbindEvent) {
327
+ _init.unbind.push(unbindEvent);
328
+ },
329
+ addInitCache: function(initCache) {
330
+ _init.caches.push(initCache);
331
+ },
332
+ addInitNode: function(initNode) {
333
+ _init.nodes.push(initNode);
334
+ },
335
+ addInitProxy: function(initProxy) {
336
+ _init.proxys.push(initProxy);
337
+ },
338
+ addInitRoot: function(initRoot) {
339
+ _init.roots.push(initRoot);
340
+ },
341
+ addNodesData: function(setting, parentNode, nodes) {
342
+ var childKey = setting.data.key.children;
343
+ if (!parentNode[childKey]) parentNode[childKey] = [];
344
+ if (parentNode[childKey].length > 0) {
345
+ parentNode[childKey][parentNode[childKey].length - 1].isLastNode = false;
346
+ view.setNodeLineIcos(setting, parentNode[childKey][parentNode[childKey].length - 1]);
347
+ }
348
+ parentNode.isParent = true;
349
+ parentNode[childKey] = parentNode[childKey].concat(nodes);
350
+ },
351
+ addSelectedNode: function(setting, node) {
352
+ var root = data.getRoot(setting);
353
+ if (!data.isSelectedNode(setting, node)) {
354
+ root.curSelectedList.push(node);
355
+ }
356
+ },
357
+ addCreatedNode: function(setting, node) {
358
+ if (!!setting.callback.onNodeCreated || !!setting.view.addDiyDom) {
359
+ var root = data.getRoot(setting);
360
+ root.createdNodes.push(node);
361
+ }
362
+ },
363
+ addZTreeTools: function(zTreeTools) {
364
+ _init.zTreeTools.push(zTreeTools);
365
+ },
366
+ exSetting: function(s) {
367
+ $.extend(true, _setting, s);
368
+ },
369
+ fixPIdKeyValue: function(setting, node) {
370
+ if (setting.data.simpleData.enable) {
371
+ node[setting.data.simpleData.pIdKey] = node.parentTId ? node.getParentNode()[setting.data.simpleData.idKey] : setting.data.simpleData.rootPId;
372
+ }
373
+ },
374
+ getAfterA: function(setting, node, array) {
375
+ for (var i=0, j=_init.afterA.length; i<j; i++) {
376
+ _init.afterA[i].apply(this, arguments);
377
+ }
378
+ },
379
+ getBeforeA: function(setting, node, array) {
380
+ for (var i=0, j=_init.beforeA.length; i<j; i++) {
381
+ _init.beforeA[i].apply(this, arguments);
382
+ }
383
+ },
384
+ getInnerAfterA: function(setting, node, array) {
385
+ for (var i=0, j=_init.innerAfterA.length; i<j; i++) {
386
+ _init.innerAfterA[i].apply(this, arguments);
387
+ }
388
+ },
389
+ getInnerBeforeA: function(setting, node, array) {
390
+ for (var i=0, j=_init.innerBeforeA.length; i<j; i++) {
391
+ _init.innerBeforeA[i].apply(this, arguments);
392
+ }
393
+ },
394
+ getCache: function(setting) {
395
+ return caches[setting.treeId];
396
+ },
397
+ getNextNode: function(setting, node) {
398
+ if (!node) return null;
399
+ var childKey = setting.data.key.children,
400
+ p = node.parentTId ? node.getParentNode() : data.getRoot(setting);
401
+ for (var i=0, l=p[childKey].length-1; i<=l; i++) {
402
+ if (p[childKey][i] === node) {
403
+ return (i==l ? null : p[childKey][i+1]);
404
+ }
405
+ }
406
+ return null;
407
+ },
408
+ getNodeByParam: function(setting, nodes, key, value) {
409
+ if (!nodes || !key) return null;
410
+ var childKey = setting.data.key.children;
411
+ for (var i = 0, l = nodes.length; i < l; i++) {
412
+ if (nodes[i][key] == value) {
413
+ return nodes[i];
414
+ }
415
+ var tmp = data.getNodeByParam(setting, nodes[i][childKey], key, value);
416
+ if (tmp) return tmp;
417
+ }
418
+ return null;
419
+ },
420
+ getNodeCache: function(setting, tId) {
421
+ if (!tId) return null;
422
+ var n = caches[setting.treeId].nodes[data.getNodeCacheId(tId)];
423
+ return n ? n : null;
424
+ },
425
+ getNodeName: function(setting, node) {
426
+ var nameKey = setting.data.key.name;
427
+ return "" + node[nameKey];
428
+ },
429
+ getNodeTitle: function(setting, node) {
430
+ var t = setting.data.key.title === "" ? setting.data.key.name : setting.data.key.title;
431
+ return "" + node[t];
432
+ },
433
+ getNodes: function(setting) {
434
+ return data.getRoot(setting)[setting.data.key.children];
435
+ },
436
+ getNodesByParam: function(setting, nodes, key, value) {
437
+ if (!nodes || !key) return [];
438
+ var childKey = setting.data.key.children,
439
+ result = [];
440
+ for (var i = 0, l = nodes.length; i < l; i++) {
441
+ if (nodes[i][key] == value) {
442
+ result.push(nodes[i]);
443
+ }
444
+ result = result.concat(data.getNodesByParam(setting, nodes[i][childKey], key, value));
445
+ }
446
+ return result;
447
+ },
448
+ getNodesByParamFuzzy: function(setting, nodes, key, value) {
449
+ if (!nodes || !key) return [];
450
+ var childKey = setting.data.key.children,
451
+ result = [];
452
+ for (var i = 0, l = nodes.length; i < l; i++) {
453
+ if (typeof nodes[i][key] == "string" && nodes[i][key].indexOf(value)>-1) {
454
+ result.push(nodes[i]);
455
+ }
456
+ result = result.concat(data.getNodesByParamFuzzy(setting, nodes[i][childKey], key, value));
457
+ }
458
+ return result;
459
+ },
460
+ getNodesByFilter: function(setting, nodes, filter, isSingle, invokeParam) {
461
+ if (!nodes) return (isSingle ? null : []);
462
+ var childKey = setting.data.key.children,
463
+ result = isSingle ? null : [];
464
+ for (var i = 0, l = nodes.length; i < l; i++) {
465
+ if (tools.apply(filter, [nodes[i], invokeParam], false)) {
466
+ if (isSingle) {return nodes[i];}
467
+ result.push(nodes[i]);
468
+ }
469
+ var tmpResult = data.getNodesByFilter(setting, nodes[i][childKey], filter, isSingle, invokeParam);
470
+ if (isSingle && !!tmpResult) {return tmpResult;}
471
+ result = isSingle ? tmpResult : result.concat(tmpResult);
472
+ }
473
+ return result;
474
+ },
475
+ getPreNode: function(setting, node) {
476
+ if (!node) return null;
477
+ var childKey = setting.data.key.children,
478
+ p = node.parentTId ? node.getParentNode() : data.getRoot(setting);
479
+ for (var i=0, l=p[childKey].length; i<l; i++) {
480
+ if (p[childKey][i] === node) {
481
+ return (i==0 ? null : p[childKey][i-1]);
482
+ }
483
+ }
484
+ return null;
485
+ },
486
+ getRoot: function(setting) {
487
+ return setting ? roots[setting.treeId] : null;
488
+ },
489
+ getSetting: function(treeId) {
490
+ return settings[treeId];
491
+ },
492
+ getSettings: function() {
493
+ return settings;
494
+ },
495
+ getZTreeTools: function(treeId) {
496
+ var r = this.getRoot(this.getSetting(treeId));
497
+ return r ? r.treeTools : null;
498
+ },
499
+ initCache: function(setting) {
500
+ for (var i=0, j=_init.caches.length; i<j; i++) {
501
+ _init.caches[i].apply(this, arguments);
502
+ }
503
+ },
504
+ initNode: function(setting, level, node, parentNode, preNode, nextNode) {
505
+ for (var i=0, j=_init.nodes.length; i<j; i++) {
506
+ _init.nodes[i].apply(this, arguments);
507
+ }
508
+ },
509
+ initRoot: function(setting) {
510
+ for (var i=0, j=_init.roots.length; i<j; i++) {
511
+ _init.roots[i].apply(this, arguments);
512
+ }
513
+ },
514
+ isSelectedNode: function(setting, node) {
515
+ var root = data.getRoot(setting);
516
+ for (var i=0, j=root.curSelectedList.length; i<j; i++) {
517
+ if(node === root.curSelectedList[i]) return true;
518
+ }
519
+ return false;
520
+ },
521
+ removeNodeCache: function(setting, node) {
522
+ var childKey = setting.data.key.children;
523
+ if (node[childKey]) {
524
+ for (var i=0, l=node[childKey].length; i<l; i++) {
525
+ arguments.callee(setting, node[childKey][i]);
526
+ }
527
+ }
528
+ data.getCache(setting).nodes[data.getNodeCacheId(node.tId)] = null;
529
+ },
530
+ removeSelectedNode: function(setting, node) {
531
+ var root = data.getRoot(setting);
532
+ for (var i=0, j=root.curSelectedList.length; i<j; i++) {
533
+ if(node === root.curSelectedList[i] || !data.getNodeCache(setting, root.curSelectedList[i].tId)) {
534
+ root.curSelectedList.splice(i, 1);
535
+ i--;j--;
536
+ }
537
+ }
538
+ },
539
+ setCache: function(setting, cache) {
540
+ caches[setting.treeId] = cache;
541
+ },
542
+ setRoot: function(setting, root) {
543
+ roots[setting.treeId] = root;
544
+ },
545
+ setZTreeTools: function(setting, zTreeTools) {
546
+ for (var i=0, j=_init.zTreeTools.length; i<j; i++) {
547
+ _init.zTreeTools[i].apply(this, arguments);
548
+ }
549
+ },
550
+ transformToArrayFormat: function (setting, nodes) {
551
+ if (!nodes) return [];
552
+ var childKey = setting.data.key.children,
553
+ r = [];
554
+ if (tools.isArray(nodes)) {
555
+ for (var i=0, l=nodes.length; i<l; i++) {
556
+ r.push(nodes[i]);
557
+ if (nodes[i][childKey])
558
+ r = r.concat(data.transformToArrayFormat(setting, nodes[i][childKey]));
559
+ }
560
+ } else {
561
+ r.push(nodes);
562
+ if (nodes[childKey])
563
+ r = r.concat(data.transformToArrayFormat(setting, nodes[childKey]));
564
+ }
565
+ return r;
566
+ },
567
+ transformTozTreeFormat: function(setting, sNodes) {
568
+ var i,l,
569
+ key = setting.data.simpleData.idKey,
570
+ parentKey = setting.data.simpleData.pIdKey,
571
+ childKey = setting.data.key.children;
572
+ if (!key || key=="" || !sNodes) return [];
573
+
574
+ if (tools.isArray(sNodes)) {
575
+ var r = [];
576
+ var tmpMap = [];
577
+ for (i=0, l=sNodes.length; i<l; i++) {
578
+ tmpMap[sNodes[i][key]] = sNodes[i];
579
+ }
580
+ for (i=0, l=sNodes.length; i<l; i++) {
581
+ if (tmpMap[sNodes[i][parentKey]] && sNodes[i][key] != sNodes[i][parentKey]) {
582
+ if (!tmpMap[sNodes[i][parentKey]][childKey])
583
+ tmpMap[sNodes[i][parentKey]][childKey] = [];
584
+ tmpMap[sNodes[i][parentKey]][childKey].push(sNodes[i]);
585
+ } else {
586
+ r.push(sNodes[i]);
587
+ }
588
+ }
589
+ return r;
590
+ }else {
591
+ return [sNodes];
592
+ }
593
+ }
594
+ },
595
+ //method of event proxy
596
+ event = {
597
+ bindEvent: function(setting) {
598
+ for (var i=0, j=_init.bind.length; i<j; i++) {
599
+ _init.bind[i].apply(this, arguments);
600
+ }
601
+ },
602
+ unbindEvent: function(setting) {
603
+ for (var i=0, j=_init.unbind.length; i<j; i++) {
604
+ _init.unbind[i].apply(this, arguments);
605
+ }
606
+ },
607
+ bindTree: function(setting) {
608
+ var eventParam = {
609
+ treeId: setting.treeId
610
+ },
611
+ o = setting.treeObj;
612
+ // for can't select text
613
+ o.bind('selectstart', function(e){
614
+ var n = e.srcElement.nodeName.toLowerCase();
615
+ return (n === "input" || n === "textarea" );
616
+ }
617
+ ).css({
618
+ "-moz-user-select":"-moz-none"
619
+ });
620
+ o.bind('click', eventParam, event.proxy);
621
+ o.bind('dblclick', eventParam, event.proxy);
622
+ o.bind('mouseover', eventParam, event.proxy);
623
+ o.bind('mouseout', eventParam, event.proxy);
624
+ o.bind('mousedown', eventParam, event.proxy);
625
+ o.bind('mouseup', eventParam, event.proxy);
626
+ o.bind('contextmenu', eventParam, event.proxy);
627
+ },
628
+ unbindTree: function(setting) {
629
+ var o = setting.treeObj;
630
+ o.unbind('click', event.proxy)
631
+ .unbind('dblclick', event.proxy)
632
+ .unbind('mouseover', event.proxy)
633
+ .unbind('mouseout', event.proxy)
634
+ .unbind('mousedown', event.proxy)
635
+ .unbind('mouseup', event.proxy)
636
+ .unbind('contextmenu', event.proxy);
637
+ },
638
+ doProxy: function(e) {
639
+ var results = [];
640
+ for (var i=0, j=_init.proxys.length; i<j; i++) {
641
+ var proxyResult = _init.proxys[i].apply(this, arguments);
642
+ results.push(proxyResult);
643
+ if (proxyResult.stop) {
644
+ break;
645
+ }
646
+ }
647
+ return results;
648
+ },
649
+ proxy: function(e) {
650
+ var setting = data.getSetting(e.data.treeId);
651
+ if (!tools.uCanDo(setting, e)) return true;
652
+ var results = event.doProxy(e),
653
+ r = true, x = false;
654
+ for (var i=0, l=results.length; i<l; i++) {
655
+ var proxyResult = results[i];
656
+ if (proxyResult.nodeEventCallback) {
657
+ x = true;
658
+ r = proxyResult.nodeEventCallback.apply(proxyResult, [e, proxyResult.node]) && r;
659
+ }
660
+ if (proxyResult.treeEventCallback) {
661
+ x = true;
662
+ r = proxyResult.treeEventCallback.apply(proxyResult, [e, proxyResult.node]) && r;
663
+ }
664
+ }
665
+ return r;
666
+ }
667
+ },
668
+ //method of event handler
669
+ handler = {
670
+ onSwitchNode: function (event, node) {
671
+ var setting = data.getSetting(event.data.treeId);
672
+ if (node.open) {
673
+ if (tools.apply(setting.callback.beforeCollapse, [setting.treeId, node], true) == false) return true;
674
+ data.getRoot(setting).expandTriggerFlag = true;
675
+ view.switchNode(setting, node);
676
+ } else {
677
+ if (tools.apply(setting.callback.beforeExpand, [setting.treeId, node], true) == false) return true;
678
+ data.getRoot(setting).expandTriggerFlag = true;
679
+ view.switchNode(setting, node);
680
+ }
681
+ return true;
682
+ },
683
+ onClickNode: function (event, node) {
684
+ var setting = data.getSetting(event.data.treeId),
685
+ clickFlag = ( (setting.view.autoCancelSelected && event.ctrlKey) && data.isSelectedNode(setting, node)) ? 0 : (setting.view.autoCancelSelected && event.ctrlKey && setting.view.selectedMulti) ? 2 : 1;
686
+ if (tools.apply(setting.callback.beforeClick, [setting.treeId, node, clickFlag], true) == false) return true;
687
+ if (clickFlag === 0) {
688
+ view.cancelPreSelectedNode(setting, node);
689
+ } else {
690
+ view.selectNode(setting, node, clickFlag === 2);
691
+ }
692
+ setting.treeObj.trigger(consts.event.CLICK, [event, setting.treeId, node, clickFlag]);
693
+ return true;
694
+ },
695
+ onZTreeMousedown: function(event, node) {
696
+ var setting = data.getSetting(event.data.treeId);
697
+ if (tools.apply(setting.callback.beforeMouseDown, [setting.treeId, node], true)) {
698
+ tools.apply(setting.callback.onMouseDown, [event, setting.treeId, node]);
699
+ }
700
+ return true;
701
+ },
702
+ onZTreeMouseup: function(event, node) {
703
+ var setting = data.getSetting(event.data.treeId);
704
+ if (tools.apply(setting.callback.beforeMouseUp, [setting.treeId, node], true)) {
705
+ tools.apply(setting.callback.onMouseUp, [event, setting.treeId, node]);
706
+ }
707
+ return true;
708
+ },
709
+ onZTreeDblclick: function(event, node) {
710
+ var setting = data.getSetting(event.data.treeId);
711
+ if (tools.apply(setting.callback.beforeDblClick, [setting.treeId, node], true)) {
712
+ tools.apply(setting.callback.onDblClick, [event, setting.treeId, node]);
713
+ }
714
+ return true;
715
+ },
716
+ onZTreeContextmenu: function(event, node) {
717
+ var setting = data.getSetting(event.data.treeId);
718
+ if (tools.apply(setting.callback.beforeRightClick, [setting.treeId, node], true)) {
719
+ tools.apply(setting.callback.onRightClick, [event, setting.treeId, node]);
720
+ }
721
+ return (typeof setting.callback.onRightClick) != "function";
722
+ }
723
+ },
724
+ //method of tools for zTree
725
+ tools = {
726
+ apply: function(fun, param, defaultValue) {
727
+ if ((typeof fun) == "function") {
728
+ return fun.apply(zt, param?param:[]);
729
+ }
730
+ return defaultValue;
731
+ },
732
+ canAsync: function(setting, node) {
733
+ var childKey = setting.data.key.children;
734
+ return (setting.async.enable && node && node.isParent && !(node.zAsync || (node[childKey] && node[childKey].length > 0)));
735
+ },
736
+ clone: function (obj){
737
+ if (obj === null) return null;
738
+ var o = obj.constructor === Array ? [] : {};
739
+ for(var i in obj){
740
+ o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? arguments.callee(obj[i]) : obj[i]);
741
+ }
742
+ return o;
743
+ },
744
+ eqs: function(str1, str2) {
745
+ return str1.toLowerCase() === str2.toLowerCase();
746
+ },
747
+ isArray: function(arr) {
748
+ return Object.prototype.toString.apply(arr) === "[object Array]";
749
+ },
750
+ getMDom: function (setting, curDom, targetExpr) {
751
+ if (!curDom) return null;
752
+ while (curDom && curDom.id !== setting.treeId) {
753
+ for (var i=0, l=targetExpr.length; curDom.tagName && i<l; i++) {
754
+ if (tools.eqs(curDom.tagName, targetExpr[i].tagName) && curDom.getAttribute(targetExpr[i].attrName) !== null) {
755
+ return curDom;
756
+ }
757
+ }
758
+ curDom = curDom.parentNode;
759
+ }
760
+ return null;
761
+ },
762
+ uCanDo: function(setting, e) {
763
+ return true;
764
+ }
765
+ },
766
+ //method of operate ztree dom
767
+ view = {
768
+ addNodes: function(setting, parentNode, newNodes, isSilent) {
769
+ if (setting.data.keep.leaf && parentNode && !parentNode.isParent) {
770
+ return;
771
+ }
772
+ if (!tools.isArray(newNodes)) {
773
+ newNodes = [newNodes];
774
+ }
775
+ if (setting.data.simpleData.enable) {
776
+ newNodes = data.transformTozTreeFormat(setting, newNodes);
777
+ }
778
+ if (parentNode) {
779
+ var target_switchObj = $("#" + parentNode.tId + consts.id.SWITCH),
780
+ target_icoObj = $("#" + parentNode.tId + consts.id.ICON),
781
+ target_ulObj = $("#" + parentNode.tId + consts.id.UL);
782
+
783
+ if (!parentNode.open) {
784
+ view.replaceSwitchClass(parentNode, target_switchObj, consts.folder.CLOSE);
785
+ view.replaceIcoClass(parentNode, target_icoObj, consts.folder.CLOSE);
786
+ parentNode.open = false;
787
+ target_ulObj.css({
788
+ "display": "none"
789
+ });
790
+ }
791
+
792
+ data.addNodesData(setting, parentNode, newNodes);
793
+ view.createNodes(setting, parentNode.level + 1, newNodes, parentNode);
794
+ if (!isSilent) {
795
+ view.expandCollapseParentNode(setting, parentNode, true);
796
+ }
797
+ } else {
798
+ data.addNodesData(setting, data.getRoot(setting), newNodes);
799
+ view.createNodes(setting, 0, newNodes, null);
800
+ }
801
+ },
802
+ appendNodes: function(setting, level, nodes, parentNode, initFlag, openFlag) {
803
+ if (!nodes) return [];
804
+ var html = [],
805
+ childKey = setting.data.key.children;
806
+ for (var i = 0, l = nodes.length; i < l; i++) {
807
+ var node = nodes[i];
808
+ if (initFlag) {
809
+ var tmpPNode = (parentNode) ? parentNode: data.getRoot(setting),
810
+ tmpPChild = tmpPNode[childKey],
811
+ isFirstNode = ((tmpPChild.length == nodes.length) && (i == 0)),
812
+ isLastNode = (i == (nodes.length - 1));
813
+ data.initNode(setting, level, node, parentNode, isFirstNode, isLastNode, openFlag);
814
+ data.addNodeCache(setting, node);
815
+ }
816
+
817
+ var childHtml = [];
818
+ if (node[childKey] && node[childKey].length > 0) {
819
+ //make child html first, because checkType
820
+ childHtml = view.appendNodes(setting, level + 1, node[childKey], node, initFlag, openFlag && node.open);
821
+ }
822
+ if (openFlag) {
823
+
824
+ view.makeDOMNodeMainBefore(html, setting, node);
825
+ view.makeDOMNodeLine(html, setting, node);
826
+ data.getBeforeA(setting, node, html);
827
+ view.makeDOMNodeNameBefore(html, setting, node);
828
+ data.getInnerBeforeA(setting, node, html);
829
+ view.makeDOMNodeIcon(html, setting, node);
830
+ data.getInnerAfterA(setting, node, html);
831
+ view.makeDOMNodeNameAfter(html, setting, node);
832
+ data.getAfterA(setting, node, html);
833
+ if (node.isParent && node.open) {
834
+ view.makeUlHtml(setting, node, html, childHtml.join(''));
835
+ }
836
+ view.makeDOMNodeMainAfter(html, setting, node);
837
+ data.addCreatedNode(setting, node);
838
+ }
839
+ }
840
+ return html;
841
+ },
842
+ appendParentULDom: function(setting, node) {
843
+ var html = [],
844
+ nObj = $("#" + node.tId),
845
+ ulObj = $("#" + node.tId + consts.id.UL),
846
+ childKey = setting.data.key.children,
847
+ childHtml = view.appendNodes(setting, node.level+1, node[childKey], node, false, true);
848
+ view.makeUlHtml(setting, node, html, childHtml.join(''));
849
+ if (!nObj.get(0) && !!node.parentTId) {
850
+ view.appendParentULDom(setting, node.getParentNode());
851
+ nObj = $("#" + node.tId);
852
+ }
853
+ if (ulObj.get(0)) {
854
+ ulObj.remove();
855
+ }
856
+ nObj.append(html.join(''));
857
+ },
858
+ asyncNode: function(setting, node, isSilent, callback) {
859
+ var i, l;
860
+ if (node && !node.isParent) {
861
+ tools.apply(callback);
862
+ return false;
863
+ } else if (node && node.isAjaxing) {
864
+ return false;
865
+ } else if (tools.apply(setting.callback.beforeAsync, [setting.treeId, node], true) == false) {
866
+ tools.apply(callback);
867
+ return false;
868
+ }
869
+ if (node) {
870
+ node.isAjaxing = true;
871
+ var icoObj = $("#" + node.tId + consts.id.ICON);
872
+ icoObj.attr({"style":"", "class":"button ico_loading"});
873
+ }
874
+
875
+ var tmpParam = {};
876
+ for (i = 0, l = setting.async.autoParam.length; node && i < l; i++) {
877
+ var pKey = setting.async.autoParam[i].split("="), spKey = pKey;
878
+ if (pKey.length>1) {
879
+ spKey = pKey[1];
880
+ pKey = pKey[0];
881
+ }
882
+ tmpParam[spKey] = node[pKey];
883
+ }
884
+ if (tools.isArray(setting.async.otherParam)) {
885
+ for (i = 0, l = setting.async.otherParam.length; i < l; i += 2) {
886
+ tmpParam[setting.async.otherParam[i]] = setting.async.otherParam[i + 1];
887
+ }
888
+ } else {
889
+ for (var p in setting.async.otherParam) {
890
+ tmpParam[p] = setting.async.otherParam[p];
891
+ }
892
+ }
893
+
894
+ var _tmpV = data.getRoot(setting)._ver;
895
+ $.ajax({
896
+ contentType: setting.async.contentType,
897
+ type: setting.async.type,
898
+ url: tools.apply(setting.async.url, [setting.treeId, node], setting.async.url),
899
+ data: tmpParam,
900
+ dataType: setting.async.dataType,
901
+ success: function(msg) {
902
+ if (_tmpV != data.getRoot(setting)._ver) {
903
+ return;
904
+ }
905
+ var newNodes = [];
906
+ try {
907
+ if (!msg || msg.length == 0) {
908
+ newNodes = [];
909
+ } else if (typeof msg == "string") {
910
+ newNodes = eval("(" + msg + ")");
911
+ } else {
912
+ newNodes = msg;
913
+ }
914
+ } catch(err) {
915
+ newNodes = msg;
916
+ }
917
+
918
+ if (node) {
919
+ node.isAjaxing = null;
920
+ node.zAsync = true;
921
+ }
922
+ view.setNodeLineIcos(setting, node);
923
+ if (newNodes && newNodes !== "") {
924
+ newNodes = tools.apply(setting.async.dataFilter, [setting.treeId, node, newNodes], newNodes);
925
+ view.addNodes(setting, node, !!newNodes ? tools.clone(newNodes) : [], !!isSilent);
926
+ } else {
927
+ view.addNodes(setting, node, [], !!isSilent);
928
+ }
929
+ setting.treeObj.trigger(consts.event.ASYNC_SUCCESS, [setting.treeId, node, msg]);
930
+ tools.apply(callback);
931
+ },
932
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
933
+ if (_tmpV != data.getRoot(setting)._ver) {
934
+ return;
935
+ }
936
+ if (node) node.isAjaxing = null;
937
+ view.setNodeLineIcos(setting, node);
938
+ setting.treeObj.trigger(consts.event.ASYNC_ERROR, [setting.treeId, node, XMLHttpRequest, textStatus, errorThrown]);
939
+ }
940
+ });
941
+ return true;
942
+ },
943
+ cancelPreSelectedNode: function (setting, node) {
944
+ var list = data.getRoot(setting).curSelectedList;
945
+ for (var i=0, j=list.length-1; j>=i; j--) {
946
+ if (!node || node === list[j]) {
947
+ $("#" + list[j].tId + consts.id.A).removeClass(consts.node.CURSELECTED);
948
+ if (node) {
949
+ data.removeSelectedNode(setting, node);
950
+ break;
951
+ }
952
+ }
953
+ }
954
+ if (!node) data.getRoot(setting).curSelectedList = [];
955
+ },
956
+ createNodeCallback: function(setting) {
957
+ if (!!setting.callback.onNodeCreated || !!setting.view.addDiyDom) {
958
+ var root = data.getRoot(setting);
959
+ while (root.createdNodes.length>0) {
960
+ var node = root.createdNodes.shift();
961
+ tools.apply(setting.view.addDiyDom, [setting.treeId, node]);
962
+ if (!!setting.callback.onNodeCreated) {
963
+ setting.treeObj.trigger(consts.event.NODECREATED, [setting.treeId, node]);
964
+ }
965
+ }
966
+ }
967
+ },
968
+ createNodes: function(setting, level, nodes, parentNode) {
969
+ if (!nodes || nodes.length == 0) return;
970
+ var root = data.getRoot(setting),
971
+ childKey = setting.data.key.children,
972
+ openFlag = !parentNode || parentNode.open || !!$("#" + parentNode[childKey][0].tId).get(0);
973
+ root.createdNodes = [];
974
+ var zTreeHtml = view.appendNodes(setting, level, nodes, parentNode, true, openFlag);
975
+ if (!parentNode) {
976
+ setting.treeObj.append(zTreeHtml.join(''));
977
+ } else {
978
+ var ulObj = $("#" + parentNode.tId + consts.id.UL);
979
+ if (ulObj.get(0)) {
980
+ ulObj.append(zTreeHtml.join(''));
981
+ }
982
+ }
983
+ view.createNodeCallback(setting);
984
+ },
985
+ destroy: function(setting) {
986
+ if (!setting) return;
987
+ data.initCache(setting);
988
+ data.initRoot(setting);
989
+ event.unbindTree(setting);
990
+ event.unbindEvent(setting);
991
+ setting.treeObj.empty();
992
+ },
993
+ expandCollapseNode: function(setting, node, expandFlag, animateFlag, callback) {
994
+ var root = data.getRoot(setting),
995
+ childKey = setting.data.key.children;
996
+ if (!node) {
997
+ tools.apply(callback, []);
998
+ return;
999
+ }
1000
+ if (root.expandTriggerFlag) {
1001
+ var _callback = callback;
1002
+ callback = function(){
1003
+ if (_callback) _callback();
1004
+ if (node.open) {
1005
+ setting.treeObj.trigger(consts.event.EXPAND, [setting.treeId, node]);
1006
+ } else {
1007
+ setting.treeObj.trigger(consts.event.COLLAPSE, [setting.treeId, node]);
1008
+ }
1009
+ };
1010
+ root.expandTriggerFlag = false;
1011
+ }
1012
+ if (!node.open && node.isParent && ((!$("#" + node.tId + consts.id.UL).get(0)) || (node[childKey] && node[childKey].length>0 && !$("#" + node[childKey][0].tId).get(0)))) {
1013
+ view.appendParentULDom(setting, node);
1014
+ view.createNodeCallback(setting);
1015
+ }
1016
+ if (node.open == expandFlag) {
1017
+ tools.apply(callback, []);
1018
+ return;
1019
+ }
1020
+ var ulObj = $("#" + node.tId + consts.id.UL),
1021
+ switchObj = $("#" + node.tId + consts.id.SWITCH),
1022
+ icoObj = $("#" + node.tId + consts.id.ICON);
1023
+
1024
+ if (node.isParent) {
1025
+ node.open = !node.open;
1026
+ if (node.iconOpen && node.iconClose) {
1027
+ icoObj.attr("style", view.makeNodeIcoStyle(setting, node));
1028
+ }
1029
+
1030
+ if (node.open) {
1031
+ view.replaceSwitchClass(node, switchObj, consts.folder.OPEN);
1032
+ view.replaceIcoClass(node, icoObj, consts.folder.OPEN);
1033
+ if (animateFlag == false || setting.view.expandSpeed == "") {
1034
+ ulObj.show();
1035
+ tools.apply(callback, []);
1036
+ } else {
1037
+ if (node[childKey] && node[childKey].length > 0) {
1038
+ ulObj.slideDown(setting.view.expandSpeed, callback);
1039
+ } else {
1040
+ ulObj.show();
1041
+ tools.apply(callback, []);
1042
+ }
1043
+ }
1044
+ } else {
1045
+ view.replaceSwitchClass(node, switchObj, consts.folder.CLOSE);
1046
+ view.replaceIcoClass(node, icoObj, consts.folder.CLOSE);
1047
+ if (animateFlag == false || setting.view.expandSpeed == "" || !(node[childKey] && node[childKey].length > 0)) {
1048
+ ulObj.hide();
1049
+ tools.apply(callback, []);
1050
+ } else {
1051
+ ulObj.slideUp(setting.view.expandSpeed, callback);
1052
+ }
1053
+ }
1054
+ } else {
1055
+ tools.apply(callback, []);
1056
+ }
1057
+ },
1058
+ expandCollapseParentNode: function(setting, node, expandFlag, animateFlag, callback) {
1059
+ if (!node) return;
1060
+ if (!node.parentTId) {
1061
+ view.expandCollapseNode(setting, node, expandFlag, animateFlag, callback);
1062
+ return;
1063
+ } else {
1064
+ view.expandCollapseNode(setting, node, expandFlag, animateFlag);
1065
+ }
1066
+ if (node.parentTId) {
1067
+ view.expandCollapseParentNode(setting, node.getParentNode(), expandFlag, animateFlag, callback);
1068
+ }
1069
+ },
1070
+ expandCollapseSonNode: function(setting, node, expandFlag, animateFlag, callback) {
1071
+ var root = data.getRoot(setting),
1072
+ childKey = setting.data.key.children,
1073
+ treeNodes = (node) ? node[childKey]: root[childKey],
1074
+ selfAnimateSign = (node) ? false : animateFlag,
1075
+ expandTriggerFlag = data.getRoot(setting).expandTriggerFlag;
1076
+ data.getRoot(setting).expandTriggerFlag = false;
1077
+ if (treeNodes) {
1078
+ for (var i = 0, l = treeNodes.length; i < l; i++) {
1079
+ if (treeNodes[i]) view.expandCollapseSonNode(setting, treeNodes[i], expandFlag, selfAnimateSign);
1080
+ }
1081
+ }
1082
+ data.getRoot(setting).expandTriggerFlag = expandTriggerFlag;
1083
+ view.expandCollapseNode(setting, node, expandFlag, animateFlag, callback );
1084
+ },
1085
+ makeDOMNodeIcon: function(html, setting, node) {
1086
+ var nameStr = data.getNodeName(setting, node),
1087
+ name = setting.view.nameIsHTML ? nameStr : nameStr.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
1088
+ html.push("<span id='", node.tId, consts.id.ICON,
1089
+ "' title='' treeNode", consts.id.ICON," class='", view.makeNodeIcoClass(setting, node),
1090
+ "' style='", view.makeNodeIcoStyle(setting, node), "'></span><span id='", node.tId, consts.id.SPAN,
1091
+ "'>",name,"</span>");
1092
+ },
1093
+ makeDOMNodeLine: function(html, setting, node) {
1094
+ html.push("<span id='", node.tId, consts.id.SWITCH, "' title='' class='", view.makeNodeLineClass(setting, node), "' treeNode", consts.id.SWITCH,"></span>");
1095
+ },
1096
+ makeDOMNodeMainAfter: function(html, setting, node) {
1097
+ html.push("</li>");
1098
+ },
1099
+ makeDOMNodeMainBefore: function(html, setting, node) {
1100
+ html.push("<li id='", node.tId, "' class='level", node.level,"' tabindex='0' hidefocus='true' treenode>");
1101
+ },
1102
+ makeDOMNodeNameAfter: function(html, setting, node) {
1103
+ html.push("</a>");
1104
+ },
1105
+ makeDOMNodeNameBefore: function(html, setting, node) {
1106
+ var title = data.getNodeTitle(setting, node),
1107
+ url = view.makeNodeUrl(setting, node),
1108
+ fontcss = view.makeNodeFontCss(setting, node),
1109
+ fontStyle = [];
1110
+ for (var f in fontcss) {
1111
+ fontStyle.push(f, ":", fontcss[f], ";");
1112
+ }
1113
+ html.push("<a id='", node.tId, consts.id.A, "' class='level", node.level,"' treeNode", consts.id.A," onclick=\"", (node.click || ''),
1114
+ "\" ", ((url != null && url.length > 0) ? "href='" + url + "'" : ""), " target='",view.makeNodeTarget(node),"' style='", fontStyle.join(''),
1115
+ "'");
1116
+ if (tools.apply(setting.view.showTitle, [setting.treeId, node], setting.view.showTitle) && title) {html.push("title='", title.replace(/'/g,"&#39;").replace(/</g,'&lt;').replace(/>/g,'&gt;'),"'");}
1117
+ html.push(">");
1118
+ },
1119
+ makeNodeFontCss: function(setting, node) {
1120
+ var fontCss = tools.apply(setting.view.fontCss, [setting.treeId, node], setting.view.fontCss);
1121
+ return (fontCss && ((typeof fontCss) != "function")) ? fontCss : {};
1122
+ },
1123
+ makeNodeIcoClass: function(setting, node) {
1124
+ var icoCss = ["ico"];
1125
+ if (!node.isAjaxing) {
1126
+ icoCss[0] = (node.iconSkin ? node.iconSkin + "_" : "") + icoCss[0];
1127
+ if (node.isParent) {
1128
+ icoCss.push(node.open ? consts.folder.OPEN : consts.folder.CLOSE);
1129
+ } else {
1130
+ icoCss.push(consts.folder.DOCU);
1131
+ }
1132
+ }
1133
+ return "button " + icoCss.join('_');
1134
+ },
1135
+ makeNodeIcoStyle: function(setting, node) {
1136
+ var icoStyle = [];
1137
+ if (!node.isAjaxing) {
1138
+ var icon = (node.isParent && node.iconOpen && node.iconClose) ? (node.open ? node.iconOpen : node.iconClose) : node.icon;
1139
+ if (icon) icoStyle.push("background:url(", icon, ") 0 0 no-repeat;");
1140
+ if (setting.view.showIcon == false || !tools.apply(setting.view.showIcon, [setting.treeId, node], true)) {
1141
+ icoStyle.push("width:0px;height:0px;");
1142
+ }
1143
+ }
1144
+ return icoStyle.join('');
1145
+ },
1146
+ makeNodeLineClass: function(setting, node) {
1147
+ var lineClass = [];
1148
+ if (setting.view.showLine) {
1149
+ if (node.level == 0 && node.isFirstNode && node.isLastNode) {
1150
+ lineClass.push(consts.line.ROOT);
1151
+ } else if (node.level == 0 && node.isFirstNode) {
1152
+ lineClass.push(consts.line.ROOTS);
1153
+ } else if (node.isLastNode) {
1154
+ lineClass.push(consts.line.BOTTOM);
1155
+ } else {
1156
+ lineClass.push(consts.line.CENTER);
1157
+ }
1158
+ } else {
1159
+ lineClass.push(consts.line.NOLINE);
1160
+ }
1161
+ if (node.isParent) {
1162
+ lineClass.push(node.open ? consts.folder.OPEN : consts.folder.CLOSE);
1163
+ } else {
1164
+ lineClass.push(consts.folder.DOCU);
1165
+ }
1166
+ return view.makeNodeLineClassEx(node) + lineClass.join('_');
1167
+ },
1168
+ makeNodeLineClassEx: function(node) {
1169
+ return "button level" + node.level + " switch ";
1170
+ },
1171
+ makeNodeTarget: function(node) {
1172
+ return (node.target || "_blank");
1173
+ },
1174
+ makeNodeUrl: function(setting, node) {
1175
+ var urlKey = setting.data.key.url;
1176
+ return node[urlKey] ? node[urlKey] : null;
1177
+ },
1178
+ makeUlHtml: function(setting, node, html, content) {
1179
+ html.push("<ul id='", node.tId, consts.id.UL, "' class='level", node.level, " ", view.makeUlLineClass(setting, node), "' style='display:", (node.open ? "block": "none"),"'>");
1180
+ html.push(content);
1181
+ html.push("</ul>");
1182
+ },
1183
+ makeUlLineClass: function(setting, node) {
1184
+ return ((setting.view.showLine && !node.isLastNode) ? consts.line.LINE : "");
1185
+ },
1186
+ removeChildNodes: function(setting, node) {
1187
+ if (!node) return;
1188
+ var childKey = setting.data.key.children,
1189
+ nodes = node[childKey];
1190
+ if (!nodes) return;
1191
+
1192
+ for (var i = 0, l = nodes.length; i < l; i++) {
1193
+ data.removeNodeCache(setting, nodes[i]);
1194
+ }
1195
+ data.removeSelectedNode(setting);
1196
+ delete node[childKey];
1197
+
1198
+ if (!setting.data.keep.parent) {
1199
+ node.isParent = false;
1200
+ node.open = false;
1201
+ var tmp_switchObj = $("#" + node.tId + consts.id.SWITCH),
1202
+ tmp_icoObj = $("#" + node.tId + consts.id.ICON);
1203
+ view.replaceSwitchClass(node, tmp_switchObj, consts.folder.DOCU);
1204
+ view.replaceIcoClass(node, tmp_icoObj, consts.folder.DOCU);
1205
+ $("#" + node.tId + consts.id.UL).remove();
1206
+ } else {
1207
+ $("#" + node.tId + consts.id.UL).empty();
1208
+ }
1209
+ },
1210
+ setFirstNode: function(setting, parentNode) {
1211
+ var childKey = setting.data.key.children, childLength = parentNode[childKey].length;
1212
+ if ( childLength > 0) {
1213
+ parentNode[childKey][0].isFirstNode = true;
1214
+ }
1215
+ },
1216
+ setLastNode: function(setting, parentNode) {
1217
+ var childKey = setting.data.key.children, childLength = parentNode[childKey].length;
1218
+ if ( childLength > 0) {
1219
+ parentNode[childKey][childLength - 1].isLastNode = true;
1220
+ }
1221
+ },
1222
+ removeNode: function(setting, node) {
1223
+ var root = data.getRoot(setting),
1224
+ childKey = setting.data.key.children,
1225
+ parentNode = (node.parentTId) ? node.getParentNode() : root;
1226
+
1227
+ node.isFirstNode = false;
1228
+ node.isLastNode = false;
1229
+ node.getPreNode = function() {return null;};
1230
+ node.getNextNode = function() {return null;};
1231
+
1232
+ if (!data.getNodeCache(setting, node.tId)) {
1233
+ return;
1234
+ }
1235
+
1236
+ $("#" + node.tId).remove();
1237
+ data.removeNodeCache(setting, node);
1238
+ data.removeSelectedNode(setting, node);
1239
+
1240
+ for (var i = 0, l = parentNode[childKey].length; i < l; i++) {
1241
+ if (parentNode[childKey][i].tId == node.tId) {
1242
+ parentNode[childKey].splice(i, 1);
1243
+ break;
1244
+ }
1245
+ }
1246
+ view.setFirstNode(setting, parentNode);
1247
+ view.setLastNode(setting, parentNode);
1248
+
1249
+ var tmp_ulObj,tmp_switchObj,tmp_icoObj,
1250
+ childLength = parentNode[childKey].length;
1251
+
1252
+ //repair nodes old parent
1253
+ if (!setting.data.keep.parent && childLength == 0) {
1254
+ //old parentNode has no child nodes
1255
+ parentNode.isParent = false;
1256
+ parentNode.open = false;
1257
+ tmp_ulObj = $("#" + parentNode.tId + consts.id.UL);
1258
+ tmp_switchObj = $("#" + parentNode.tId + consts.id.SWITCH);
1259
+ tmp_icoObj = $("#" + parentNode.tId + consts.id.ICON);
1260
+ view.replaceSwitchClass(parentNode, tmp_switchObj, consts.folder.DOCU);
1261
+ view.replaceIcoClass(parentNode, tmp_icoObj, consts.folder.DOCU);
1262
+ tmp_ulObj.css("display", "none");
1263
+
1264
+ } else if (setting.view.showLine && childLength > 0) {
1265
+ //old parentNode has child nodes
1266
+ var newLast = parentNode[childKey][childLength - 1];
1267
+ tmp_ulObj = $("#" + newLast.tId + consts.id.UL);
1268
+ tmp_switchObj = $("#" + newLast.tId + consts.id.SWITCH);
1269
+ tmp_icoObj = $("#" + newLast.tId + consts.id.ICON);
1270
+ if (parentNode == root) {
1271
+ if (parentNode[childKey].length == 1) {
1272
+ //node was root, and ztree has only one root after move node
1273
+ view.replaceSwitchClass(newLast, tmp_switchObj, consts.line.ROOT);
1274
+ } else {
1275
+ var tmp_first_switchObj = $("#" + parentNode[childKey][0].tId + consts.id.SWITCH);
1276
+ view.replaceSwitchClass(parentNode[childKey][0], tmp_first_switchObj, consts.line.ROOTS);
1277
+ view.replaceSwitchClass(newLast, tmp_switchObj, consts.line.BOTTOM);
1278
+ }
1279
+ } else {
1280
+ view.replaceSwitchClass(newLast, tmp_switchObj, consts.line.BOTTOM);
1281
+ }
1282
+ tmp_ulObj.removeClass(consts.line.LINE);
1283
+ }
1284
+ },
1285
+ replaceIcoClass: function(node, obj, newName) {
1286
+ if (!obj || node.isAjaxing) return;
1287
+ var tmpName = obj.attr("class");
1288
+ if (tmpName == undefined) return;
1289
+ var tmpList = tmpName.split("_");
1290
+ switch (newName) {
1291
+ case consts.folder.OPEN:
1292
+ case consts.folder.CLOSE:
1293
+ case consts.folder.DOCU:
1294
+ tmpList[tmpList.length-1] = newName;
1295
+ break;
1296
+ }
1297
+ obj.attr("class", tmpList.join("_"));
1298
+ },
1299
+ replaceSwitchClass: function(node, obj, newName) {
1300
+ if (!obj) return;
1301
+ var tmpName = obj.attr("class");
1302
+ if (tmpName == undefined) return;
1303
+ var tmpList = tmpName.split("_");
1304
+ switch (newName) {
1305
+ case consts.line.ROOT:
1306
+ case consts.line.ROOTS:
1307
+ case consts.line.CENTER:
1308
+ case consts.line.BOTTOM:
1309
+ case consts.line.NOLINE:
1310
+ tmpList[0] = view.makeNodeLineClassEx(node) + newName;
1311
+ break;
1312
+ case consts.folder.OPEN:
1313
+ case consts.folder.CLOSE:
1314
+ case consts.folder.DOCU:
1315
+ tmpList[1] = newName;
1316
+ break;
1317
+ }
1318
+ obj.attr("class", tmpList.join("_"));
1319
+ if (newName !== consts.folder.DOCU) {
1320
+ obj.removeAttr("disabled");
1321
+ } else {
1322
+ obj.attr("disabled", "disabled");
1323
+ }
1324
+ },
1325
+ selectNode: function(setting, node, addFlag) {
1326
+ if (!addFlag) {
1327
+ view.cancelPreSelectedNode(setting);
1328
+ }
1329
+ $("#" + node.tId + consts.id.A).addClass(consts.node.CURSELECTED);
1330
+ data.addSelectedNode(setting, node);
1331
+ },
1332
+ setNodeFontCss: function(setting, treeNode) {
1333
+ var aObj = $("#" + treeNode.tId + consts.id.A),
1334
+ fontCss = view.makeNodeFontCss(setting, treeNode);
1335
+ if (fontCss) {
1336
+ aObj.css(fontCss);
1337
+ }
1338
+ },
1339
+ setNodeLineIcos: function(setting, node) {
1340
+ if (!node) return;
1341
+ var switchObj = $("#" + node.tId + consts.id.SWITCH),
1342
+ ulObj = $("#" + node.tId + consts.id.UL),
1343
+ icoObj = $("#" + node.tId + consts.id.ICON),
1344
+ ulLine = view.makeUlLineClass(setting, node);
1345
+ if (ulLine.length==0) {
1346
+ ulObj.removeClass(consts.line.LINE);
1347
+ } else {
1348
+ ulObj.addClass(ulLine);
1349
+ }
1350
+ switchObj.attr("class", view.makeNodeLineClass(setting, node));
1351
+ if (node.isParent) {
1352
+ switchObj.removeAttr("disabled");
1353
+ } else {
1354
+ switchObj.attr("disabled", "disabled");
1355
+ }
1356
+ icoObj.removeAttr("style");
1357
+ icoObj.attr("style", view.makeNodeIcoStyle(setting, node));
1358
+ icoObj.attr("class", view.makeNodeIcoClass(setting, node));
1359
+ },
1360
+ setNodeName: function(setting, node) {
1361
+ var title = data.getNodeTitle(setting, node),
1362
+ nObj = $("#" + node.tId + consts.id.SPAN);
1363
+ nObj.empty();
1364
+ if (setting.view.nameIsHTML) {
1365
+ nObj.html(data.getNodeName(setting, node));
1366
+ } else {
1367
+ nObj.text(data.getNodeName(setting, node));
1368
+ }
1369
+ if (tools.apply(setting.view.showTitle, [setting.treeId, node], setting.view.showTitle)) {
1370
+ var aObj = $("#" + node.tId + consts.id.A);
1371
+ aObj.attr("title", !title ? "" : title);
1372
+ }
1373
+ },
1374
+ setNodeTarget: function(node) {
1375
+ var aObj = $("#" + node.tId + consts.id.A);
1376
+ aObj.attr("target", view.makeNodeTarget(node));
1377
+ },
1378
+ setNodeUrl: function(setting, node) {
1379
+ var aObj = $("#" + node.tId + consts.id.A),
1380
+ url = view.makeNodeUrl(setting, node);
1381
+ if (url == null || url.length == 0) {
1382
+ aObj.removeAttr("href");
1383
+ } else {
1384
+ aObj.attr("href", url);
1385
+ }
1386
+ },
1387
+ switchNode: function(setting, node) {
1388
+ if (node.open || !tools.canAsync(setting, node)) {
1389
+ view.expandCollapseNode(setting, node, !node.open);
1390
+ } else if (setting.async.enable) {
1391
+ if (!view.asyncNode(setting, node)) {
1392
+ view.expandCollapseNode(setting, node, !node.open);
1393
+ return;
1394
+ }
1395
+ } else if (node) {
1396
+ view.expandCollapseNode(setting, node, !node.open);
1397
+ }
1398
+ }
1399
+ };
1400
+ // zTree defind
1401
+ $.fn.zTree = {
1402
+ consts : _consts,
1403
+ _z : {
1404
+ tools: tools,
1405
+ view: view,
1406
+ event: event,
1407
+ data: data
1408
+ },
1409
+ getZTreeObj: function(treeId) {
1410
+ var o = data.getZTreeTools(treeId);
1411
+ return o ? o : null;
1412
+ },
1413
+ destroy: function(treeId) {
1414
+ if (!!treeId && treeId.length > 0) {
1415
+ view.destroy(data.getSetting(treeId));
1416
+ } else {
1417
+ for(var s in settings) {
1418
+ view.destroy(settings[s]);
1419
+ }
1420
+ }
1421
+ },
1422
+ init: function(obj, zSetting, zNodes) {
1423
+ var setting = tools.clone(_setting);
1424
+ $.extend(true, setting, zSetting);
1425
+ setting.treeId = obj.attr("id");
1426
+ setting.treeObj = obj;
1427
+ setting.treeObj.empty();
1428
+ settings[setting.treeId] = setting;
1429
+ //For some older browser,(e.g., ie6)
1430
+ if(typeof document.body.style.maxHeight === "undefined") {
1431
+ setting.view.expandSpeed = "";
1432
+ }
1433
+ data.initRoot(setting);
1434
+ var root = data.getRoot(setting),
1435
+ childKey = setting.data.key.children;
1436
+ zNodes = zNodes ? tools.clone(tools.isArray(zNodes)? zNodes : [zNodes]) : [];
1437
+ if (setting.data.simpleData.enable) {
1438
+ root[childKey] = data.transformTozTreeFormat(setting, zNodes);
1439
+ } else {
1440
+ root[childKey] = zNodes;
1441
+ }
1442
+
1443
+ data.initCache(setting);
1444
+ event.unbindTree(setting);
1445
+ event.bindTree(setting);
1446
+ event.unbindEvent(setting);
1447
+ event.bindEvent(setting);
1448
+
1449
+ var zTreeTools = {
1450
+ setting : setting,
1451
+ addNodes : function(parentNode, newNodes, isSilent) {
1452
+ if (!newNodes) return null;
1453
+ if (!parentNode) parentNode = null;
1454
+ if (parentNode && !parentNode.isParent && setting.data.keep.leaf) return null;
1455
+ var xNewNodes = tools.clone(tools.isArray(newNodes)? newNodes: [newNodes]);
1456
+ function addCallback() {
1457
+ view.addNodes(setting, parentNode, xNewNodes, (isSilent==true));
1458
+ }
1459
+
1460
+ if (tools.canAsync(setting, parentNode)) {
1461
+ view.asyncNode(setting, parentNode, isSilent, addCallback);
1462
+ } else {
1463
+ addCallback();
1464
+ }
1465
+ return xNewNodes;
1466
+ },
1467
+ cancelSelectedNode : function(node) {
1468
+ view.cancelPreSelectedNode(this.setting, node);
1469
+ },
1470
+ destroy : function() {
1471
+ view.destroy(this.setting);
1472
+ },
1473
+ expandAll : function(expandFlag) {
1474
+ expandFlag = !!expandFlag;
1475
+ view.expandCollapseSonNode(this.setting, null, expandFlag, true);
1476
+ return expandFlag;
1477
+ },
1478
+ expandNode : function(node, expandFlag, sonSign, focus, callbackFlag) {
1479
+ if (!node || !node.isParent) return null;
1480
+ if (expandFlag !== true && expandFlag !== false) {
1481
+ expandFlag = !node.open;
1482
+ }
1483
+ callbackFlag = !!callbackFlag;
1484
+
1485
+ if (callbackFlag && expandFlag && (tools.apply(setting.callback.beforeExpand, [setting.treeId, node], true) == false)) {
1486
+ return null;
1487
+ } else if (callbackFlag && !expandFlag && (tools.apply(setting.callback.beforeCollapse, [setting.treeId, node], true) == false)) {
1488
+ return null;
1489
+ }
1490
+ if (expandFlag && node.parentTId) {
1491
+ view.expandCollapseParentNode(this.setting, node.getParentNode(), expandFlag, false);
1492
+ }
1493
+ if (expandFlag === node.open && !sonSign) {
1494
+ return null;
1495
+ }
1496
+
1497
+ data.getRoot(setting).expandTriggerFlag = callbackFlag;
1498
+ if (sonSign) {
1499
+ view.expandCollapseSonNode(this.setting, node, expandFlag, true, function() {
1500
+ if (focus !== false) {try{$("#" + node.tId).focus().blur();}catch(e){}}
1501
+ });
1502
+ } else {
1503
+ node.open = !expandFlag;
1504
+ view.switchNode(this.setting, node);
1505
+ if (focus !== false) {try{$("#" + node.tId).focus().blur();}catch(e){}}
1506
+ }
1507
+ return expandFlag;
1508
+ },
1509
+ getNodes : function() {
1510
+ return data.getNodes(this.setting);
1511
+ },
1512
+ getNodeByParam : function(key, value, parentNode) {
1513
+ if (!key) return null;
1514
+ return data.getNodeByParam(this.setting, parentNode?parentNode[this.setting.data.key.children]:data.getNodes(this.setting), key, value);
1515
+ },
1516
+ getNodeByTId : function(tId) {
1517
+ return data.getNodeCache(this.setting, tId);
1518
+ },
1519
+ getNodesByParam : function(key, value, parentNode) {
1520
+ if (!key) return null;
1521
+ return data.getNodesByParam(this.setting, parentNode?parentNode[this.setting.data.key.children]:data.getNodes(this.setting), key, value);
1522
+ },
1523
+ getNodesByParamFuzzy : function(key, value, parentNode) {
1524
+ if (!key) return null;
1525
+ return data.getNodesByParamFuzzy(this.setting, parentNode?parentNode[this.setting.data.key.children]:data.getNodes(this.setting), key, value);
1526
+ },
1527
+ getNodesByFilter: function(filter, isSingle, parentNode, invokeParam) {
1528
+ isSingle = !!isSingle;
1529
+ if (!filter || (typeof filter != "function")) return (isSingle ? null : []);
1530
+ return data.getNodesByFilter(this.setting, parentNode?parentNode[this.setting.data.key.children]:data.getNodes(this.setting), filter, isSingle, invokeParam);
1531
+ },
1532
+ getNodeIndex : function(node) {
1533
+ if (!node) return null;
1534
+ var childKey = setting.data.key.children,
1535
+ parentNode = (node.parentTId) ? node.getParentNode() : data.getRoot(this.setting);
1536
+ for (var i=0, l = parentNode[childKey].length; i < l; i++) {
1537
+ if (parentNode[childKey][i] == node) return i;
1538
+ }
1539
+ return -1;
1540
+ },
1541
+ getSelectedNodes : function() {
1542
+ var r = [], list = data.getRoot(this.setting).curSelectedList;
1543
+ for (var i=0, l=list.length; i<l; i++) {
1544
+ r.push(list[i]);
1545
+ }
1546
+ return r;
1547
+ },
1548
+ isSelectedNode : function(node) {
1549
+ return data.isSelectedNode(this.setting, node);
1550
+ },
1551
+ reAsyncChildNodes : function(parentNode, reloadType, isSilent) {
1552
+ if (!this.setting.async.enable) return;
1553
+ var isRoot = !parentNode;
1554
+ if (isRoot) {
1555
+ parentNode = data.getRoot(this.setting);
1556
+ }
1557
+ if (reloadType=="refresh") {
1558
+ var childKey = this.setting.data.key.children;
1559
+ for (var i = 0, l = parentNode[childKey] ? parentNode[childKey].length : 0; i < l; i++) {
1560
+ data.removeNodeCache(setting, parentNode[childKey][i]);
1561
+ }
1562
+ data.removeSelectedNode(setting);
1563
+ parentNode[childKey] = [];
1564
+ if (isRoot) {
1565
+ this.setting.treeObj.empty();
1566
+ } else {
1567
+ var ulObj = $("#" + parentNode.tId + consts.id.UL);
1568
+ ulObj.empty();
1569
+ }
1570
+ }
1571
+ view.asyncNode(this.setting, isRoot? null:parentNode, !!isSilent);
1572
+ },
1573
+ refresh : function() {
1574
+ this.setting.treeObj.empty();
1575
+ var root = data.getRoot(this.setting),
1576
+ nodes = root[this.setting.data.key.children]
1577
+ data.initRoot(this.setting);
1578
+ root[this.setting.data.key.children] = nodes
1579
+ data.initCache(this.setting);
1580
+ view.createNodes(this.setting, 0, root[this.setting.data.key.children]);
1581
+ },
1582
+ removeChildNodes : function(node) {
1583
+ if (!node) return null;
1584
+ var childKey = setting.data.key.children,
1585
+ nodes = node[childKey];
1586
+ view.removeChildNodes(setting, node);
1587
+ return nodes ? nodes : null;
1588
+ },
1589
+ removeNode : function(node, callbackFlag) {
1590
+ if (!node) return;
1591
+ callbackFlag = !!callbackFlag;
1592
+ if (callbackFlag && tools.apply(setting.callback.beforeRemove, [setting.treeId, node], true) == false) return;
1593
+ view.removeNode(setting, node);
1594
+ if (callbackFlag) {
1595
+ this.setting.treeObj.trigger(consts.event.REMOVE, [setting.treeId, node]);
1596
+ }
1597
+ },
1598
+ selectNode : function(node, addFlag) {
1599
+ if (!node) return;
1600
+ if (tools.uCanDo(this.setting)) {
1601
+ addFlag = setting.view.selectedMulti && addFlag;
1602
+ if (node.parentTId) {
1603
+ view.expandCollapseParentNode(this.setting, node.getParentNode(), true, false, function() {
1604
+ try{$("#" + node.tId).focus().blur();}catch(e){}
1605
+ });
1606
+ } else {
1607
+ try{$("#" + node.tId).focus().blur();}catch(e){}
1608
+ }
1609
+ view.selectNode(this.setting, node, addFlag);
1610
+ }
1611
+ },
1612
+ transformTozTreeNodes : function(simpleNodes) {
1613
+ return data.transformTozTreeFormat(this.setting, simpleNodes);
1614
+ },
1615
+ transformToArray : function(nodes) {
1616
+ return data.transformToArrayFormat(this.setting, nodes);
1617
+ },
1618
+ updateNode : function(node, checkTypeFlag) {
1619
+ if (!node) return;
1620
+ var nObj = $("#" + node.tId);
1621
+ if (nObj.get(0) && tools.uCanDo(this.setting)) {
1622
+ view.setNodeName(this.setting, node);
1623
+ view.setNodeTarget(node);
1624
+ view.setNodeUrl(this.setting, node);
1625
+ view.setNodeLineIcos(this.setting, node);
1626
+ view.setNodeFontCss(this.setting, node);
1627
+ }
1628
+ }
1629
+ }
1630
+ root.treeTools = zTreeTools;
1631
+ data.setZTreeTools(setting, zTreeTools);
1632
+
1633
+ if (root[childKey] && root[childKey].length > 0) {
1634
+ view.createNodes(setting, 0, root[childKey]);
1635
+ } else if (setting.async.enable && setting.async.url && setting.async.url !== '') {
1636
+ view.asyncNode(setting);
1637
+ }
1638
+ return zTreeTools;
1639
+ }
1640
+ };
1641
+
1642
+ var zt = $.fn.zTree,
1643
+ consts = zt.consts;
1644
+ })(jQuery);