📄 treeview.js
字号:
this.tree.id + '\',' + this.index + ')'; sb[sb.length] = '<td'; // sb[sb.length] = ' onselectstart="return false"'; sb[sb.length] = ' id="' + this.getToggleElId() + '"'; sb[sb.length] = ' class="' + this.getStyle() + '"'; if (this.hasChildren(true)) { sb[sb.length] = ' onmouseover="this.className='; sb[sb.length] = getNode + '.getHoverStyle()"'; sb[sb.length] = ' onmouseout="this.className='; sb[sb.length] = getNode + '.getStyle()"'; } sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '">'; sb[sb.length] = '<div class="ygtvspacer">'; /* sb[sb.length] = '<img id="' + this.getSpacerId() + '"'; sb[sb.length] = ' alt=""'; sb[sb.length] = ' tabindex=0'; sb[sb.length] = ' src="' + this.spacerPath + '"'; sb[sb.length] = ' title="' + this.getStateText() + '"'; sb[sb.length] = ' class="ygtvspacer"'; // sb[sb.length] = ' onkeypress="return ' + getNode + '".onKeyPress()"'; sb[sb.length] = ' />'; */ //sb[sb.length] = ' '; sb[sb.length] = '</div>'; sb[sb.length] = '</td>'; sb[sb.length] = '<td '; sb[sb.length] = (this.nowrap) ? ' nowrap="nowrap" ' : ''; sb[sb.length] = ' >'; sb[sb.length] = '<a'; sb[sb.length] = ' id="' + this.labelElId + '"'; sb[sb.length] = ' class="' + this.labelStyle + '"'; sb[sb.length] = ' href="' + this.href + '"'; sb[sb.length] = ' target="' + this.target + '"'; sb[sb.length] = ' onclick="return ' + getNode + '.onLabelClick(' + getNode +')"'; if (this.hasChildren(true)) { sb[sb.length] = ' onmouseover="document.getElementById(\''; sb[sb.length] = this.getToggleElId() + '\').className='; sb[sb.length] = getNode + '.getHoverStyle()"'; sb[sb.length] = ' onmouseout="document.getElementById(\''; sb[sb.length] = this.getToggleElId() + '\').className='; sb[sb.length] = getNode + '.getStyle()"'; } sb[sb.length] = ' >'; sb[sb.length] = this.label; sb[sb.length] = '</a>'; sb[sb.length] = '</td>'; sb[sb.length] = '</tr>'; sb[sb.length] = '</table>'; return sb.join(""); }, /** * Executed when the label is clicked. Fires the labelClick custom event. * @method onLabelClick * @param me {Node} this node * @scope the anchor tag clicked * @return false to cancel the anchor click */ onLabelClick: function(me) { return me.tree.fireEvent("labelClick", me); //return true; }, toString: function() { return "TextNode (" + this.index + ") " + this.label; }});/** * A custom YAHOO.widget.Node that handles the unique nature of * the virtual, presentationless root node. * @namespace YAHOO.widget * @class RootNode * @extends YAHOO.widget.Node * @param oTree {YAHOO.widget.TreeView} The tree instance this node belongs to * @constructor */YAHOO.widget.RootNode = function(oTree) { // Initialize the node with null params. The root node is a // special case where the node has no presentation. So we have // to alter the standard properties a bit. this.init(null, null, true); /* * For the root node, we get the tree reference from as a param * to the constructor instead of from the parent element. */ this.tree = oTree;};YAHOO.extend(YAHOO.widget.RootNode, YAHOO.widget.Node, { // overrides YAHOO.widget.Node getNodeHtml: function() { return ""; }, toString: function() { return "RootNode"; }, loadComplete: function() { this.tree.draw(); }, collapse: function() {}, expand: function() {}});/** * This implementation takes either a string or object for the * oData argument. If is it a string, we will use it for the display * of this node (and it can contain any html code). If the parameter * is an object, we look for a parameter called "html" that will be * used for this node's display. * @namespace YAHOO.widget * @class HTMLNode * @extends YAHOO.widget.Node * @constructor * @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 * @param hasIcon {boolean} specifies whether or not leaf nodes should * have an icon */YAHOO.widget.HTMLNode = function(oData, oParent, expanded, hasIcon) { if (oData) { this.init(oData, oParent, expanded); this.initContent(oData, hasIcon); }};YAHOO.extend(YAHOO.widget.HTMLNode, YAHOO.widget.Node, { /** * The CSS class for the html content container. Defaults to ygtvhtml, but * can be overridden to provide a custom presentation for a specific node. * @property contentStyle * @type string */ contentStyle: "ygtvhtml", /** * The generated id that will contain the data passed in by the implementer. * @property contentElId * @type string */ contentElId: null, /** * The HTML content to use for this node's display * @property content * @type string */ content: null, /** * Sets up the node label * @property initContent * @param {object} An html string or object containing an html property * @param {boolean} hasIcon determines if the node will be rendered with an * icon or not */ initContent: function(oData, hasIcon) { if (typeof oData == "string") { oData = { html: oData }; } this.html = oData.html; this.contentElId = "ygtvcontentel" + this.index; this.hasIcon = hasIcon; }, /** * Returns the outer html element for this node's content * @method getContentEl * @return {HTMLElement} the element */ getContentEl: function() { return document.getElementById(this.contentElId); }, // overrides YAHOO.widget.Node getNodeHtml: function() { var sb = []; sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">'; sb[sb.length] = '<tr>'; for (var i=0;i<this.depth;++i) { //sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '"> </td>'; 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] = ' onclick="javascript:' + this.getToggleLink() + '"'; if (this.hasChildren(true)) { sb[sb.length] = ' onmouseover="this.className='; sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\''; sb[sb.length] = this.tree.id + '\',' + this.index + ').getHoverStyle()"'; sb[sb.length] = ' onmouseout="this.className='; sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\''; sb[sb.length] = this.tree.id + '\',' + this.index + ').getStyle()"'; } //sb[sb.length] = '> </td>'; sb[sb.length] = '><div class="ygtvspacer"></div></td>'; } sb[sb.length] = '<td'; sb[sb.length] = ' id="' + this.contentElId + '"'; sb[sb.length] = ' class="' + this.contentStyle + '"'; sb[sb.length] = (this.nowrap) ? ' nowrap="nowrap" ' : ''; sb[sb.length] = ' >'; sb[sb.length] = this.html; sb[sb.length] = '</td>'; sb[sb.length] = '</tr>'; sb[sb.length] = '</table>'; return sb.join(""); }, toString: function() { return "HTMLNode (" + this.index + ")"; }});/** * A menu-specific implementation that differs from TextNode in that only * one sibling can be expanded at a time. * @namespace YAHOO.widget * @class MenuNode * @extends YAHOO.widget.TextNode * @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 * @constructor */YAHOO.widget.MenuNode = function(oData, oParent, expanded) { if (oData) { this.init(oData, oParent, expanded); this.setUpLabel(oData); } /* * Menus usually allow only one branch to be open at a time. */ this.multiExpand = false;};YAHOO.extend(YAHOO.widget.MenuNode, YAHOO.widget.TextNode, { toString: function() { return "MenuNode (" + this.index + ") " + this.label; }});/** * A static factory class for tree view expand/collapse animations * @class TVAnim * @static */YAHOO.widget.TVAnim = function() { return { /** * Constant for the fade in animation * @property FADE_IN * @type string * @static */ FADE_IN: "TVFadeIn", /** * Constant for the fade out animation * @property FADE_OUT * @type string * @static */ FADE_OUT: "TVFadeOut", /** * Returns a ygAnim instance of the given type * @method getAnim * @param type {string} the type of animation * @param el {HTMLElement} the element to element (probably the children div) * @param callback {function} function to invoke when the animation is done. * @return {YAHOO.util.Animation} the animation instance * @static */ getAnim: function(type, el, callback) { if (YAHOO.widget[type]) { return new YAHOO.widget[type](el, callback); } else { return null; } }, /** * Returns true if the specified animation class is available * @method isValid * @param type {string} the type of animation * @return {boolean} true if valid, false if not * @static */ isValid: function(type) { return (YAHOO.widget[type]); } };} ();/** * A 1/2 second fade-in animation. * @class TVFadeIn * @constructor * @param el {HTMLElement} the element to animate * @param callback {function} function to invoke when the animation is finished */YAHOO.widget.TVFadeIn = function(el, callback) { /** * The element to animate * @property el * @type HTMLElement */ this.el = el; /** * the callback to invoke when the animation is complete * @property callback * @type function */ this.callback = callback;};YAHOO.widget.TVFadeIn.prototype = { /** * Performs the animation * @method animate */ animate: function() { var tvanim = this; var s = this.el.style; s.opacity = 0.1; s.filter = "alpha(opacity=10)"; s.display = ""; var dur = 0.4; var a = new YAHOO.util.Anim(this.el, {opacity: {from: 0.1, to: 1, unit:""}}, dur); a.onComplete.subscribe( function() { tvanim.onComplete(); } ); a.animate(); }, /** * Clean up and invoke callback * @method onComplete */ onComplete: function() { this.callback(); }, /** * toString * @method toString * @return {string} the string representation of the instance */ toString: function() { return "TVFadeIn"; }};/** * A 1/2 second fade out animation. * @class TVFadeOut * @constructor * @param el {HTMLElement} the element to animate * @param callback {Function} function to invoke when the animation is finished */YAHOO.widget.TVFadeOut = function(el, callback) { /** * The element to animate * @property el * @type HTMLElement */ this.el = el; /** * the callback to invoke when the animation is complete * @property callback * @type function */ this.callback = callback;};YAHOO.widget.TVFadeOut.prototype = { /** * Performs the animation * @method animate */ animate: function() { var tvanim = this; var dur = 0.4; var a = new YAHOO.util.Anim(this.el, {opacity: {from: 1, to: 0.1, unit:""}}, dur); a.onComplete.subscribe( function() { tvanim.onComplete(); } ); a.animate(); }, /** * Clean up and invoke callback * @method onComplete */ onComplete: function() { var s = this.el.style; s.display = "none"; // s.opacity = 1; s.filter = "alpha(opacity=100)"; this.callback(); }, /** * toString * @method toString * @return {string} the string representation of the instance */ toString: function() { return "TVFadeOut"; }};YAHOO.register("treeview", YAHOO.widget.TreeView, {version: "2.2.2", build: "204"});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -