?? treeview-debug.js
字號:
* @type boolean * @default false */ nowrap: false, /** * The node type * @property _type * @private */ _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.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; if (!this.href) { this.href = "javascript:" + this.getToggleLink(); } // @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() { return this.parent.children; }, /** * 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 document.getElementById(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 document.getElementById(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 document.getElementById(this.getToggleElId()); }, /* * 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 ""; } }, */ /** * Generates the link that will invoke this node's toggle method * @method getToggleLink * @return {string} the javascript url for toggling this node */ getToggleLink: function() { return "YAHOO.widget.TreeView.getNode(\'" + this.tree.id + "\'," + this.index + ").toggle()"; }, /** * Hides this nodes children (creating them if necessary), changes the * @method collapse * toggle style. */ 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) { this.logger.log("Collapse was stopped by the abstract onCollapse"); return; } ret = this.tree.fireEvent("collapse", this); if (false === ret) { this.logger.log("Collapse was stopped by a custom event handler"); 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() { // Only expand if currently collapsed. if (this.expanded) { return; } // fire the expand event handler var ret = this.tree.onExpand(this); if (false === ret) { this.logger.log("Expand was stopped by the abstract onExpand"); return; } ret = this.tree.fireEvent("expand", this); if (false === ret) { this.logger.log("Expand was stopped by the custom event handler"); return; } if (!this.getEl()) { this.expanded = true; return; } if (! this.childrenRendered) { this.logger.log("children not rendered yet"); this.getChildrenEl().innerHTML = this.renderChildren(); } else { this.logger.log("CHILDREN RENDERED"); } this.expanded = true; this.updateIcon(); // this.getSpacer().title = this.getStateText(); // We do an extra check for children here because the lazy // load feature can expose nodes that have no children. // if (!this.hasChildren()) { if (this.isLoading) { this.expanded = false; return; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -