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

📄 treeview.js

📁 Serendipity是一个php+mysql的blog程序
💻 JS
📖 第 1 页 / 共 3 页
字号:
     *     * @type YAHOO.widget.Node     */    nextSibling: null,    /**     * We can set the node up to call an external method to get the child     * data dynamically.     *     * @type boolean     * @private     */    _dynLoad: false,    /**     * Function to execute when we need to get this node's child data.     *     * @type function     */    dataLoader: null,    /**     * This is true for dynamically loading nodes while waiting for the     * callback to return.     *     * @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.     *     * @type boolean     */    hasIcon: true,    /**     * Initializes this node, gets some of the properties from the parent     *     * @param oData {object} a string or object containing the data that will     * be used to render this node     * @param oParent {YAHOO.widget.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;        // oParent should never be null except when we create the root node.        if (oParent) {            this.tree			= oParent.tree;            this.parent			= oParent;            this.href			= "javascript:" + this.getToggleLink();            this.depth			= oParent.depth + 1;            this.multiExpand	= oParent.multiExpand;            oParent.appendChild(this);        }    },    /**     * Appends a node to the child collection.     *     * @param node {YAHOO.widget.Node} the new node     * @return {YAHOO.widget.Node} the child node     * @private     */    appendChild: function(node) {        if (this.hasChildren()) {            var sib = this.children[this.children.length - 1];            sib.nextSibling = node;            node.previousSibling = sib;        }        this.tree.regNode(node);        this.children[this.children.length] = node;        return node;    },    /**     * Returns a node array of this node's siblings, null if none.     *     * @return YAHOO.widget.Node[]     */    getSiblings: function() {        return this.parent.children;    },    /**     * Shows this node's children     */    showChildren: function() {        if (!this.tree.animateExpand(this.getChildrenEl())) {            if (this.hasChildren()) {                this.getChildrenEl().style.display = "";            }        }    },    /**     * Hides this node's children     */    hideChildren: function() {        if (!this.tree.animateCollapse(this.getChildrenEl())) {            this.getChildrenEl().style.display = "none";        }    },    /**     * Returns the id for this node's container div     *     * @return {string} the element id     */    getElId: function() {        return "ygtv" + this.index;    },    /**     * Returns the id for this node's children div     *     * @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     *     * @return {string} the toggel element id     */    getToggleElId: function() {        return "ygtvt" + this.index;    },    /**     * Returns this node's container html element     *     * @return {Object} the container html element     */    getEl: function() {        return document.getElementById(this.getElId());    },    /**     * Returns the div that was generated for this node's children     *     * @return {Object} this node's children div     */    getChildrenEl: function() {        return document.getElementById(this.getChildrenElId());    },    /**     * Returns the element that is being used for this node's toggle.     *     * @return {Object} this node's toggel html element     */    getToggleEl: function() {        return document.getElementById(this.getToggleElId());    },    /**     * Generates the link that will invoke this node's toggle method     *     * @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     * toggle style.     */    collapse: function() {        // Only collapse if currently expanded        if (!this.expanded) { return; }        if (!this.getEl()) {            this.expanded = false;            return;        }        // hide the child div        this.hideChildren();        this.expanded = false;        if (this.hasIcon) {            this.getToggleEl().className = this.getStyle();        }        // fire the collapse event handler        this.tree.onCollapse(this);    },    /**     * Shows this nodes children (creating them if necessary), changes the     * toggle style, and collapses its siblings if multiExpand is not set.     */    expand: function() {        // Only expand if currently collapsed.        if (this.expanded) { return; }        if (!this.getEl()) {            this.expanded = true;            return;        }        if (! this.childrenRendered) {            this.getChildrenEl().innerHTML = this.renderChildren();        }        this.expanded = true;        if (this.hasIcon) {            this.getToggleEl().className = this.getStyle();        }        // 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;        }        if (! this.multiExpand) {            var sibs = this.getSiblings();            for (var i=0; i<sibs.length; ++i) {                if (sibs[i] != this && sibs[i].expanded) {                    sibs[i].collapse();                }            }        }        this.showChildren();        // fire the expand event handler        this.tree.onExpand(this);    },    /**     * Returns the css style name for the toggle     *     * @return {string} the css class for this node's toggle     */    getStyle: function() {        if (this.isLoading) {            return "ygtvloading";        } else {            // location top or bottom, middle nodes also get the top style            var loc = (this.nextSibling) ? "t" : "l";            // type p=plus(expand), m=minus(collapase), n=none(no children)            var type = "n";            if (this.hasChildren(true) || this.isDynamic()) {                type = (this.expanded) ? "m" : "p";            }            return "ygtv" + loc + type;        }    },    /**     * Returns the hover style for the icon     * @return {string} the css class hover state     */    getHoverStyle: function() {        var s = this.getStyle();        if (this.hasChildren(true) && !this.isLoading) {            s += "h";        }        return s;    },    /**     * Recursively expands all of this node's children.     */    expandAll: function() {        for (var i=0;i<this.children.length;++i) {            var c = this.children[i];            if (c.isDynamic()) {                alert("Not supported (lazy load + expand all)");                break;            } else if (! c.multiExpand) {                alert("Not supported (no multi-expand + expand all)");                break;            } else {                c.expand();                c.expandAll();            }        }    },    /**     * Recursively collapses all of this node's children.     */    collapseAll: function() {        for (var i=0;i<this.children.length;++i) {            this.children[i].collapse();            this.children[i].collapseAll();        }    },    /**     * Configures this node for dynamically obtaining the child data     * when the node is first expanded.     *     * @param fmDataLoader {function} the function that will be used to get the data.     */    setDynamicLoad: function(fnDataLoader) {        this.dataLoader = fnDataLoader;        this._dynLoad = true;    },    /**     * Evaluates if this node is the root node of the tree     *     * @return {boolean} true if this is the root node     */    isRoot: function() {        return (this == this.tree.root);    },    /**     * Evaluates if this node's children should be loaded dynamically.  Looks for     * the property both in this instance and the root node.  If the tree is     * defined to load all children dynamically, the data callback function is     * defined in the root node     *     * @return {boolean} true if this node's children are to be loaded dynamically     */    isDynamic: function() {        var lazy = (!this.isRoot() && (this._dynLoad || this.tree.root._dynLoad));        return lazy;    },    /**     * Checks if this node has children.  If this node is lazy-loading and the     * children have not been rendered, we do not know whether or not there     * are actual children.  In most cases, we need to assume that there are     * children (for instance, the toggle needs to show the expandable     * presentation state).  In other times we want to know if there are rendered     * children.  For the latter, "checkForLazyLoad" should be false.     *     * @param checkForLazyLoad {boolean} should we check for unloaded children?     * @return {boolean} true if this has children or if it might and we are     * checking for this condition.     */    hasChildren: function(checkForLazyLoad) {        return ( this.children.length > 0 ||                (checkForLazyLoad && this.isDynamic() && !this.childrenRendered) );    },    /**     * Expands if node is collapsed, collapses otherwise.     */    toggle: function() {        if (!this.tree.locked && ( this.hasChildren(true) || this.isDynamic()) ) {            if (this.expanded) { this.collapse(); } else { this.expand(); }        }    },    /**     * Returns the markup for this node and its children.     *     * @return {string} the markup for this node and its expanded children.     */    getHtml: function() {        var sb = [];        sb[sb.length] = '<div class="ygtvitem" id="' + this.getElId() + '">';        sb[sb.length] = this.getNodeHtml();        sb[sb.length] = this.getChildrenHtml();        sb[sb.length] = '</div>';        return sb.join("");    },    /**     * Called when first rendering the tree.  We always build the div that will     * contain this nodes children, but we don't render the children themselves     * unless this node is expanded.     *     * @return {string} the children container div html and any expanded children     * @private     */    getChildrenHtml: function() {        var sb = [];        sb[sb.length] = '<div class="ygtvchildren"';        sb[sb.length] = ' id="' + this.getChildrenElId() + '"';        if (!this.expanded) {            sb[sb.length] = ' style="display:none;"';        }        sb[sb.length] = '>';        // Don't render the actual child node HTML unless this node is expanded.        if (this.hasChildren(true) && this.expanded) {            sb[sb.length] = this.renderChildren();        }        sb[sb.length] = '</div>';        return sb.join("");    },    /**     * Generates the markup for the child nodes.  This is not done until the node     * is expanded.     *     * @return {string} the html for this node's children     * @private     */    renderChildren: function() {        var node = this;        if (this.isDynamic() && !this.childrenRendered) {            this.isLoading = true;            this.tree.locked = true;            if (this.dataLoader) {                setTimeout(                    function() {                        node.dataLoader(node,                            function() {                                node.loadComplete();                            });                    }, 10);            } else if (this.tree.root.dataLoader) {                setTimeout(                    function() {                        node.tree.root.dataLoader(node,                            function() {                                node.loadComplete();                            });                    }, 10);            } else {                return "Error: data loader not found or not specified.";            }            return "";        } else {            return this.completeRender();        }    },    /**     * Called when we know we have all the child data.     * @return {string} children html     */    completeRender: function() {        var sb = [];        for (var i=0; i < this.children.length; ++i) {            sb[sb.length] = this.children[i].getHtml();        }        this.childrenRendered = true;        return sb.join("");    },    /**     * Load complete is the callback function we pass to the data provider     * in dynamic load situations.     */    loadComplete: function() {        this.getChildrenEl().innerHTML = this.completeRender();        this.isLoading = false;        this.expand();        this.tree.locked = false;    },    /**     * Returns this node's ancestor at the specified depth.     *     * @param {int} depth the depth of the ancestor.     * @return {YAHOO.widget.Node} the ancestor     */    getAncestor: function(depth) {        if (depth >= this.depth || depth < 0)  {            return null;        }

⌨️ 快捷键说明

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