jquery.ztree.excheck.js 21.4 KB
Newer Older
Z
ztree 已提交
1
/*
2
 * JQuery zTree excheck v3.5.35
Z
ztree 已提交
3
 * http://treejs.cn/
Z
ztree 已提交
4 5 6 7 8 9 10
 *
 * Copyright (c) 2010 Hunter.z
 *
 * Licensed same as jquery - MIT License
 * http://www.opensource.org/licenses/mit-license.php
 *
 * email: hunter.z@263.net
11
 * Date: 2018-03-30
Z
ztree 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
 */
(function($){
	//default consts of excheck
	var _consts = {
		event: {
			CHECK: "ztree_check"
		},
		id: {
			CHECK: "_check"
		},
		checkbox: {
			STYLE: "checkbox",
			DEFAULT: "chk",
			DISABLED: "disable",
			FALSE: "false",
			TRUE: "true",
			FULL: "full",
			PART: "part",
			FOCUS: "focus"
		},
		radio: {
			STYLE: "radio",
			TYPE_ALL: "all",
			TYPE_LEVEL: "level"
		}
	},
	//default setting of excheck
	_setting = {
		check: {
			enable: false,
			autoCheckTrigger: false,
			chkStyle: _consts.checkbox.STYLE,
			nocheckInherit: false,
			chkDisabledInherit: false,
			radioType: _consts.radio.TYPE_LEVEL,
			chkboxType: {
				"Y": "ps",
				"N": "ps"
			}
		},
		data: {
			key: {
				checked: "checked"
			}
		},
		callback: {
			beforeCheck:null,
			onCheck:null
		}
	},
	//default root of excheck
	_initRoot = function (setting) {
		var r = data.getRoot(setting);
		r.radioCheckedList = [];
	},
	//default cache of excheck
	_initCache = function(treeId) {},
	//default bind event of excheck
	_bindEvent = function(setting) {
		var o = setting.treeObj,
		c = consts.event;
		o.bind(c.CHECK, function (event, srcEvent, treeId, node) {
74 75
			event.srcEvent = srcEvent;
			tools.apply(setting.callback.onCheck, [event, treeId, node]);
Z
ztree 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
		});
	},
	_unbindEvent = function(setting) {
		var o = setting.treeObj,
		c = consts.event;
		o.unbind(c.CHECK);
	},
	//default event proxy of excheck
	_eventProxy = function(e) {
		var target = e.target,
		setting = data.getSetting(e.data.treeId),
		tId = "", node = null,
		nodeEventType = "", treeEventType = "",
		nodeEventCallback = null, treeEventCallback = null;

		if (tools.eqs(e.type, "mouseover")) {
			if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode"+ consts.id.CHECK) !== null) {
				tId = tools.getNodeMainDom(target).id;
				nodeEventType = "mouseoverCheck";
			}
		} else if (tools.eqs(e.type, "mouseout")) {
			if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode"+ consts.id.CHECK) !== null) {
				tId = tools.getNodeMainDom(target).id;
				nodeEventType = "mouseoutCheck";
			}
		} else if (tools.eqs(e.type, "click")) {
			if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode"+ consts.id.CHECK) !== null) {
				tId = tools.getNodeMainDom(target).id;
				nodeEventType = "checkNode";
			}
		}
		if (tId.length>0) {
			node = data.getNodeCache(setting, tId);
			switch (nodeEventType) {
				case "checkNode" :
					nodeEventCallback = _handler.onCheckNode;
					break;
				case "mouseoverCheck" :
					nodeEventCallback = _handler.onMouseoverCheck;
					break;
				case "mouseoutCheck" :
					nodeEventCallback = _handler.onMouseoutCheck;
					break;
			}
		}
		var proxyResult = {
			stop: nodeEventType === "checkNode",
			node: node,
			nodeEventType: nodeEventType,
			nodeEventCallback: nodeEventCallback,
			treeEventType: treeEventType,
			treeEventCallback: treeEventCallback
		};
		return proxyResult
	},
	//default init node of excheck
	_initNode = function(setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
		if (!n) return;
134 135 136
		var checked = data.nodeChecked(setting, n);
		checked = data.nodeChecked(setting, n, checked);
		n.checkedOld = checked;
Z
ztree 已提交
137 138 139 140 141 142 143 144 145 146
		if (typeof n.nocheck == "string") n.nocheck = tools.eqs(n.nocheck, "true");
		n.nocheck = !!n.nocheck || (setting.check.nocheckInherit && parentNode && !!parentNode.nocheck);
		if (typeof n.chkDisabled == "string") n.chkDisabled = tools.eqs(n.chkDisabled, "true");
		n.chkDisabled = !!n.chkDisabled || (setting.check.chkDisabledInherit && parentNode && !!parentNode.chkDisabled);
		if (typeof n.halfCheck == "string") n.halfCheck = tools.eqs(n.halfCheck, "true");
		n.halfCheck = !!n.halfCheck;
		n.check_Child_State = -1;
		n.check_Focus = false;
		n.getCheckStatus = function() {return data.getCheckStatus(setting, n);};

147
		if (setting.check.chkStyle == consts.radio.STYLE && setting.check.radioType == consts.radio.TYPE_ALL && checked) {
Z
ztree 已提交
148 149 150 151 152 153 154 155 156 157 158 159 160 161
			var r = data.getRoot(setting);
			r.radioCheckedList.push(n);
		}
	},
	//add dom for check
	_beforeA = function(setting, node, html) {
		if (setting.check.enable) {
			data.makeChkFlag(setting, node);
			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>");
		}
	},
	//update zTreeObj, add method of check
	_zTreeTools = function(setting, zTreeTools) {
		zTreeTools.checkNode = function(node, checked, checkTypeFlag, callbackFlag) {
162
			var nodeChecked = data.nodeChecked(setting, node);
Z
ztree 已提交
163 164
			if (node.chkDisabled === true) return;
			if (checked !== true && checked !== false) {
165
				checked = !nodeChecked;
Z
ztree 已提交
166 167 168
			}
			callbackFlag = !!callbackFlag;

169
			if (nodeChecked === checked && !checkTypeFlag) {
Z
ztree 已提交
170
				return;
171
			} else if (callbackFlag && tools.apply(this.setting.callback.beforeCheck, [this.setting.treeId, node], true) == false) {
Z
ztree 已提交
172 173
				return;
			}
174
			if (tools.uCanDo(this.setting) && this.setting.check.enable && node.nocheck !== true) {
175
        data.nodeChecked(setting, node, checked);
176 177 178 179
				var checkObj = $$(node, consts.id.CHECK, this.setting);
				if (checkTypeFlag || this.setting.check.chkStyle === consts.radio.STYLE) view.checkNodeRelation(this.setting, node);
				view.setChkClass(this.setting, checkObj, node);
				view.repairParentChkClassWithSelf(this.setting, node);
Z
ztree 已提交
180
				if (callbackFlag) {
181
					this.setting.treeObj.trigger(consts.event.CHECK, [null, this.setting.treeId, node]);
Z
ztree 已提交
182 183 184 185 186
				}
			}
		}

		zTreeTools.checkAllNodes = function(checked) {
187
			view.repairAllChk(this.setting, !!checked);
Z
ztree 已提交
188 189 190
		}

		zTreeTools.getCheckedNodes = function(checked) {
191 192 193
			var checked = (checked !== false);
			var children = data.nodeChildren(setting, data.getRoot(this.setting));
			return data.getTreeCheckedNodes(this.setting, children, checked);
Z
ztree 已提交
194 195 196
		}

		zTreeTools.getChangeCheckedNodes = function() {
197 198
      var children = data.nodeChildren(setting, data.getRoot(this.setting));
			return data.getTreeChangeCheckedNodes(this.setting, children);
Z
ztree 已提交
199 200 201 202 203 204
		}

		zTreeTools.setChkDisabled = function(node, disabled, inheritParent, inheritChildren) {
			disabled = !!disabled;
			inheritParent = !!inheritParent;
			inheritChildren = !!inheritChildren;
205 206
			view.repairSonChkDisabled(this.setting, node, disabled, inheritChildren);
			view.repairParentChkDisabled(this.setting, node.getParentNode(), disabled, inheritParent);
Z
ztree 已提交
207 208 209 210 211
		}

		var _updateNode = zTreeTools.updateNode;
		zTreeTools.updateNode = function(node, checkTypeFlag) {
			if (_updateNode) _updateNode.apply(zTreeTools, arguments);
212 213 214 215 216 217 218
			if (!node || !this.setting.check.enable) return;
			var nObj = $$(node, this.setting);
			if (nObj.get(0) && tools.uCanDo(this.setting)) {
				var checkObj = $$(node, consts.id.CHECK, this.setting);
				if (checkTypeFlag == true || this.setting.check.chkStyle === consts.radio.STYLE) view.checkNodeRelation(this.setting, node);
				view.setChkClass(this.setting, checkObj, node);
				view.repairParentChkClassWithSelf(this.setting, node);
Z
ztree 已提交
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
			}
		}
	},
	//method of operate data
	_data = {
		getRadioCheckedList: function(setting) {
			var checkedList = data.getRoot(setting).radioCheckedList;
			for (var i=0, j=checkedList.length; i<j; i++) {
				if(!data.getNodeCache(setting, checkedList[i].tId)) {
					checkedList.splice(i, 1);
					i--; j--;
				}
			}
			return checkedList;
		},
		getCheckStatus: function(setting, node) {
			if (!setting.check.enable || node.nocheck || node.chkDisabled) return null;
236
			var checked = data.nodeChecked(setting, node),
Z
ztree 已提交
237
			r = {
238 239
				checked: checked,
				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)))
Z
ztree 已提交
240 241 242 243 244
			};
			return r;
		},
		getTreeCheckedNodes: function(setting, nodes, checked, results) {
			if (!nodes) return [];
245
			var onlyOne = (checked && setting.check.chkStyle == consts.radio.STYLE && setting.check.radioType == consts.radio.TYPE_ALL);
Z
ztree 已提交
246 247
			results = !results ? [] : results;
			for (var i = 0, l = nodes.length; i < l; i++) {
248 249 250 251 252
				var node = nodes[i];
        var children = data.nodeChildren(setting, node);
        var nodeChecked = data.nodeChecked(setting, node);
				if (node.nocheck !== true && node.chkDisabled !== true && nodeChecked == checked) {
					results.push(node);
Z
ztree 已提交
253 254 255 256
					if(onlyOne) {
						break;
					}
				}
257
				data.getTreeCheckedNodes(setting, children, checked, results);
Z
ztree 已提交
258 259 260 261 262 263 264 265 266 267
				if(onlyOne && results.length > 0) {
					break;
				}
			}
			return results;
		},
		getTreeChangeCheckedNodes: function(setting, nodes, results) {
			if (!nodes) return [];
			results = !results ? [] : results;
			for (var i = 0, l = nodes.length; i < l; i++) {
268 269 270 271 272
				var node = nodes[i];
        var children = data.nodeChildren(setting, node);
        var nodeChecked = data.nodeChecked(setting, node);
				if (node.nocheck !== true && node.chkDisabled !== true && nodeChecked != node.checkedOld) {
					results.push(node);
Z
ztree 已提交
273
				}
274
				data.getTreeChangeCheckedNodes(setting, children, results);
Z
ztree 已提交
275 276 277 278 279
			}
			return results;
		},
		makeChkFlag: function(setting, node) {
			if (!node) return;
280 281 282 283 284 285
			var chkFlag = -1;
			var children = data.nodeChildren(setting, node);
			if (children) {
				for (var i = 0, l = children.length; i < l; i++) {
					var cNode = children[i];
          var nodeChecked = data.nodeChecked(setting, cNode);
Z
ztree 已提交
286 287 288 289 290 291
					var tmp = -1;
					if (setting.check.chkStyle == consts.radio.STYLE) {
						if (cNode.nocheck === true || cNode.chkDisabled === true) {
							tmp = cNode.check_Child_State;
						} else if (cNode.halfCheck === true) {
							tmp = 2;
292
						} else if (nodeChecked) {
Z
ztree 已提交
293 294 295 296 297 298 299 300 301 302 303 304 305 306
							tmp = 2;
						} else {
							tmp = cNode.check_Child_State > 0 ? 2:0;
						}
						if (tmp == 2) {
							chkFlag = 2; break;
						} else if (tmp == 0){
							chkFlag = 0;
						}
					} else if (setting.check.chkStyle == consts.checkbox.STYLE) {
						if (cNode.nocheck === true || cNode.chkDisabled === true) {
							tmp = cNode.check_Child_State;
						} else if (cNode.halfCheck === true) {
							tmp = 1;
307
						} else if (nodeChecked) {
Z
ztree 已提交
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
							tmp = (cNode.check_Child_State === -1 || cNode.check_Child_State === 2) ? 2 : 1;
						} else {
							tmp = (cNode.check_Child_State > 0) ? 1 : 0;
						}
						if (tmp === 1) {
							chkFlag = 1; break;
						} else if (tmp === 2 && chkFlag > -1 && i > 0 && tmp !== chkFlag) {
							chkFlag = 1; break;
						} else if (chkFlag === 2 && tmp > -1 && tmp < 2) {
							chkFlag = 1; break;
						} else if (tmp > -1) {
							chkFlag = tmp;
						}
					}
				}
			}
			node.check_Child_State = chkFlag;
		}
	},
	//method of event proxy
	_event = {

	},
	//method of event handler
	_handler = {
		onCheckNode: function (event, node) {
			if (node.chkDisabled === true) return false;
335
			var setting = data.getSetting(event.data.treeId);
Z
ztree 已提交
336
			if (tools.apply(setting.callback.beforeCheck, [setting.treeId, node], true) == false) return true;
337 338
      var nodeChecked = data.nodeChecked(setting, node);
      data.nodeChecked(setting, node, !nodeChecked);
Z
ztree 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
			view.checkNodeRelation(setting, node);
			var checkObj = $$(node, consts.id.CHECK, setting);
			view.setChkClass(setting, checkObj, node);
			view.repairParentChkClassWithSelf(setting, node);
			setting.treeObj.trigger(consts.event.CHECK, [event, setting.treeId, node]);
			return true;
		},
		onMouseoverCheck: function(event, node) {
			if (node.chkDisabled === true) return false;
			var setting = data.getSetting(event.data.treeId),
			checkObj = $$(node, consts.id.CHECK, setting);
			node.check_Focus = true;
			view.setChkClass(setting, checkObj, node);
			return true;
		},
		onMouseoutCheck: function(event, node) {
			if (node.chkDisabled === true) return false;
			var setting = data.getSetting(event.data.treeId),
			checkObj = $$(node, consts.id.CHECK, setting);
			node.check_Focus = false;
			view.setChkClass(setting, checkObj, node);
			return true;
		}
	},
	//method of tools for zTree
	_tools = {

	},
	//method of operate ztree dom
	_view = {
		checkNodeRelation: function(setting, node) {
			var pNode, i, l,
			r = consts.radio;
372
      var nodeChecked = data.nodeChecked(setting, node);
Z
ztree 已提交
373 374
			if (setting.check.chkStyle == r.STYLE) {
				var checkedList = data.getRadioCheckedList(setting);
375
				if (nodeChecked) {
Z
ztree 已提交
376 377 378
					if (setting.check.radioType == r.TYPE_ALL) {
						for (i = checkedList.length-1; i >= 0; i--) {
							pNode = checkedList[i];
379 380 381
              var pNodeChecked = data.nodeChecked(setting, pNode);
							if (pNodeChecked && pNode != node) {
                data.nodeChecked(setting, pNode, false);
382
								checkedList.splice(i, 1);
Z
ztree 已提交
383

384 385 386 387
								view.setChkClass(setting, $$(pNode, consts.id.CHECK, setting), pNode);
								if (pNode.parentTId != node.parentTId) {
									view.repairParentChkClassWithSelf(setting, pNode);
								}
Z
ztree 已提交
388 389 390 391 392
							}
						}
						checkedList.push(node);
					} else {
						var parentNode = (node.parentTId) ? node.getParentNode() : data.getRoot(setting);
393 394 395 396 397 398
            var children = data.nodeChildren(setting, parentNode);
						for (i = 0, l = children.length; i < l; i++) {
							pNode = children[i];
              var pNodeChecked = data.nodeChecked(setting, pNode);
							if (pNodeChecked && pNode != node) {
								data.nodeChecked(setting, pNode, false);
Z
ztree 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411 412
								view.setChkClass(setting, $$(pNode, consts.id.CHECK, setting), pNode);
							}
						}
					}
				} else if (setting.check.radioType == r.TYPE_ALL) {
					for (i = 0, l = checkedList.length; i < l; i++) {
						if (node == checkedList[i]) {
							checkedList.splice(i, 1);
							break;
						}
					}
				}

			} else {
413 414
        var children = data.nodeChildren(setting, node);
				if (nodeChecked && (!children || children.length==0 || setting.check.chkboxType.Y.indexOf("s") > -1)) {
Z
ztree 已提交
415 416
					view.setSonNodeCheckBox(setting, node, true);
				}
417
				if (!nodeChecked && (!children || children.length==0 || setting.check.chkboxType.N.indexOf("s") > -1)) {
Z
ztree 已提交
418 419
					view.setSonNodeCheckBox(setting, node, false);
				}
420
				if (nodeChecked && setting.check.chkboxType.Y.indexOf("p") > -1) {
Z
ztree 已提交
421 422
					view.setParentNodeCheckBox(setting, node, true);
				}
423
				if (!nodeChecked && setting.check.chkboxType.N.indexOf("p") > -1) {
Z
ztree 已提交
424 425 426 427 428
					view.setParentNodeCheckBox(setting, node, false);
				}
			}
		},
		makeChkClass: function(setting, node) {
429
			var c = consts.checkbox, r = consts.radio,
Z
ztree 已提交
430
			fullStyle = "";
431
      var nodeChecked = data.nodeChecked(setting, node);
Z
ztree 已提交
432 433 434 435 436 437 438
			if (node.chkDisabled === true) {
				fullStyle = c.DISABLED;
			} else if (node.halfCheck) {
				fullStyle = c.PART;
			} else if (setting.check.chkStyle == r.STYLE) {
				fullStyle = (node.check_Child_State < 1)? c.FULL:c.PART;
			} else {
439
				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);
Z
ztree 已提交
440
			}
441
			var chkName = setting.check.chkStyle + "_" + (nodeChecked ? c.TRUE : c.FALSE) + "_" + fullStyle;
Z
ztree 已提交
442 443 444 445 446
			chkName = (node.check_Focus && node.chkDisabled !== true) ? chkName + "_" + c.FOCUS : chkName;
			return consts.className.BUTTON + " " + c.DEFAULT + " " + chkName;
		},
		repairAllChk: function(setting, checked) {
			if (setting.check.enable && setting.check.chkStyle === consts.checkbox.STYLE) {
447 448 449 450
				var root = data.getRoot(setting);
				var children = data.nodeChildren(setting, root);
				for (var i = 0, l = children.length; i<l ; i++) {
					var node = children[i];
Z
ztree 已提交
451
					if (node.nocheck !== true && node.chkDisabled !== true) {
452
            data.nodeChecked(setting, node, checked);
Z
ztree 已提交
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
					}
					view.setSonNodeCheckBox(setting, node, checked);
				}
			}
		},
		repairChkClass: function(setting, node) {
			if (!node) return;
			data.makeChkFlag(setting, node);
			if (node.nocheck !== true) {
				var checkObj = $$(node, consts.id.CHECK, setting);
				view.setChkClass(setting, checkObj, node);
			}
		},
		repairParentChkClass: function(setting, node) {
			if (!node || !node.parentTId) return;
			var pNode = node.getParentNode();
			view.repairChkClass(setting, pNode);
			view.repairParentChkClass(setting, pNode);
		},
		repairParentChkClassWithSelf: function(setting, node) {
			if (!node) return;
474 475 476
      var children = data.nodeChildren(setting, node);
			if (children && children.length > 0) {
				view.repairParentChkClass(setting, children[0]);
Z
ztree 已提交
477 478 479 480 481 482
			} else {
				view.repairParentChkClass(setting, node);
			}
		},
		repairSonChkDisabled: function(setting, node, chkDisabled, inherit) {
			if (!node) return;
483
      if (node.chkDisabled != chkDisabled) {
Z
ztree 已提交
484 485 486
				node.chkDisabled = chkDisabled;
			}
			view.repairChkClass(setting, node);
487 488 489 490
      var children = data.nodeChildren(setting, node);
      if (children && inherit) {
				for (var i = 0, l = children.length; i < l; i++) {
					var sNode = children[i];
Z
ztree 已提交
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
					view.repairSonChkDisabled(setting, sNode, chkDisabled, inherit);
				}
			}
		},
		repairParentChkDisabled: function(setting, node, chkDisabled, inherit) {
			if (!node) return;
			if (node.chkDisabled != chkDisabled && inherit) {
				node.chkDisabled = chkDisabled;
			}
			view.repairChkClass(setting, node);
			view.repairParentChkDisabled(setting, node.getParentNode(), chkDisabled, inherit);
		},
		setChkClass: function(setting, obj, node) {
			if (!obj) return;
			if (node.nocheck === true) {
				obj.hide();
			} else {
				obj.show();
			}
510
            obj.attr('class', view.makeChkClass(setting, node));
Z
ztree 已提交
511 512
		},
		setParentNodeCheckBox: function(setting, node, value, srcNode) {
513
			var checkObj = $$(node, consts.id.CHECK, setting);
Z
ztree 已提交
514 515 516
			if (!srcNode) srcNode = node;
			data.makeChkFlag(setting, node);
			if (node.nocheck !== true && node.chkDisabled !== true) {
517
        data.nodeChecked(setting, node, value);
Z
ztree 已提交
518 519 520 521 522 523 524 525
				view.setChkClass(setting, checkObj, node);
				if (setting.check.autoCheckTrigger && node != srcNode) {
					setting.treeObj.trigger(consts.event.CHECK, [null, setting.treeId, node]);
				}
			}
			if (node.parentTId) {
				var pSign = true;
				if (!value) {
526
          var pNodes = data.nodeChildren(setting, node.getParentNode());
Z
ztree 已提交
527
					for (var i = 0, l = pNodes.length; i < l; i++) {
528 529 530 531
					  var pNode = pNodes[i];
            var nodeChecked = data.nodeChecked(setting, pNode);
						if ((pNode.nocheck !== true && pNode.chkDisabled !== true && nodeChecked)
						|| ((pNode.nocheck === true || pNode.chkDisabled === true) && pNode.check_Child_State > 0)) {
Z
ztree 已提交
532 533 534 535 536 537 538 539 540 541 542 543
							pSign = false;
							break;
						}
					}
				}
				if (pSign) {
					view.setParentNodeCheckBox(setting, node.getParentNode(), value, srcNode);
				}
			}
		},
		setSonNodeCheckBox: function(setting, node, value, srcNode) {
			if (!node) return;
544
			var checkObj = $$(node, consts.id.CHECK, setting);
Z
ztree 已提交
545 546 547
			if (!srcNode) srcNode = node;

			var hasDisable = false;
548 549 550 551
      var children = data.nodeChildren(setting, node);
			if (children) {
				for (var i = 0, l = children.length; i < l; i++) {
					var sNode = children[i];
Z
ztree 已提交
552 553 554 555 556 557 558 559 560 561
					view.setSonNodeCheckBox(setting, sNode, value, srcNode);
					if (sNode.chkDisabled === true) hasDisable = true;
				}
			}

			if (node != data.getRoot(setting) && node.chkDisabled !== true) {
				if (hasDisable && node.nocheck !== true) {
					data.makeChkFlag(setting, node);
				}
				if (node.nocheck !== true && node.chkDisabled !== true) {
562 563
          data.nodeChecked(setting, node, value);
					if (!hasDisable) node.check_Child_State = (children && children.length > 0) ? (value ? 2 : 0) : -1;
Z
ztree 已提交
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
				} else {
					node.check_Child_State = -1;
				}
				view.setChkClass(setting, checkObj, node);
				if (setting.check.autoCheckTrigger && node != srcNode && node.nocheck !== true && node.chkDisabled !== true) {
					setting.treeObj.trigger(consts.event.CHECK, [null, setting.treeId, node]);
				}
			}

		}
	},

	_z = {
		tools: _tools,
		view: _view,
		event: _event,
		data: _data
	};
	$.extend(true, $.fn.zTree.consts, _consts);
	$.extend(true, $.fn.zTree._z, _z);

	var zt = $.fn.zTree,
	tools = zt._z.tools,
	consts = zt.consts,
	view = zt._z.view,
	data = zt._z.data,
	event = zt._z.event,
	$$ = tools.$;

593 594 595 596 597 598 599
	data.nodeChecked = function(setting, node, newChecked) {
    if (!node) {
      return false;
    }
    var key = setting.data.key.checked;
    if (typeof newChecked !== 'undefined') {
      if (typeof newChecked === "string") {
600
        newChecked = tools.eqs(newChecked, "true");
601 602 603 604 605 606 607
      }
      newChecked = !!newChecked;
      node[key] = newChecked;
    }
    return node[key];
  };

Z
ztree 已提交
608 609 610 611 612 613 614 615 616 617 618
	data.exSetting(_setting);
	data.addInitBind(_bindEvent);
	data.addInitUnBind(_unbindEvent);
	data.addInitCache(_initCache);
	data.addInitNode(_initNode);
	data.addInitProxy(_eventProxy, true);
	data.addInitRoot(_initRoot);
	data.addBeforeA(_beforeA);
	data.addZTreeTools(_zTreeTools);

	var _createNodes = view.createNodes;
619
	view.createNodes = function(setting, level, nodes, parentNode, index) {
Z
ztree 已提交
620 621 622 623 624 625 626 627 628 629 630 631 632 633
		if (_createNodes) _createNodes.apply(view, arguments);
		if (!nodes) return;
		view.repairParentChkClassWithSelf(setting, parentNode);
	}
	var _removeNode = view.removeNode;
	view.removeNode = function(setting, node) {
		var parentNode = node.getParentNode();
		if (_removeNode) _removeNode.apply(view, arguments);
		if (!node || !parentNode) return;
		view.repairChkClass(setting, parentNode);
		view.repairParentChkClass(setting, parentNode);
	}

	var _appendNodes = view.appendNodes;
634
	view.appendNodes = function(setting, level, nodes, parentNode, index, initFlag, openFlag) {
Z
ztree 已提交
635 636 637 638 639 640 641 642 643 644
		var html = "";
		if (_appendNodes) {
			html = _appendNodes.apply(view, arguments);
		}
		if (parentNode) {
			data.makeChkFlag(setting, parentNode);
		}
		return html;
	}
})(jQuery);