jquery.ztree.excheck-3.5.js 21 KB

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