123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- /*
- * JQuery zTree exHideNodes
- * v3.5.42
- * http://treejs.cn/
- *
- * Copyright (c) 2010 Hunter.z
- *
- * Licensed same as jquery - MIT License
- * http://www.opensource.org/licenses/mit-license.php
- *
- * Date: 2020-01-19
- */
- (function ($) {
- var _setting = {
- data: {
- key: {
- isHidden: "isHidden"
- }
- }
- };
- //default init node of exLib
- var _initNode = function (setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
- var isHidden = data.isHidden(setting, n);
- data.isHidden(setting, n, isHidden);
- data.initHideForExCheck(setting, n);
- },
- //add dom for check
- _beforeA = function (setting, node, html) {
- },
- //update zTreeObj, add method of exLib
- _zTreeTools = function (setting, zTreeTools) {
- zTreeTools.showNodes = function (nodes, options) {
- view.showNodes(setting, nodes, options);
- }
- zTreeTools.showNode = function (node, options) {
- if (!node) {
- return;
- }
- view.showNodes(setting, [node], options);
- }
- zTreeTools.hideNodes = function (nodes, options) {
- view.hideNodes(setting, nodes, options);
- }
- zTreeTools.hideNode = function (node, options) {
- if (!node) {
- return;
- }
- view.hideNodes(setting, [node], options);
- }
- var _checkNode = zTreeTools.checkNode;
- if (_checkNode) {
- zTreeTools.checkNode = function (node, checked, checkTypeFlag, callbackFlag) {
- if (!!node && !!data.isHidden(setting, node)) {
- return;
- }
- _checkNode.apply(zTreeTools, arguments);
- }
- }
- },
- //method of operate data
- _data = {
- initHideForExCheck: function (setting, n) {
- var isHidden = data.isHidden(setting, n);
- if (isHidden && setting.check && setting.check.enable) {
- if (typeof n._nocheck == "undefined") {
- n._nocheck = !!n.nocheck
- n.nocheck = true;
- }
- n.check_Child_State = -1;
- if (view.repairParentChkClassWithSelf) {
- view.repairParentChkClassWithSelf(setting, n);
- }
- }
- },
- initShowForExCheck: function (setting, n) {
- var isHidden = data.isHidden(setting, n);
- if (!isHidden && setting.check && setting.check.enable) {
- if (typeof n._nocheck != "undefined") {
- n.nocheck = n._nocheck;
- delete n._nocheck;
- }
- if (view.setChkClass) {
- var checkObj = $$(n, consts.id.CHECK, setting);
- view.setChkClass(setting, checkObj, n);
- }
- if (view.repairParentChkClassWithSelf) {
- view.repairParentChkClassWithSelf(setting, n);
- }
- }
- }
- },
- //method of operate ztree dom
- _view = {
- clearOldFirstNode: function (setting, node) {
- var n = node.getNextNode();
- while (!!n) {
- if (n.isFirstNode) {
- n.isFirstNode = false;
- view.setNodeLineIcos(setting, n);
- break;
- }
- if (n.isLastNode) {
- break;
- }
- n = n.getNextNode();
- }
- },
- clearOldLastNode: function (setting, node, openFlag) {
- var n = node.getPreNode();
- while (!!n) {
- if (n.isLastNode) {
- n.isLastNode = false;
- if (openFlag) {
- view.setNodeLineIcos(setting, n);
- }
- break;
- }
- if (n.isFirstNode) {
- break;
- }
- n = n.getPreNode();
- }
- },
- makeDOMNodeMainBefore: function (html, setting, node) {
- var isHidden = data.isHidden(setting, node);
- html.push("<li ", (isHidden ? "style='display:none;' " : ""), "id='", node.tId, "' class='", consts.className.LEVEL, node.level, "' tabindex='0' hidefocus='true' treenode>");
- },
- showNode: function (setting, node, options) {
- data.isHidden(setting, node, false);
- data.initShowForExCheck(setting, node);
- $$(node, setting).show();
- },
- showNodes: function (setting, nodes, options) {
- if (!nodes || nodes.length == 0) {
- return;
- }
- var pList = {}, i, j;
- for (i = 0, j = nodes.length; i < j; i++) {
- var n = nodes[i];
- if (!pList[n.parentTId]) {
- var pn = n.getParentNode();
- pList[n.parentTId] = (pn === null) ? data.getRoot(setting) : n.getParentNode();
- }
- view.showNode(setting, n, options);
- }
- for (var tId in pList) {
- var children = data.nodeChildren(setting, pList[tId]);
- view.setFirstNodeForShow(setting, children);
- view.setLastNodeForShow(setting, children);
- }
- },
- hideNode: function (setting, node, options) {
- data.isHidden(setting, node, true);
- node.isFirstNode = false;
- node.isLastNode = false;
- data.initHideForExCheck(setting, node);
- view.cancelPreSelectedNode(setting, node);
- $$(node, setting).hide();
- },
- hideNodes: function (setting, nodes, options) {
- if (!nodes || nodes.length == 0) {
- return;
- }
- var pList = {}, i, j;
- for (i = 0, j = nodes.length; i < j; i++) {
- var n = nodes[i];
- if ((n.isFirstNode || n.isLastNode) && !pList[n.parentTId]) {
- var pn = n.getParentNode();
- pList[n.parentTId] = (pn === null) ? data.getRoot(setting) : n.getParentNode();
- }
- view.hideNode(setting, n, options);
- }
- for (var tId in pList) {
- var children = data.nodeChildren(setting, pList[tId]);
- view.setFirstNodeForHide(setting, children);
- view.setLastNodeForHide(setting, children);
- }
- },
- setFirstNode: function (setting, parentNode) {
- var children = data.nodeChildren(setting, parentNode);
- var isHidden = data.isHidden(setting, children[0], false);
- if (children.length > 0 && !isHidden) {
- children[0].isFirstNode = true;
- } else if (children.length > 0) {
- view.setFirstNodeForHide(setting, children);
- }
- },
- setLastNode: function (setting, parentNode) {
- var children = data.nodeChildren(setting, parentNode);
- var isHidden = data.isHidden(setting, children[0]);
- if (children.length > 0 && !isHidden) {
- children[children.length - 1].isLastNode = true;
- } else if (children.length > 0) {
- view.setLastNodeForHide(setting, children);
- }
- },
- setFirstNodeForHide: function (setting, nodes) {
- var n, i, j;
- for (i = 0, j = nodes.length; i < j; i++) {
- n = nodes[i];
- if (n.isFirstNode) {
- break;
- }
- var isHidden = data.isHidden(setting, n);
- if (!isHidden && !n.isFirstNode) {
- n.isFirstNode = true;
- view.setNodeLineIcos(setting, n);
- break;
- } else {
- n = null;
- }
- }
- return n;
- },
- setFirstNodeForShow: function (setting, nodes) {
- var n, i, j, first, old;
- for (i = 0, j = nodes.length; i < j; i++) {
- n = nodes[i];
- var isHidden = data.isHidden(setting, n);
- if (!first && !isHidden && n.isFirstNode) {
- first = n;
- break;
- } else if (!first && !isHidden && !n.isFirstNode) {
- n.isFirstNode = true;
- first = n;
- view.setNodeLineIcos(setting, n);
- } else if (first && n.isFirstNode) {
- n.isFirstNode = false;
- old = n;
- view.setNodeLineIcos(setting, n);
- break;
- } else {
- n = null;
- }
- }
- return {"new": first, "old": old};
- },
- setLastNodeForHide: function (setting, nodes) {
- var n, i;
- for (i = nodes.length - 1; i >= 0; i--) {
- n = nodes[i];
- if (n.isLastNode) {
- break;
- }
- var isHidden = data.isHidden(setting, n);
- if (!isHidden && !n.isLastNode) {
- n.isLastNode = true;
- view.setNodeLineIcos(setting, n);
- break;
- } else {
- n = null;
- }
- }
- return n;
- },
- setLastNodeForShow: function (setting, nodes) {
- var n, i, j, last, old;
- for (i = nodes.length - 1; i >= 0; i--) {
- n = nodes[i];
- var isHidden = data.isHidden(setting, n);
- if (!last && !isHidden && n.isLastNode) {
- last = n;
- break;
- } else if (!last && !isHidden && !n.isLastNode) {
- n.isLastNode = true;
- last = n;
- view.setNodeLineIcos(setting, n);
- } else if (last && n.isLastNode) {
- n.isLastNode = false;
- old = n;
- view.setNodeLineIcos(setting, n);
- break;
- } else {
- n = null;
- }
- }
- return {"new": last, "old": old};
- }
- },
- _z = {
- view: _view,
- data: _data
- };
- $.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.$;
- data.isHidden = function (setting, node, newIsHidden) {
- if (!node) {
- return false;
- }
- var key = setting.data.key.isHidden;
- if (typeof newIsHidden !== 'undefined') {
- if (typeof newIsHidden === "string") {
- newIsHidden = tools.eqs(newIsHidden, "true");
- }
- newIsHidden = !!newIsHidden;
- node[key] = newIsHidden;
- } else if (typeof node[key] == "string"){
- node[key] = tools.eqs(node[key], "true");
- } else {
- node[key] = !!node[key];
- }
- return node[key];
- };
- data.exSetting(_setting);
- data.addInitNode(_initNode);
- data.addBeforeA(_beforeA);
- data.addZTreeTools(_zTreeTools);
- // Override method in core
- var _dInitNode = data.initNode;
- data.initNode = function (setting, level, node, parentNode, isFirstNode, isLastNode, openFlag) {
- var tmpPNode = (parentNode) ? parentNode : data.getRoot(setting),
- children = tmpPNode[setting.data.key.children];
- data.tmpHideFirstNode = view.setFirstNodeForHide(setting, children);
- data.tmpHideLastNode = view.setLastNodeForHide(setting, children);
- if (openFlag) {
- view.setNodeLineIcos(setting, data.tmpHideFirstNode);
- view.setNodeLineIcos(setting, data.tmpHideLastNode);
- }
- isFirstNode = (data.tmpHideFirstNode === node);
- isLastNode = (data.tmpHideLastNode === node);
- if (_dInitNode) _dInitNode.apply(data, arguments);
- if (openFlag && isLastNode) {
- view.clearOldLastNode(setting, node, openFlag);
- }
- };
- var _makeChkFlag = data.makeChkFlag;
- if (!!_makeChkFlag) {
- data.makeChkFlag = function (setting, node) {
- if (!!node && !!data.isHidden(setting, node)) {
- return;
- }
- _makeChkFlag.apply(data, arguments);
- }
- }
- var _getTreeCheckedNodes = data.getTreeCheckedNodes;
- if (!!_getTreeCheckedNodes) {
- data.getTreeCheckedNodes = function (setting, nodes, checked, results) {
- if (!!nodes && nodes.length > 0) {
- var p = nodes[0].getParentNode();
- if (!!p && !!data.isHidden(setting, p)) {
- return [];
- }
- }
- return _getTreeCheckedNodes.apply(data, arguments);
- }
- }
- var _getTreeChangeCheckedNodes = data.getTreeChangeCheckedNodes;
- if (!!_getTreeChangeCheckedNodes) {
- data.getTreeChangeCheckedNodes = function (setting, nodes, results) {
- if (!!nodes && nodes.length > 0) {
- var p = nodes[0].getParentNode();
- if (!!p && !!data.isHidden(setting, p)) {
- return [];
- }
- }
- return _getTreeChangeCheckedNodes.apply(data, arguments);
- }
- }
- var _expandCollapseSonNode = view.expandCollapseSonNode;
- if (!!_expandCollapseSonNode) {
- view.expandCollapseSonNode = function (setting, node, expandFlag, animateFlag, callback) {
- if (!!node && !!data.isHidden(setting, node)) {
- return;
- }
- _expandCollapseSonNode.apply(view, arguments);
- }
- }
- var _setSonNodeCheckBox = view.setSonNodeCheckBox;
- if (!!_setSonNodeCheckBox) {
- view.setSonNodeCheckBox = function (setting, node, value, srcNode) {
- if (!!node && !!data.isHidden(setting, node)) {
- return;
- }
- _setSonNodeCheckBox.apply(view, arguments);
- }
- }
- var _repairParentChkClassWithSelf = view.repairParentChkClassWithSelf;
- if (!!_repairParentChkClassWithSelf) {
- view.repairParentChkClassWithSelf = function (setting, node) {
- if (!!node && !!data.isHidden(setting, node)) {
- return;
- }
- _repairParentChkClassWithSelf.apply(view, arguments);
- }
- }
- })(jQuery);
|