📄 treeview-debug.js
字号:
* @type Node */ previousSibling: null, /** * This node's next sibling * @property nextSibling * @type Node */ nextSibling: null, /** * We can set the node up to call an external method to get the child * data dynamically. * @property _dynLoad * @type boolean * @private */ _dynLoad: false, /** * Function to execute when we need to get this node's child data. * @property dataLoader * @type function */ dataLoader: null, /** * This is true for dynamically loading nodes while waiting for the * callback to return. * @property isLoading * @type boolean */ isLoading: false, /** * The toggle/branch icon will not show if this is set to false. This * could be useful if the implementer wants to have the child contain * extra info about the parent, rather than an actual node. * @property hasIcon * @type boolean */ hasIcon: true, /** * Used to configure what happens when a dynamic load node is expanded * and we discover that it does not have children. By default, it is * treated as if it still could have children (plus/minus icon). Set * iconMode to have it display like a leaf node instead. * @property iconMode * @type int */ iconMode: 0, /** * Specifies whether or not the content area of the node should be allowed * to wrap. * @property nowrap * @type boolean * @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; } this.logger = new YAHOO.widget.LogWriter(this.toString()); /** * 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) { this.logger.log("insertBefore: " + node); var p = node.parent; if (p) { if (this.tree) { this.tree.popNode(this); } var refIndex = node.isChildOf(p); //this.logger.log(refIndex); 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) { this.logger.log("insertAfter: " + node); var p = node.parent; if (p) { if (this.tree) { this.tree.popNode(this); } var refIndex = node.isChildOf(p); this.logger.log(refIndex); 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() { this.logger.log("hiding " + this.index); 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 ""; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -