jquery.ztree.core-3.5.js 54 KB

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