📄 tree-node.js
字号:
} else if(this.data.isExpanded){ this.signElement.className = this.signElement.className.replace(/\b(plus|fetching)\b/, "minus"); } else { this.signElement.className = this.signElement.className.replace(/\b(minus|fetching)\b/, "plus"); } }};/** * @private * This method is invoked when icon is clicked */Zapatec.Tree.Node.prototype.onIconClick = function(){ this.fireEvent("iconClick"); if(this.config.tree.config.selectOnIconClick){ if(this.config.tree.config.deselectSelected && this.data.isSelected){ this.deselect(); } else { this.select(); } } if(!this.config.tree.config.expandOnIconClick){ return null; } this.toggle();};/** * @private * This method is invoked when icon is double clicked */Zapatec.Tree.Node.prototype.onIconDblclick = function(){ this.fireEvent("iconDblclick"); if(this.config.tree.config.selectOnIconDblclick){ if(this.config.tree.config.deselectSelected && this.data.isSelected){ this.deselect(); } else { this.select(); } } if(!this.config.tree.config.expandOnIconDblclick){ return null; } this.toggle();};/** * @private * When user right-clicks icon */Zapatec.Tree.Node.prototype.onIconContextMenu = function(){ return !this.config.tree.config.disableContextMenu;}/** * Fires when user clicks icon(actually mouseup). If this is right-click - event will be fired * @param {Object} ev */Zapatec.Tree.Node.prototype.onIconMouseup = function(ev){ if(!ev){ ev = window.event; } if(Zapatec.Tree.Utils.isRightClick(ev)){ this.fireEvent("labelRightClick", ev); Zapatec.Utils.stopEvent(ev); // Safari bug workaround ev.returnValue = true; return false; }}/** * @private * This method is invoked when +/- is clicked */Zapatec.Tree.Node.prototype.onSignClick = function(){ this.fireEvent("signClick"); if(this.config.tree.config.selectOnSignClick){ if(this.config.tree.config.deselectSelected && this.data.isSelected){ this.deselect(); } else { this.select(); } } if(!this.config.tree.config.expandOnSignClick){ return null; } this.toggle();};/** * @private * This method is invoked when +/- sign is double clicked */Zapatec.Tree.Node.prototype.onSignDblclick = function(){ this.fireEvent("signDblclick"); if(this.config.tree.config.selectOnSignDblclick){ if(this.config.tree.config.deselectSelected && this.data.isSelected){ this.deselect(); } else { this.select(); } } if(!this.config.tree.config.expandOnSignDblclick){ return null; } this.toggle();};/** * @private * This method is invoked when label is clicked */Zapatec.Tree.Node.prototype.onLabelClick = function(){ this.fireEvent("labelClick"); if(this.config.tree.config.selectOnLabelClick){ if(this.config.tree.config.deselectSelected && this.data.isSelected){ this.deselect(); } else { this.select(); } } if(this.config.tree.config.editable && this.config.tree.config.editOnClick){ this.config.tree.editInline.show(this.getLinkToLabelElement()); } if(!this.config.tree.config.expandOnLabelClick){ return null; } this.toggle();};/** * @private * This method is invoked when label is double clicked */Zapatec.Tree.Node.prototype.onLabelDblclick = function(){ this.fireEvent("labelDblclick"); if(this.config.tree.config.selectOnLabelDblclick){ if(this.config.tree.config.deselectSelected && this.data.isSelected){ this.deselect(); } else { this.select(); } } if(this.config.tree.config.editable && this.config.tree.config.editOnDblclick){ this.config.tree.editInline.show(this.getLinkToLabelElement()); } if(!this.config.tree.config.expandOnLabelDblclick){ return null; } this.toggle();};/** * @private * When user right-clicks node label */Zapatec.Tree.Node.prototype.onLabelContextMenu = function(){ return !this.config.tree.config.disableContextMenu;}/** * Fires when user clicks label (actually during mouseup). If this is right-click - event will be fired * @param {Object} ev */Zapatec.Tree.Node.prototype.onLabelMouseup = function(ev){ if(!ev){ ev = window.event; } if(Zapatec.Tree.Utils.isRightClick(ev)){ this.fireEvent("labelRightClick", ev); Zapatec.Utils.stopEvent(ev); // Safari bug workaround ev.returnValue = true; return false; }}/** * Select this node */Zapatec.Tree.Node.prototype.select = function(){ if(this.config.isRootNode){ return null; } if(!this.config.tree.config.selectMultiple){ if(this.config.tree.prevSelected){ this.config.tree.prevSelected.deselect(); } } this.data.isSelected = true; this.config.tree.prevSelected = this; if(this.config.tree.config.saveState){ Zapatec.Utils.writeCookie("Zapatec.Tree-" + this.config.tree.config.saveId, this.data.attributes && this.data.attributes.id ? this.data.attributes.id : this.id, null, '/', 7); } if(this.isCreated && this.config.tree.config.highlightSelectedNode){ Zapatec.Utils.addClass(this.labelContainer, "tree-item-selected"); } this.fireEvent("select"); if(this.config.tree.onItemSelect){ this.config.tree.onItemSelect(this.data && this.data.attributes && this.data.attributes.id ? this.data.attributes.id : this.id); }};/** * Deselect this node */Zapatec.Tree.Node.prototype.deselect = function(){ if(this.config.isRootNode || !this.data.isSelected){ return null; } if(this.isCreated){ this.labelContainer.className = this.labelContainer.className.replace(/\btree-item-selected\b/, ""); } this.data.isSelected = false; this.config.tree.prevSelected = null; this.fireEvent("deselect");};/** * Collapse branch at this node. (branches at child nodes won't be collapsed) */Zapatec.Tree.Node.prototype.collapse = function(){ this.data.isExpanded = false; if(!this.isCreated || !this.hasSubtree()){ return null; } this.childrenContainer.style.display = 'none'; if(!this.config.isRootNode){ this.labelContainer.className = this.labelContainer.className.replace(/\btree-item-expanded\b/, ""); this.labelContainer.className += " tree-item-collapsed"; this.putIcons(); } this.fireEvent("collapse");};/** * Collapse whole branch at this node (all child nodes also will be collapsed) */Zapatec.Tree.Node.prototype.collapseBranch = function(){ if(!this.children){ return null; } for(var ii = 0; ii < this.children.length; ii++){ this.children[ii].collapseBranch(); } this.collapse(); this.fireEvent("collapseBranch");};/** * Expand branch at this node. (branches at child nodes won't be expanded) */Zapatec.Tree.Node.prototype.expand = function(){ this.data.isExpanded = true; if(this.config.tree.config.compact){ // we need to collapse all other expanded nodes var parentNodes = []; var parentNode = this; while(parentNode != null && !parentNode.config.isRootNode){ parentNodes.push(parentNode); parentNode = parentNode.config.parentNode; } for(var ii = this.config.tree.allNodes.length - 1; ii >= 0 ; ii--){ var node = this.config.tree.allNodes[ii]; if(node.data && node.data.isExpanded){ var isParent = false; for(var jj = parentNodes.length - 1; jj >= 0 ; jj--){ if(node == parentNodes[jj]){ isParent = true; break; } } if(!isParent){ node.collapse(); } } } } if(!this.isCreated || !this.hasSubtree()){ return null; } if(!this.config.isRootNode){ this.labelContainer.className = this.labelContainer.className.replace(/\btree-item-collapsed\b/, ""); this.labelContainer.className += " tree-item-expanded"; this.putIcons(); } if(this.config.quick || this.children.length == 0){ // If quick mode is choosed or node has no children - then all nodes // (either predefined and loaded) will be displayed simultaneously if(this.config.source){ if(!this.isFetching){ this.loadData(); } } else { this.childrenContainer.style.display = 'block'; this.createChildren(); for(var ii = 0; ii < this.children.length; ii++){ if(!this.children[ii].isCreated){ this.children[ii].afterCreate(); } } } } else { // display predefined childnodes first and load other nodes after that. // If a lot of nodes will be loaded - use quick mode this.childrenContainer.style.display = 'block'; this.createChildren(); for(var ii = 0; ii < this.children.length; ii++){ if(!this.children[ii].isCreated){ this.children[ii].afterCreate(); } } if(this.config.source){ if(!this.isFetching){ this.loadData(); } } } this.fireEvent("expand");};/** * Expand whole branch at this node (all child nodes also will be expanded) */Zapatec.Tree.Node.prototype.expandBranch = function(){ if(!this.children){ return null; } for(var ii = 0; ii < this.children.length; ii++){ this.children[ii].expandBranch(); } this.expand(); this.fireEvent("expandBranch");};/** * Toggle branch at this node. */Zapatec.Tree.Node.prototype.toggle = function(){ this.fireEvent("toggle"); if(this.data.isExpanded){ return this.collapse(); } else { return this.expand(); }};/** * @private * Function to load tree content on tree load from JSON source. * @param objResponse {Object} Server response */Zapatec.Tree.Node.prototype.loadDataJson = function(objResponse){ if(objResponse == null){ return null; } if(objResponse.expandedIcon){ objResponse.expandedIcon = Zapatec.Tree.Utils.addIconClass(objResponse.expandedIcon, "expandedIcon"); } if(objResponse.collapsedIcon){ objResponse.collapsedIcon = Zapatec.Tree.Utils.addIconClass(objResponse.collapsedIcon, "collapsedIcon");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -