jquery.ztree.excheck.js 25 KB

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