jquery.ztree.excheck-3.3.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /*
  2. * JQuery zTree excheck 3.3
  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: 2012-07-16
  12. */
  13. (function($){
  14. //default consts of excheck
  15. var _consts = {
  16. event: {
  17. CHECK: "ztree_check"
  18. },
  19. id: {
  20. CHECK: "_check"
  21. },
  22. checkbox: {
  23. STYLE: "checkbox",
  24. DEFAULT: "chk",
  25. DISABLED: "disable",
  26. FALSE: "false",
  27. TRUE: "true",
  28. FULL: "full",
  29. PART: "part",
  30. FOCUS: "focus"
  31. },
  32. radio: {
  33. STYLE: "radio",
  34. TYPE_ALL: "all",
  35. TYPE_LEVEL: "level"
  36. }
  37. },
  38. //default setting of excheck
  39. _setting = {
  40. check: {
  41. enable: false,
  42. autoCheckTrigger: false,
  43. chkStyle: _consts.checkbox.STYLE,
  44. nocheckInherit: false,
  45. radioType: _consts.radio.TYPE_LEVEL,
  46. chkboxType: {
  47. "Y": "ps",
  48. "N": "ps"
  49. }
  50. },
  51. data: {
  52. key: {
  53. checked: "checked"
  54. }
  55. },
  56. callback: {
  57. beforeCheck:null,
  58. onCheck:null
  59. }
  60. },
  61. //default root of excheck
  62. _initRoot = function (setting) {
  63. var r = data.getRoot(setting);
  64. r.radioCheckedList = [];
  65. },
  66. //default cache of excheck
  67. _initCache = function(treeId) {},
  68. //default bind event of excheck
  69. _bindEvent = function(setting) {
  70. var o = setting.treeObj,
  71. c = consts.event;
  72. o.unbind(c.CHECK);
  73. o.bind(c.CHECK, function (event, treeId, node) {
  74. tools.apply(setting.callback.onCheck, [event, treeId, node]);
  75. });
  76. },
  77. //default event proxy of excheck
  78. _eventProxy = function(e) {
  79. var target = e.target,
  80. setting = data.getSetting(e.data.treeId),
  81. tId = "", node = null,
  82. nodeEventType = "", treeEventType = "",
  83. nodeEventCallback = null, treeEventCallback = null;
  84. if (tools.eqs(e.type, "mouseover")) {
  85. if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode"+ consts.id.CHECK) !== null) {
  86. tId = target.parentNode.id;
  87. nodeEventType = "mouseoverCheck";
  88. }
  89. } else if (tools.eqs(e.type, "mouseout")) {
  90. if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode"+ consts.id.CHECK) !== null) {
  91. tId = target.parentNode.id;
  92. nodeEventType = "mouseoutCheck";
  93. }
  94. } else if (tools.eqs(e.type, "click")) {
  95. if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode"+ consts.id.CHECK) !== null) {
  96. tId = target.parentNode.id;
  97. nodeEventType = "checkNode";
  98. }
  99. }
  100. if (tId.length>0) {
  101. node = data.getNodeCache(setting, tId);
  102. switch (nodeEventType) {
  103. case "checkNode" :
  104. nodeEventCallback = _handler.onCheckNode;
  105. break;
  106. case "mouseoverCheck" :
  107. nodeEventCallback = _handler.onMouseoverCheck;
  108. break;
  109. case "mouseoutCheck" :
  110. nodeEventCallback = _handler.onMouseoutCheck;
  111. break;
  112. }
  113. }
  114. var proxyResult = {
  115. stop: false,
  116. node: node,
  117. nodeEventType: nodeEventType,
  118. nodeEventCallback: nodeEventCallback,
  119. treeEventType: treeEventType,
  120. treeEventCallback: treeEventCallback
  121. };
  122. return proxyResult
  123. },
  124. //default init node of excheck
  125. _initNode = function(setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
  126. if (!n) return;
  127. var checkedKey = setting.data.key.checked;
  128. if (typeof n[checkedKey] == "string") n[checkedKey] = tools.eqs(n[checkedKey], "true");
  129. n[checkedKey] = !!n[checkedKey];
  130. n.checkedOld = n[checkedKey];
  131. n.nocheck = !!n.nocheck || (setting.check.nocheckInherit && parentNode && !!parentNode.nocheck);
  132. n.chkDisabled = !!n.chkDisabled || (parentNode && !!parentNode.chkDisabled);
  133. if (typeof n.halfCheck == "string") n.halfCheck = tools.eqs(n.halfCheck, "true");
  134. n.halfCheck = !!n.halfCheck;
  135. n.check_Child_State = -1;
  136. n.check_Focus = false;
  137. n.getCheckStatus = function() {return data.getCheckStatus(setting, n);};
  138. if (isLastNode) {
  139. data.makeChkFlag(setting, parentNode);
  140. }
  141. },
  142. //add dom for check
  143. _beforeA = function(setting, node, html) {
  144. var checkedKey = setting.data.key.checked;
  145. if (setting.check.enable) {
  146. data.makeChkFlag(setting, node);
  147. if (setting.check.chkStyle == consts.radio.STYLE && setting.check.radioType == consts.radio.TYPE_ALL && node[checkedKey] ) {
  148. var r = data.getRoot(setting);
  149. r.radioCheckedList.push(node);
  150. }
  151. html.push("<span ID='", node.tId, consts.id.CHECK, "' class='", view.makeChkClass(setting, node), "' treeNode", consts.id.CHECK, (node.nocheck === true?" style='display:none;'":""),"></span>");
  152. }
  153. },
  154. //update zTreeObj, add method of check
  155. _zTreeTools = function(setting, zTreeTools) {
  156. zTreeTools.checkNode = function(node, checked, checkTypeFlag, callbackFlag) {
  157. var checkedKey = this.setting.data.key.checked;
  158. if (node.chkDisabled === true) return;
  159. if (checked !== true && checked !== false) {
  160. checked = !node[checkedKey];
  161. }
  162. callbackFlag = !!callbackFlag;
  163. if (node[checkedKey] === checked && !checkTypeFlag) {
  164. return;
  165. } else if (callbackFlag && tools.apply(this.setting.callback.beforeCheck, [this.setting.treeId, node], true) == false) {
  166. return;
  167. }
  168. if (tools.uCanDo(this.setting) && this.setting.check.enable && node.nocheck !== true) {
  169. node[checkedKey] = checked;
  170. var checkObj = $("#" + node.tId + consts.id.CHECK);
  171. if (checkTypeFlag || this.setting.check.chkStyle === consts.radio.STYLE) view.checkNodeRelation(this.setting, node);
  172. view.setChkClass(this.setting, checkObj, node);
  173. view.repairParentChkClassWithSelf(this.setting, node);
  174. if (callbackFlag) {
  175. setting.treeObj.trigger(consts.event.CHECK, [setting.treeId, node]);
  176. }
  177. }
  178. }
  179. zTreeTools.checkAllNodes = function(checked) {
  180. view.repairAllChk(this.setting, !!checked);
  181. }
  182. zTreeTools.getCheckedNodes = function(checked) {
  183. var childKey = this.setting.data.key.children;
  184. checked = (checked !== false);
  185. return data.getTreeCheckedNodes(this.setting, data.getRoot(setting)[childKey], checked);
  186. }
  187. zTreeTools.getChangeCheckedNodes = function() {
  188. var childKey = this.setting.data.key.children;
  189. return data.getTreeChangeCheckedNodes(this.setting, data.getRoot(setting)[childKey]);
  190. }
  191. zTreeTools.setChkDisabled = function(node, disabled) {
  192. disabled = !!disabled;
  193. view.repairSonChkDisabled(this.setting, node, disabled);
  194. if (!disabled) view.repairParentChkDisabled(this.setting, node, disabled);
  195. }
  196. var _updateNode = zTreeTools.updateNode;
  197. zTreeTools.updateNode = function(node, checkTypeFlag) {
  198. if (_updateNode) _updateNode.apply(zTreeTools, arguments);
  199. if (!node || !this.setting.check.enable) return;
  200. var nObj = $("#" + node.tId);
  201. if (nObj.get(0) && tools.uCanDo(this.setting)) {
  202. var checkObj = $("#" + node.tId + consts.id.CHECK);
  203. if (checkTypeFlag == true || this.setting.check.chkStyle === consts.radio.STYLE) view.checkNodeRelation(this.setting, node);
  204. view.setChkClass(this.setting, checkObj, node);
  205. view.repairParentChkClassWithSelf(this.setting, node);
  206. }
  207. }
  208. },
  209. //method of operate data
  210. _data = {
  211. getRadioCheckedList: function(setting) {
  212. var checkedList = data.getRoot(setting).radioCheckedList;
  213. for (var i=0, j=checkedList.length; i<j; i++) {
  214. if(!data.getNodeCache(setting, checkedList[i].tId)) {
  215. checkedList.splice(i, 1);
  216. i--; j--;
  217. }
  218. }
  219. return checkedList;
  220. },
  221. getCheckStatus: function(setting, node) {
  222. if (!setting.check.enable || node.nocheck) return null;
  223. var checkedKey = setting.data.key.checked,
  224. r = {
  225. checked: node[checkedKey],
  226. half: node.halfCheck ? node.halfCheck : (setting.check.chkStyle == consts.radio.STYLE ? (node.check_Child_State === 2) : (node[checkedKey] ? (node.check_Child_State > -1 && node.check_Child_State < 2) : (node.check_Child_State > 0)))
  227. };
  228. return r;
  229. },
  230. getTreeCheckedNodes: function(setting, nodes, checked, results) {
  231. if (!nodes) return [];
  232. var childKey = setting.data.key.children,
  233. checkedKey = setting.data.key.checked,
  234. onlyOne = (checked && setting.check.chkStyle == consts.radio.STYLE && setting.check.radioType == consts.radio.TYPE_ALL);
  235. results = !results ? [] : results;
  236. for (var i = 0, l = nodes.length; i < l; i++) {
  237. if (nodes[i].nocheck !== true && nodes[i][checkedKey] == checked) {
  238. results.push(nodes[i]);
  239. if(onlyOne) {
  240. break;
  241. }
  242. }
  243. data.getTreeCheckedNodes(setting, nodes[i][childKey], checked, results);
  244. if(onlyOne && results.length > 0) {
  245. break;
  246. }
  247. }
  248. return results;
  249. },
  250. getTreeChangeCheckedNodes: function(setting, nodes, results) {
  251. if (!nodes) return [];
  252. var childKey = setting.data.key.children,
  253. checkedKey = setting.data.key.checked;
  254. results = !results ? [] : results;
  255. for (var i = 0, l = nodes.length; i < l; i++) {
  256. if (nodes[i].nocheck !== true && nodes[i][checkedKey] != nodes[i].checkedOld) {
  257. results.push(nodes[i]);
  258. }
  259. data.getTreeChangeCheckedNodes(setting, nodes[i][childKey], results);
  260. }
  261. return results;
  262. },
  263. makeChkFlag: function(setting, node) {
  264. if (!node) return;
  265. var childKey = setting.data.key.children,
  266. checkedKey = setting.data.key.checked,
  267. chkFlag = -1;
  268. if (node[childKey]) {
  269. var start = false;
  270. for (var i = 0, l = node[childKey].length; i < l; i++) {
  271. var cNode = node[childKey][i];
  272. var tmp = -1;
  273. if (setting.check.chkStyle == consts.radio.STYLE) {
  274. if (cNode.nocheck === true) {
  275. tmp = cNode.check_Child_State;
  276. } else if (cNode.halfCheck === true) {
  277. tmp = 2;
  278. } else if (cNode.nocheck !== true && cNode[checkedKey]) {
  279. tmp = 2;
  280. } else {
  281. tmp = cNode.check_Child_State > 0 ? 2:0;
  282. }
  283. if (tmp == 2) {
  284. chkFlag = 2; break;
  285. } else if (tmp == 0){
  286. chkFlag = 0;
  287. }
  288. } else if (setting.check.chkStyle == consts.checkbox.STYLE) {
  289. if (cNode.nocheck === true) {
  290. tmp = cNode.check_Child_State;
  291. } else if (cNode.halfCheck === true) {
  292. tmp = 1;
  293. } else if (cNode.nocheck !== true && cNode[checkedKey] ) {
  294. tmp = (cNode.check_Child_State === -1 || cNode.check_Child_State === 2) ? 2 : 1;
  295. } else {
  296. tmp = (cNode.check_Child_State > 0) ? 1 : 0;
  297. }
  298. if (tmp === 1) {
  299. chkFlag = 1; break;
  300. } else if (tmp === 2 && start && tmp !== chkFlag) {
  301. chkFlag = 1; break;
  302. } else if (chkFlag === 2 && tmp > -1 && tmp < 2) {
  303. chkFlag = 1; break;
  304. } else if (tmp > -1) {
  305. chkFlag = tmp;
  306. }
  307. if (!start) start = (cNode.nocheck !== true);
  308. }
  309. }
  310. }
  311. node.check_Child_State = chkFlag;
  312. }
  313. },
  314. //method of event proxy
  315. _event = {
  316. },
  317. //method of event handler
  318. _handler = {
  319. onCheckNode: function (event, node) {
  320. if (node.chkDisabled === true) return false;
  321. var setting = data.getSetting(event.data.treeId),
  322. checkedKey = setting.data.key.checked;
  323. if (tools.apply(setting.callback.beforeCheck, [setting.treeId, node], true) == false) return true;
  324. node[checkedKey] = !node[checkedKey];
  325. view.checkNodeRelation(setting, node);
  326. var checkObj = $("#" + node.tId + consts.id.CHECK);
  327. view.setChkClass(setting, checkObj, node);
  328. view.repairParentChkClassWithSelf(setting, node);
  329. setting.treeObj.trigger(consts.event.CHECK, [setting.treeId, node]);
  330. return true;
  331. },
  332. onMouseoverCheck: function(event, node) {
  333. if (node.chkDisabled === true) return false;
  334. var setting = data.getSetting(event.data.treeId),
  335. checkObj = $("#" + node.tId + consts.id.CHECK);
  336. node.check_Focus = true;
  337. view.setChkClass(setting, checkObj, node);
  338. return true;
  339. },
  340. onMouseoutCheck: function(event, node) {
  341. if (node.chkDisabled === true) return false;
  342. var setting = data.getSetting(event.data.treeId),
  343. checkObj = $("#" + node.tId + consts.id.CHECK);
  344. node.check_Focus = false;
  345. view.setChkClass(setting, checkObj, node);
  346. return true;
  347. }
  348. },
  349. //method of tools for zTree
  350. _tools = {
  351. },
  352. //method of operate ztree dom
  353. _view = {
  354. checkNodeRelation: function(setting, node) {
  355. var pNode, i, l,
  356. childKey = setting.data.key.children,
  357. checkedKey = setting.data.key.checked,
  358. r = consts.radio;
  359. if (setting.check.chkStyle == r.STYLE) {
  360. var checkedList = data.getRadioCheckedList(setting);
  361. if (node[checkedKey]) {
  362. if (setting.check.radioType == r.TYPE_ALL) {
  363. for (i = checkedList.length-1; i >= 0; i--) {
  364. pNode = checkedList[i];
  365. pNode[checkedKey] = false;
  366. checkedList.splice(i, 1);
  367. view.setChkClass(setting, $("#" + pNode.tId + consts.id.CHECK), pNode);
  368. if (pNode.parentTId != node.parentTId) {
  369. view.repairParentChkClassWithSelf(setting, pNode);
  370. }
  371. }
  372. checkedList.push(node);
  373. } else {
  374. var parentNode = (node.parentTId) ? node.getParentNode() : data.getRoot(setting);
  375. for (i = 0, l = parentNode[childKey].length; i < l; i++) {
  376. pNode = parentNode[childKey][i];
  377. if (pNode[checkedKey] && pNode != node) {
  378. pNode[checkedKey] = false;
  379. view.setChkClass(setting, $("#" + pNode.tId + consts.id.CHECK), pNode);
  380. }
  381. }
  382. }
  383. } else if (setting.check.radioType == r.TYPE_ALL) {
  384. for (i = 0, l = checkedList.length; i < l; i++) {
  385. if (node == checkedList[i]) {
  386. checkedList.splice(i, 1);
  387. break;
  388. }
  389. }
  390. }
  391. } else {
  392. if (node[checkedKey] && (!node[childKey] || node[childKey].length==0 || setting.check.chkboxType.Y.indexOf("s") > -1)) {
  393. view.setSonNodeCheckBox(setting, node, true);
  394. }
  395. if (!node[checkedKey] && (!node[childKey] || node[childKey].length==0 || setting.check.chkboxType.N.indexOf("s") > -1)) {
  396. view.setSonNodeCheckBox(setting, node, false);
  397. }
  398. if (node[checkedKey] && setting.check.chkboxType.Y.indexOf("p") > -1) {
  399. view.setParentNodeCheckBox(setting, node, true);
  400. }
  401. if (!node[checkedKey] && setting.check.chkboxType.N.indexOf("p") > -1) {
  402. view.setParentNodeCheckBox(setting, node, false);
  403. }
  404. }
  405. },
  406. makeChkClass: function(setting, node) {
  407. var checkedKey = setting.data.key.checked,
  408. c = consts.checkbox, r = consts.radio,
  409. fullStyle = "";
  410. if (node.chkDisabled === true) {
  411. fullStyle = c.DISABLED;
  412. } else if (node.halfCheck) {
  413. fullStyle = c.PART;
  414. } else if (setting.check.chkStyle == r.STYLE) {
  415. fullStyle = (node.check_Child_State < 1)? c.FULL:c.PART;
  416. } else {
  417. fullStyle = node[checkedKey] ? ((node.check_Child_State === 2 || node.check_Child_State === -1) ? c.FULL:c.PART) : ((node.check_Child_State < 1)? c.FULL:c.PART);
  418. }
  419. var chkName = setting.check.chkStyle + "_" + (node[checkedKey] ? c.TRUE : c.FALSE) + "_" + fullStyle;
  420. chkName = (node.check_Focus && node.chkDisabled !== true) ? chkName + "_" + c.FOCUS : chkName;
  421. return "button " + c.DEFAULT + " " + chkName;
  422. },
  423. repairAllChk: function(setting, checked) {
  424. if (setting.check.enable && setting.check.chkStyle === consts.checkbox.STYLE) {
  425. var checkedKey = setting.data.key.checked,
  426. childKey = setting.data.key.children,
  427. root = data.getRoot(setting);
  428. for (var i = 0, l = root[childKey].length; i<l ; i++) {
  429. var node = root[childKey][i];
  430. if (node.nocheck !== true) {
  431. node[checkedKey] = checked;
  432. }
  433. view.setSonNodeCheckBox(setting, node, checked);
  434. }
  435. }
  436. },
  437. repairChkClass: function(setting, node) {
  438. if (!node) return;
  439. data.makeChkFlag(setting, node);
  440. var checkObj = $("#" + node.tId + consts.id.CHECK);
  441. view.setChkClass(setting, checkObj, node);
  442. },
  443. repairParentChkClass: function(setting, node) {
  444. if (!node || !node.parentTId) return;
  445. var pNode = node.getParentNode();
  446. view.repairChkClass(setting, pNode);
  447. view.repairParentChkClass(setting, pNode);
  448. },
  449. repairParentChkClassWithSelf: function(setting, node) {
  450. if (!node) return;
  451. var childKey = setting.data.key.children;
  452. if (node[childKey] && node[childKey].length > 0) {
  453. view.repairParentChkClass(setting, node[childKey][0]);
  454. } else {
  455. view.repairParentChkClass(setting, node);
  456. }
  457. },
  458. repairSonChkDisabled: function(setting, node, chkDisabled) {
  459. if (!node) return;
  460. var childKey = setting.data.key.children;
  461. if (node.chkDisabled != chkDisabled) {
  462. node.chkDisabled = chkDisabled;
  463. if (node.nocheck !== true) view.repairChkClass(setting, node);
  464. }
  465. if (node[childKey]) {
  466. for (var i = 0, l = node[childKey].length; i < l; i++) {
  467. var sNode = node[childKey][i];
  468. view.repairSonChkDisabled(setting, sNode, chkDisabled);
  469. }
  470. }
  471. },
  472. repairParentChkDisabled: function(setting, node, chkDisabled) {
  473. if (!node) return;
  474. if (node.chkDisabled != chkDisabled) {
  475. node.chkDisabled = chkDisabled;
  476. if (node.nocheck !== true) view.repairChkClass(setting, node);
  477. }
  478. view.repairParentChkDisabled(setting, node.getParentNode(), chkDisabled);
  479. },
  480. setChkClass: function(setting, obj, node) {
  481. if (!obj) return;
  482. if (node.nocheck === true) {
  483. obj.hide();
  484. } else {
  485. obj.show();
  486. }
  487. obj.removeClass();
  488. obj.addClass(view.makeChkClass(setting, node));
  489. },
  490. setParentNodeCheckBox: function(setting, node, value, srcNode) {
  491. var childKey = setting.data.key.children,
  492. checkedKey = setting.data.key.checked,
  493. checkObj = $("#" + node.tId + consts.id.CHECK);
  494. if (!srcNode) srcNode = node;
  495. data.makeChkFlag(setting, node);
  496. if (node.nocheck !== true && node.chkDisabled !== true) {
  497. node[checkedKey] = value;
  498. view.setChkClass(setting, checkObj, node);
  499. if (setting.check.autoCheckTrigger && node != srcNode && node.nocheck !== true) {
  500. setting.treeObj.trigger(consts.event.CHECK, [setting.treeId, node]);
  501. }
  502. }
  503. if (node.parentTId) {
  504. var pSign = true;
  505. if (!value) {
  506. var pNodes = node.getParentNode()[childKey];
  507. for (var i = 0, l = pNodes.length; i < l; i++) {
  508. if ((pNodes[i].nocheck !== true && pNodes[i][checkedKey])
  509. || (pNodes[i].nocheck === true && pNodes[i].check_Child_State > 0)) {
  510. pSign = false;
  511. break;
  512. }
  513. }
  514. }
  515. if (pSign) {
  516. view.setParentNodeCheckBox(setting, node.getParentNode(), value, srcNode);
  517. }
  518. }
  519. },
  520. setSonNodeCheckBox: function(setting, node, value, srcNode) {
  521. if (!node) return;
  522. var childKey = setting.data.key.children,
  523. checkedKey = setting.data.key.checked,
  524. checkObj = $("#" + node.tId + consts.id.CHECK);
  525. if (!srcNode) srcNode = node;
  526. var hasDisable = false;
  527. if (node[childKey]) {
  528. for (var i = 0, l = node[childKey].length; i < l && node.chkDisabled !== true; i++) {
  529. var sNode = node[childKey][i];
  530. view.setSonNodeCheckBox(setting, sNode, value, srcNode);
  531. if (sNode.chkDisabled === true) hasDisable = true;
  532. }
  533. }
  534. if (node != data.getRoot(setting) && node.chkDisabled !== true) {
  535. if (hasDisable && node.nocheck !== true) {
  536. data.makeChkFlag(setting, node);
  537. }
  538. if (node.nocheck !== true) {
  539. node[checkedKey] = value;
  540. if (!hasDisable) node.check_Child_State = (node[childKey] && node[childKey].length > 0) ? (value ? 2 : 0) : -1;
  541. } else {
  542. node.check_Child_State = -1;
  543. }
  544. view.setChkClass(setting, checkObj, node);
  545. if (setting.check.autoCheckTrigger && node != srcNode && node.nocheck !== true) {
  546. setting.treeObj.trigger(consts.event.CHECK, [setting.treeId, node]);
  547. }
  548. }
  549. }
  550. },
  551. _z = {
  552. tools: _tools,
  553. view: _view,
  554. event: _event,
  555. data: _data
  556. };
  557. $.extend(true, $.fn.zTree.consts, _consts);
  558. $.extend(true, $.fn.zTree._z, _z);
  559. var zt = $.fn.zTree,
  560. tools = zt._z.tools,
  561. consts = zt.consts,
  562. view = zt._z.view,
  563. data = zt._z.data,
  564. event = zt._z.event;
  565. data.exSetting(_setting);
  566. data.addInitBind(_bindEvent);
  567. data.addInitCache(_initCache);
  568. data.addInitNode(_initNode);
  569. data.addInitProxy(_eventProxy);
  570. data.addInitRoot(_initRoot);
  571. data.addBeforeA(_beforeA);
  572. data.addZTreeTools(_zTreeTools);
  573. var _createNodes = view.createNodes;
  574. view.createNodes = function(setting, level, nodes, parentNode) {
  575. if (_createNodes) _createNodes.apply(view, arguments);
  576. if (!nodes) return;
  577. view.repairParentChkClassWithSelf(setting, parentNode);
  578. }
  579. var _removeNode = view.removeNode;
  580. view.removeNode = function(setting, node) {
  581. var parentNode = node.getParentNode();
  582. if (_removeNode) _removeNode.apply(view, arguments);
  583. if (!node || !parentNode) return;
  584. view.repairChkClass(setting, parentNode);
  585. view.repairParentChkClass(setting, parentNode);
  586. }
  587. })(jQuery);