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

📄 treeview.js

📁 一个很不错的...ajax树..支持复选框
💻 JS
📖 第 1 页 / 共 5 页
字号:
        return true;    },    /**     * Deletes this nodes child collection, recursively.  Also collapses     * the node, and resets the dynamic load flag.  The primary use for     * this method is to purge a node and allow it to fetch its data     * dynamically again.     * @method removeChildren     * @param {Node} node the node to purge     */    removeChildren: function(node) {         while (node.children.length) {            this._deleteNode(node.children[0]);        }        node.childrenRendered = false;        node.dynamicLoadComplete = false;        if (node.expanded) {            node.collapse();        } else {            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];    },    /**     * TreeView instance toString     * @method toString     * @return {string} string representation of the tree     */    toString: function() {        return "TreeView " + this.id;    },    /**     * Generates an unique id for an element if it doesn't yet have one     * @method generateId     * @private     */    generateId: function(el) {        var id = el.id;        if (!id) {            id = "yui-tv-auto-id-" + YAHOO.widget.TreeView.counter;            ++YAHOO.widget.TreeView.counter;        }        return id;    },    /**     * 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) { }};YAHOO.augment(YAHOO.widget.TreeView, 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 */YAHOO.widget.TreeView.nodeCount = 0;/** * Global cache of tree instances * @property YAHOO.widget.TreeView.trees * @type Array * @static * @private */YAHOO.widget.TreeView.trees = [];/** * Counter for generating a new unique element id * @property YAHOO.widget.TreeView.counter * @static * @private */YAHOO.widget.TreeView.counter = 0;/** * 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 */YAHOO.widget.TreeView.getTree = function(treeId) {    var t = YAHOO.widget.TreeView.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 */YAHOO.widget.TreeView.getNode = function(treeId, nodeIndex) {    var t = YAHOO.widget.TreeView.getTree(treeId);    return (t) ? t.getNodeByIndex(nodeIndex) : null;};/** * Add a DOM event * @method YAHOO.widget.TreeView.addHandler * @param el the elment to bind the handler to * @param {string} sType the type of event handler * @param {function} fn the callback to invoke * @static */YAHOO.widget.TreeView.addHandler = function (el, sType, fn) {    if (el.addEventListener) {        el.addEventListener(sType, fn, false);    } else if (el.attachEvent) {        el.attachEvent("on" + sType, fn);    }};/** * Remove a DOM event * @method YAHOO.widget.TreeView.removeHandler * @param el the elment to bind the handler to * @param {string} sType the type of event handler * @param {function} fn the callback to invoke * @static */YAHOO.widget.TreeView.removeHandler = function (el, sType, fn) {    if (el.removeEventListener) {        el.removeEventListener(sType, fn, false);    } else if (el.detachEvent) {        el.detachEvent("on" + sType, fn);    }};/** * 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 */YAHOO.widget.TreeView.preload = function(prefix) {    prefix = prefix || "ygtv";    var styles = ["tn","tm","tmh","tp","tph","ln","lm","lmh","lp","lph","loading"];    var sb = [];        for (var i = 0; i < styles.length; ++i) {         sb[sb.length] = '<span class="' + prefix + styles[i] + '">&#160;</span>';    }    var f = document.createElement("div");    var s = f.style;    s.position = "absolute";    s.top = "-1000px";    s.left = "-1000px";    f.innerHTML = sb.join("");    document.body.appendChild(f);    YAHOO.widget.TreeView.removeHandler(window,                 "load", YAHOO.widget.TreeView.preload);};YAHOO.widget.TreeView.addHandler(window,                 "load", YAHOO.widget.TreeView.preload);/** * 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 * @param oParent {Node} this node's parent node * @param expanded {boolean} the initial expanded/collapsed state * @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     * @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

⌨️ 快捷键说明

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