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

📄 treeview.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
        }        if (!this.childrenRendered) {            this.getChildrenEl().innerHTML = this.renderChildren();        } else {        }        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;        }        if (! this.multiExpand) {            var sibs = this.getSiblings();            for (var i=0; sibs && i<sibs.length; ++i) {                if (sibs[i] != this && sibs[i].expanded) {                     sibs[i].collapse();                 }            }        }        this.showChildren();        ret = this.tree.fireEvent("expandComplete", this);    },    updateIcon: function() {        if (this.hasIcon) {            var el = this.getToggleEl();            if (el) {                el.className = el.className.replace(/ygtv(([tl][pmn]h?)|(loading))/,this.getStyle());            }        }    },    /**     * Returns the css style name for the toggle     * @method getStyle     * @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() && !this.getIconMode())) {            // if (this.hasChildren(true)) {                type = (this.expanded) ? "m" : "p";            }            return "ygtv" + loc + type;        }    },    /**     * Returns the hover style for the icon     * @return {string} the css class hover state     * @method getHoverStyle     */    getHoverStyle: function() {         var s = this.getStyle();        if (this.hasChildren(true) && !this.isLoading) {             s += "h";         }        return s;    },    /**     * Recursively expands all of this node's children.     * @method expandAll     */    expandAll: function() {         for (var i=0;i<this.children.length;++i) {            var c = this.children[i];            if (c.isDynamic()) {                break;            } else if (! c.multiExpand) {                break;            } else {                c.expand();                c.expandAll();            }        }    },    /**     * Recursively collapses all of this node's children.     * @method collapseAll     */    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.  Calling it without the callback     * will turn off dynamic load for the node.     * @method setDynamicLoad     * @param fmDataLoader {function} the function that will be used to get the data.     * @param iconMode {int} configures the icon that is displayed when a dynamic     * load node is expanded the first time without children.  By default, the      * "collapse" icon will be used.  If set to 1, the leaf node icon will be     * displayed.     */    setDynamicLoad: function(fnDataLoader, iconMode) {         if (fnDataLoader) {            this.dataLoader = fnDataLoader;            this._dynLoad = true;        } else {            this.dataLoader = null;            this._dynLoad = false;        }        if (iconMode) {            this.iconMode = iconMode;        }    },    /**     * Evaluates if this node is the root node of the tree     * @method isRoot     * @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     * @method isDynamic     * @return {boolean} true if this node's children are to be loaded dynamically     */    isDynamic: function() {         if (this.isLeaf) {            return false;        } else {            return (!this.isRoot() && (this._dynLoad || this.tree.root._dynLoad));            // return lazy;        }    },    /**     * Returns the current icon mode.  This refers to the way childless dynamic     * load nodes appear (this comes into play only after the initial dynamic     * load request produced no children).     * @method getIconMode     * @return {int} 0 for collapse style, 1 for leaf node style     */    getIconMode: function() {        return (this.iconMode || this.tree.root.iconMode);    },    /**     * 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.     * @method hasChildren     * @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) {         if (this.isLeaf) {            return false;        } else {            return ( this.children.length > 0 || (checkForLazyLoad && this.isDynamic() && !this.dynamicLoadComplete) );        }    },    /**     * Expands if node is collapsed, collapses otherwise.     * @method toggle     */    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.     * @method getHtml     * @return {string} the markup for this node and its expanded children.     */    getHtml: function() {        this.childrenRendered = false;        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.     * @method getChildrenHtml     * @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() + '"';        // This is a workaround for an IE rendering issue, the child div has layout        // in IE, creating extra space if a leaf node is created with the expanded        // property set to true.        if (!this.expanded || !this.hasChildren()) {            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) ||                (this.renderHidden && !this.isDynamic()) ) {            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.     * @method renderChildren     * @return {string} the html for this node's children     * @private     */    renderChildren: function() {        var node = this;        if (this.isDynamic() && !this.dynamicLoadComplete) {            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.     * @method completeRender     * @return {string} children html     */    completeRender: function() {        var sb = [];        for (var i=0; i < this.children.length; ++i) {            // this.children[i].childrenRendered = false;            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.     * @method loadComplete     */    loadComplete: function() {        this.getChildrenEl().innerHTML = this.completeRender();        this.dynamicLoadComplete = true;        this.isLoading = false;        this.expand(true);        this.tree.locked = false;    },    /**     * Returns this node's ancestor at the specified depth.     * @method getAncestor     * @param {int} depth the depth of the ancestor.     * @return {Node} the ancestor     */    getAncestor: function(depth) {        if (depth >= this.depth || depth < 0)  {            return null;        }        var p = this.parent;                while (p.depth > depth) {            p = p.parent;        }        return p;    },    /**     * Returns the css class for the spacer at the specified depth for     * this node.  If this node's ancestor at the specified depth     * has a next sibling the presentation is different than if it     * does not have a next sibling     * @method getDepthStyle     * @param {int} depth the depth of the ancestor.     * @return {string} the css class for the spacer     */    getDepthStyle: function(depth) {        return (this.getAncestor(depth).nextSibling) ?             "ygtvdepthcell" : "ygtvblankdepthcell";    },    /**     * Get the markup for the node.  This may be overrided so that we can     * support different types of nodes.     * @method getNodeHtml     * @return {string} The HTML that will render this node.     */    getNodeHtml: function() {         var sb = [];        sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0" class="ygtvdepth' + this.depth + '">';        sb[sb.length] = '<tr class="ygtvrow">';                for (var i=0;i<this.depth;++i) {            sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '"><div class="ygtvspacer"></div></td>';        }        if (this.hasIcon) {            sb[sb.length] = '<td';             sb[sb.length] = ' id="' + this.getToggleElId() + '"';            sb[sb.length] = ' class="' + this.getStyle() + '"';            sb[sb.length] = '><a href="#" class="ygtvspacer">&nbsp;</a></td>';        }        sb[sb.length] = '<td';        sb[sb.length] = ' id="' + this.contentElId + '"';         sb[sb.length] = ' class="' + this.contentStyle  + ' ygtvcontent" ';        sb[sb.length] = (this.nowrap) ? ' nowrap="nowrap" ' : '';        sb[sb.length] = ' >';		sb[sb.length] = this.getContentHtml();        sb[sb.length] = '</td>';        sb[sb.length] = '</tr>';        sb[sb.length] = '</table>';        return sb.join("");    },	/**     * Get the markup for the contents of the node.  This is designed to be overrided so that we can     * support different types of nodes.     * @method getContentHtml     * @return {string} The HTML that will render the content of this node.     */	getContentHtml: function () {		return "";	},    /**     * Regenerates the html for this node and its children.  To be used when the     * node is expanded and new children have been added.     * @method refresh     */    refresh: function() {        // this.loadComplete();        this.getChildrenEl().innerHTML = this.completeRender();        if (this.hasIcon) {            var el = this.getToggleEl();            if (el) {                el.className = this.getStyle();            }        }    },    /**     * Node toString     * @method toString     * @return {string} string representation of the node     */    toString: function() {        return this._type + " (" + this.index + ")";    },	/**	* array of items that had the focus set on them	* so that they can be cleaned when focus is lost	* @property _focusHighlightedItems	* @type Array of DOM elements	* @private	*/	_focusHighlightedItems: [],	_focusedItem: null,	/**	* Sets the focus on the node element.	* It will only be able to set the focus on nodes that have anchor elements in it.  	* Toggle or branch icons have anchors and can be focused on.  	* If will fail in nodes that have no anchor	* @method focus	*

⌨️ 快捷键说明

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