📄 treeview.js
字号:
* @default false */ nowrap: false, /** * If true, the node will alway be rendered as a leaf node. This can be * used to override the presentation when dynamically loading the entire * tree. Setting this to true also disables the dynamic load call for the * node. * @property isLeaf * @type boolean * @default false */ isLeaf: false,/** * The CSS class for the html content container. Defaults to ygtvhtml, but * can be overridden to provide a custom presentation for a specific node. * @property contentStyle * @type string */ contentStyle: "", /** * The generated id that will contain the data passed in by the implementer. * @property contentElId * @type string */ contentElId: null, /** * The node type * @property _type * @private * @type string * @default "Node"*/ _type: "Node", /* spacerPath: "http://us.i1.yimg.com/us.yimg.com/i/space.gif", expandedText: "Expanded", collapsedText: "Collapsed", loadingText: "Loading", */ /** * Initializes this node, gets some of the properties from the parent * @method init * @param oData {object} a string or object containing the data that will * be used to render this node * @param oParent {Node} this node's parent node * @param expanded {boolean} the initial expanded/collapsed state */ init: function(oData, oParent, expanded) { this.data = oData; this.children = []; this.index = YAHOO.widget.TreeView.nodeCount; ++YAHOO.widget.TreeView.nodeCount; this.contentElId = "ygtvcontentel" + this.index; if (Lang.isObject(oData)) { for (var property in oData) { if (property.charAt(0) != '_' && oData.hasOwnProperty(property) && !Lang.isUndefined(this[property]) && !Lang.isFunction(this[property]) ) { this[property] = oData[property]; } } } if (!Lang.isUndefined(expanded) ) { this.expanded = expanded; } /** * The parentChange event is fired when a parent element is applied * to the node. This is useful if you need to apply tree-level * properties to a tree that need to happen if a node is moved from * one tree to another. * * @event parentChange * @type CustomEvent */ this.createEvent("parentChange", this); // oParent should never be null except when we create the root node. if (oParent) { oParent.appendChild(this); } }, /** * Certain properties for the node cannot be set until the parent * is known. This is called after the node is inserted into a tree. * the parent is also applied to this node's children in order to * make it possible to move a branch from one tree to another. * @method applyParent * @param {Node} parentNode this node's parent node * @return {boolean} true if the application was successful */ applyParent: function(parentNode) { if (!parentNode) { return false; } this.tree = parentNode.tree; this.parent = parentNode; this.depth = parentNode.depth + 1; // @todo why was this put here. This causes new nodes added at the // root level to lose the menu behavior. // if (! this.multiExpand) { // this.multiExpand = parentNode.multiExpand; // } this.tree.regNode(this); parentNode.childrenRendered = false; // cascade update existing children for (var i=0, len=this.children.length;i<len;++i) { this.children[i].applyParent(this); } this.fireEvent("parentChange"); return true; }, /** * Appends a node to the child collection. * @method appendChild * @param childNode {Node} the new node * @return {Node} the child node * @private */ appendChild: function(childNode) { if (this.hasChildren()) { var sib = this.children[this.children.length - 1]; sib.nextSibling = childNode; childNode.previousSibling = sib; } this.children[this.children.length] = childNode; childNode.applyParent(this); // part of the IE display issue workaround. If child nodes // are added after the initial render, and the node was // instantiated with expanded = true, we need to show the // children div now that the node has a child. if (this.childrenRendered && this.expanded) { this.getChildrenEl().style.display = ""; } return childNode; }, /** * Appends this node to the supplied node's child collection * @method appendTo * @param parentNode {Node} the node to append to. * @return {Node} The appended node */ appendTo: function(parentNode) { return parentNode.appendChild(this); }, /** * Inserts this node before this supplied node * @method insertBefore * @param node {Node} the node to insert this node before * @return {Node} the inserted node */ insertBefore: function(node) { var p = node.parent; if (p) { if (this.tree) { this.tree.popNode(this); } var refIndex = node.isChildOf(p); p.children.splice(refIndex, 0, this); if (node.previousSibling) { node.previousSibling.nextSibling = this; } this.previousSibling = node.previousSibling; this.nextSibling = node; node.previousSibling = this; this.applyParent(p); } return this; }, /** * Inserts this node after the supplied node * @method insertAfter * @param node {Node} the node to insert after * @return {Node} the inserted node */ insertAfter: function(node) { var p = node.parent; if (p) { if (this.tree) { this.tree.popNode(this); } var refIndex = node.isChildOf(p); if (!node.nextSibling) { this.nextSibling = null; return this.appendTo(p); } p.children.splice(refIndex + 1, 0, this); node.nextSibling.previousSibling = this; this.previousSibling = node; this.nextSibling = node.nextSibling; node.nextSibling = this; this.applyParent(p); } return this; }, /** * Returns true if the Node is a child of supplied Node * @method isChildOf * @param parentNode {Node} the Node to check * @return {boolean} The node index if this Node is a child of * supplied Node, else -1. * @private */ isChildOf: function(parentNode) { if (parentNode && parentNode.children) { for (var i=0, len=parentNode.children.length; i<len ; ++i) { if (parentNode.children[i] === this) { return i; } } } return -1; }, /** * Returns a node array of this node's siblings, null if none. * @method getSiblings * @return Node[] */ getSiblings: function() { var sib = this.parent.children.slice(0); for (var i=0;i < sib.length && sib[i] != this;i++) {} sib.splice(i,1); if (sib.length) { return sib; } return null; }, /** * Shows this node's children * @method showChildren */ showChildren: function() { if (!this.tree.animateExpand(this.getChildrenEl(), this)) { if (this.hasChildren()) { this.getChildrenEl().style.display = ""; } } }, /** * Hides this node's children * @method hideChildren */ hideChildren: function() { if (!this.tree.animateCollapse(this.getChildrenEl(), this)) { this.getChildrenEl().style.display = "none"; } }, /** * Returns the id for this node's container div * @method getElId * @return {string} the element id */ getElId: function() { return "ygtv" + this.index; }, /** * Returns the id for this node's children div * @method getChildrenElId * @return {string} the element id for this node's children div */ getChildrenElId: function() { return "ygtvc" + this.index; }, /** * Returns the id for this node's toggle element * @method getToggleElId * @return {string} the toggel element id */ getToggleElId: function() { return "ygtvt" + this.index; }, /* * Returns the id for this node's spacer image. The spacer is positioned * over the toggle and provides feedback for screen readers. * @method getSpacerId * @return {string} the id for the spacer image */ /* getSpacerId: function() { return "ygtvspacer" + this.index; }, */ /** * Returns this node's container html element * @method getEl * @return {HTMLElement} the container html element */ getEl: function() { return Dom.get(this.getElId()); }, /** * Returns the div that was generated for this node's children * @method getChildrenEl * @return {HTMLElement} this node's children div */ getChildrenEl: function() { return Dom.get(this.getChildrenElId()); }, /** * Returns the element that is being used for this node's toggle. * @method getToggleEl * @return {HTMLElement} this node's toggle html element */ getToggleEl: function() { return Dom.get(this.getToggleElId()); }, /** * Returns the outer html element for this node's content * @method getContentEl * @return {HTMLElement} the element */ getContentEl: function() { return Dom.get(this.contentElId); }, /* * Returns the element that is being used for this node's spacer. * @method getSpacer * @return {HTMLElement} this node's spacer html element */ /* getSpacer: function() { return document.getElementById( this.getSpacerId() ) || {}; }, */ /* getStateText: function() { if (this.isLoading) { return this.loadingText; } else if (this.hasChildren(true)) { if (this.expanded) { return this.expandedText; } else { return this.collapsedText; } } else { return ""; } }, */ /** * Hides this nodes children (creating them if necessary), changes the toggle style. * @method collapse */ collapse: function() { // Only collapse if currently expanded if (!this.expanded) { return; } // fire the collapse event handler var ret = this.tree.onCollapse(this); if (false === ret) { return; } ret = this.tree.fireEvent("collapse", this); if (false === ret) { return; } if (!this.getEl()) { this.expanded = false; } else { // hide the child div this.hideChildren(); this.expanded = false; this.updateIcon(); } // this.getSpacer().title = this.getStateText(); ret = this.tree.fireEvent("collapseComplete", this); }, /** * Shows this nodes children (creating them if necessary), changes the * toggle style, and collapses its siblings if multiExpand is not set. * @method expand */ expand: function(lazySource) { // Only expand if currently collapsed. if (this.expanded && !lazySource) { return; } var ret = true; // When returning from the lazy load handler, expand is called again // in order to render the new children. The "expand" event already // fired before fething the new data, so we need to skip it now. if (!lazySource) { // fire the expand event handler ret = this.tree.onExpand(this); if (false === ret) { return; } ret = this.tree.fireEvent("expand", this); } if (false === ret) { return; } if (!this.getEl()) { this.expanded = true; return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -