⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treeview.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
        if (node.expanded) {            // wait until the animation is complete before deleting to            // avoid javascript errors            if (this._collapseAnim) {                this.subscribe("animComplete",                         this._removeChildren_animComplete, this, true);                Widget.Node.prototype.collapse.call(node);                return;            }            node.collapse();        }        while (node.children.length) {            this._deleteNode(node.children[0]);        }        if (node.isRoot()) {            Widget.Node.prototype.expand.call(node);        }        node.childrenRendered = false;        node.dynamicLoadComplete = false;        node.updateIcon();    },    /**     * Deletes the node and recurses children     * @method _deleteNode     * @private     */    _deleteNode: function(node) {         // Remove all the child nodes first        this.removeChildren(node);        // Remove the node from the tree        this.popNode(node);    },    /**     * Removes the node from the tree, preserving the child collection      * to make it possible to insert the branch into another part of the      * tree, or another tree.     * @method popNode     * @param {Node} the node to remove     */    popNode: function(node) {         var p = node.parent;        // Update the parent's collection of children        var a = [];        for (var i=0, len=p.children.length;i<len;++i) {            if (p.children[i] != node) {                a[a.length] = p.children[i];            }        }        p.children = a;        // reset the childrenRendered flag for the parent        p.childrenRendered = false;         // Update the sibling relationship        if (node.previousSibling) {            node.previousSibling.nextSibling = node.nextSibling;        }        if (node.nextSibling) {            node.nextSibling.previousSibling = node.previousSibling;        }        node.parent = null;        node.previousSibling = null;        node.nextSibling = null;        node.tree = null;        // Update the tree's node collection         delete this._nodes[node.index];    },	/**	* Nulls out the entire TreeView instance and related objects, removes attached	* event listeners, and clears out DOM elements inside the container. After	* calling this method, the instance reference should be expliclitly nulled by	* implementer, as in myDataTable = null. Use with caution!	*	* @method destroy	*/	destroy : function() {		// Since the label editor can be separated from the main TreeView control		// the destroy method for it might not be there.		if (this._destroyEditor) { this._destroyEditor(); }		var el = this.getEl();		Event.removeListener(el,'click');		Event.removeListener(el,'dblclick');		Event.removeListener(el,'mouseover');		Event.removeListener(el,'mouseout');		Event.removeListener(el,'keydown');		for (var i = 0 ; i < this._nodes.length; i++) {			var node = this._nodes[i];			if (node && node.destroy) {node.destroy(); }		}		el.parentNode.removeChild(el);		this._hasEvents = false;	},					    /**     * TreeView instance toString     * @method toString     * @return {string} string representation of the tree     */    toString: function() {        return "TreeView " + this.id;    },    /**     * Count of nodes in tree     * @method getNodeCount     * @return {int} number of nodes in the tree     */    getNodeCount: function() {        return this.getRoot().getNodeCount();    },    /**     * Returns an object which could be used to rebuild the tree.     * It can be passed to the tree constructor to reproduce the same tree.     * It will return false if any node loads dynamically, regardless of whether it is loaded or not.     * @method getTreeDefinition     * @return {Object | false}  definition of the tree or false if any node is defined as dynamic     */    getTreeDefinition: function() {        return this.getRoot().getNodeDefinition();    },    /**     * Abstract method that is executed when a node is expanded     * @method onExpand     * @param node {Node} the node that was expanded     * @deprecated use treeobj.subscribe("expand") instead     */    onExpand: function(node) { },    /**     * Abstract method that is executed when a node is collapsed.     * @method onCollapse     * @param node {Node} the node that was collapsed.     * @deprecated use treeobj.subscribe("collapse") instead     */    onCollapse: function(node) { }};/* Backwards compatibility aliases */var PROT = TV.prototype; /**     * Renders the tree boilerplate and visible nodes.     *  Alias for render     * @method draw     * @deprecated Use render instead     */PROT.draw = PROT.render;/* end backwards compatibility aliases */YAHOO.augment(TV, YAHOO.util.EventProvider);/** * Running count of all nodes created in all trees.  This is  * used to provide unique identifies for all nodes.  Deleting * nodes does not change the nodeCount. * @property YAHOO.widget.TreeView.nodeCount * @type int * @static */TV.nodeCount = 0;/** * Global cache of tree instances * @property YAHOO.widget.TreeView.trees * @type Array * @static * @private */TV.trees = [];/** * Global method for getting a tree by its id.  Used in the generated * tree html. * @method YAHOO.widget.TreeView.getTree * @param treeId {String} the id of the tree instance * @return {TreeView} the tree instance requested, null if not found. * @static */TV.getTree = function(treeId) {    var t = TV.trees[treeId];    return (t) ? t : null;};/** * Global method for getting a node by its id.  Used in the generated * tree html. * @method YAHOO.widget.TreeView.getNode * @param treeId {String} the id of the tree instance * @param nodeIndex {String} the index of the node to return * @return {Node} the node instance requested, null if not found * @static */TV.getNode = function(treeId, nodeIndex) {    var t = TV.getTree(treeId);    return (t) ? t.getNodeByIndex(nodeIndex) : null;};/**     * Class name assigned to elements that have the focus     *     * @property TreeView.FOCUS_CLASS_NAME     * @type String     * @static     * @final     * @default "ygtvfocus"	*/ TV.FOCUS_CLASS_NAME = 'ygtvfocus';/** * Attempts to preload the images defined in the styles used to draw the tree by * rendering off-screen elements that use the styles. * @method YAHOO.widget.TreeView.preload * @param {string} prefix the prefix to use to generate the names of the * images to preload, default is ygtv * @static */TV.preload = function(e, prefix) {    prefix = prefix || "ygtv";    var styles = ["tn","tm","tmh","tp","tph","ln","lm","lmh","lp","lph","loading"];    // var styles = ["tp"];    var sb = [];        // save the first one for the outer container    for (var i=1; i < styles.length; i=i+1) {         sb[sb.length] = '<span class="' + prefix + styles[i] + '">&#160;</span>';    }    var f = document.createElement("div");    var s = f.style;    s.className = prefix + styles[0];    s.position = "absolute";    s.height = "1px";    s.width = "1px";    s.top = "-1000px";    s.left = "-1000px";    f.innerHTML = sb.join("");    document.body.appendChild(f);    Event.removeListener(window, "load", TV.preload);};Event.addListener(window,"load", TV.preload);})();(function () {	var Dom = YAHOO.util.Dom,		Lang = YAHOO.lang,		Event = YAHOO.util.Event;/** * The base class for all tree nodes.  The node's presentation and behavior in * response to mouse events is handled in Node subclasses. * @namespace YAHOO.widget * @class Node * @uses YAHOO.util.EventProvider * @param oData {object} a string or object containing the data that will * be used to render this node, and any custom attributes that should be * stored with the node (which is available in noderef.data). * All values in oData will be used to set equally named properties in the node * as long as the node does have such properties, they are not undefined, private or functions. * @param oParent {Node} this node's parent node * @param expanded {boolean} the initial expanded/collapsed state (deprecated, use oData.expanded) * @constructor */YAHOO.widget.Node = function(oData, oParent, expanded) {    if (oData) { this.init(oData, oParent, expanded); }};YAHOO.widget.Node.prototype = {    /**     * The index for this instance obtained from global counter in YAHOO.widget.TreeView.     * @property index     * @type int     */    index: 0,    /**     * This node's child node collection.     * @property children     * @type Node[]      */    children: null,    /**     * Tree instance this node is part of     * @property tree     * @type TreeView     */    tree: null,    /**     * The data linked to this node.  This can be any object or primitive     * value, and the data can be used in getNodeHtml().     * @property data     * @type object     */    data: null,    /**     * Parent node     * @property parent     * @type Node     */    parent: null,    /**     * The depth of this node.  We start at -1 for the root node.     * @property depth     * @type int     */    depth: -1,    /**     * The href for the node's label.  If one is not specified, the href will     * be set so that it toggles the node.     * @property href     * @type string     */    href: null,    /**     * The label href target, defaults to current window     * @property target     * @type string     */    target: "_self",    /**     * The node's expanded/collapsed state     * @property expanded     * @type boolean     */    expanded: false,    /**     * Can multiple children be expanded at once?     * @property multiExpand     * @type boolean     */    multiExpand: true,    /**     * Should we render children for a collapsed node?  It is possible that the     * implementer will want to render the hidden data...  @todo verify that we      * need this, and implement it if we do.     * @property renderHidden     * @type boolean     */    renderHidden: false,    /**     * This flag is set to true when the html is generated for this node's     * children, and set to false when new children are added.     * @property childrenRendered     * @type boolean     */    childrenRendered: false,    /**     * Dynamically loaded nodes only fetch the data the first time they are     * expanded.  This flag is set to true once the data has been fetched.     * @property dynamicLoadComplete     * @type boolean     */    dynamicLoadComplete: false,    /**     * This node's previous sibling     * @property previousSibling     * @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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -