📄 treeview.js
字号:
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 * * @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 is designed to be overrided so that we can * support different types of nodes. * * @return {string} the html for this node */ getNodeHtml: function() { return ""; }};/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. *//** * @class A custom YAHOO.widget.Node that handles the unique nature of * the virtual, presentationless root node. * * @extends YAHOO.widget.Node * @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. * * @type YAHOO.widget.TreeView */ this.tree = oTree;};YAHOO.widget.RootNode.prototype = new YAHOO.widget.Node();// overrides YAHOO.widget.NodeYAHOO.widget.RootNode.prototype.getNodeHtml = function() { return "";};/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. *//** * @class The default node presentation. The first parameter should be * either a string that will be used as the node's label, or an object * that has a string propery called label. By default, the clicking the * label will toggle the expanded/collapsed state of the node. By * changing the href property of the instance, this behavior can be * changed so that the label will go to the specified href. * * @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 */YAHOO.widget.TextNode = function(oData, oParent, expanded) { if (oParent) { this.init(oData, oParent, expanded); this.setUpLabel(oData); }};YAHOO.widget.TextNode.prototype = new YAHOO.widget.Node();/** * The CSS class for the label href. Defaults to ygtvlabel, but can be * overridden to provide a custom presentation for a specific node. * * @type string */YAHOO.widget.TextNode.prototype.labelStyle = "ygtvlabel";/** * The derived element id of the label for this node * * @type string */YAHOO.widget.TextNode.prototype.labelElId = null;/** * The text for the label. It is assumed that the oData parameter will * either be a string that will be used as the label, or an object that * has a property called "label" that we will use. * * @type string */YAHOO.widget.TextNode.prototype.label = null;/** * Sets up the node label * * @param oData string containing the label, or an object with a label property */YAHOO.widget.TextNode.prototype.setUpLabel = function(oData) { if (typeof oData == "string") { oData = { label: oData }; } this.label = oData.label; // update the link if (oData.href) { this.href = oData.href; } // set the target if (oData.target) { this.target = oData.target; } this.labelElId = "ygtvlabelel" + this.index;};/** * Returns the label element * * @return {object} the element */YAHOO.widget.TextNode.prototype.getLabelEl = function() { return document.getElementById(this.labelElId);};// overrides YAHOO.widget.NodeYAHOO.widget.TextNode.prototype.getNodeHtml = function() { var sb = new Array(); sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">'; sb[sb.length] = '<tr>'; for (i=0;i<this.depth;++i) { // sb[sb.length] = '<td class="ygtvdepthcell"> </td>'; sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '"> </td>'; } var getNode = 'YAHOO.widget.TreeView.getNode(\'' + 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] = '</td>'; sb[sb.length] = '<td>'; 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 + '"'; 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("");};/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. *//** * @class menu-specific implementation that differs in that only one sibling * can be expanded at a time. * @extends YAHOO.widget.TextNode * @constructor */YAHOO.widget.MenuNode = function(oData, oParent, expanded) { if (oParent) { this.init(oData, oParent, expanded); this.setUpLabel(oData); } // Menus usually allow only one branch to be open at a time. this.multiExpand = false;};YAHOO.widget.MenuNode.prototype = new YAHOO.widget.TextNode();/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. *//** * @class 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. * * @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 (oParent) { this.init(oData, oParent, expanded); this.initContent(oData, hasIcon); }};YAHOO.widget.HTMLNode.prototype = new YAHOO.widget.Node();/** * The CSS class for the label href. Defaults to ygtvlabel, but can be * overridden to provide a custom presentation for a specific node. * * @type string */YAHOO.widget.HTMLNode.prototype.contentStyle = "ygtvhtml";/** * The generated id that will contain the data passed in by the implementer. * * @type string */YAHOO.widget.HTMLNode.prototype.contentElId = null;/** * The HTML content to use for this node's display * * @type string */YAHOO.widget.HTMLNode.prototype.content = null;/** * Sets up the node label * * @param {object} html string or object containing a html field * @param {boolean} hasIcon determines if the node will be rendered with an * icon or not */YAHOO.widget.HTMLNode.prototype.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 * * @return {Object} the element */YAHOO.widget.HTMLNode.prototype.getContentEl = function() { return document.getElementById(this.contentElId);};// overrides YAHOO.widget.NodeYAHOO.widget.HTMLNode.prototype.getNodeHtml = function() { var sb = new Array(); sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">'; sb[sb.length] = '<tr>'; for (i=0;i<this.depth;++i) { sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '"> </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] = '<td'; sb[sb.length] = ' id="' + this.contentElId + '"'; sb[sb.length] = ' class="' + this.contentStyle + '"'; sb[sb.length] = ' >'; sb[sb.length] = this.html; sb[sb.length] = '</td>'; sb[sb.length] = '</tr>'; sb[sb.length] = '</table>'; return sb.join("");};/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. *//** * Static factory class for tree view expand/collapse animations */YAHOO.widget.TVAnim = new function() { /** * Constant for the fade in animation * * @type string */ this.FADE_IN = "YAHOO.widget.TVFadeIn"; /** * Constant for the fade out animation * * @type string */ this.FADE_OUT = "YAHOO.widget.TVFadeOut"; /** * Returns a ygAnim instance of the given type * * @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 {ygAnim} the animation instance */ this.getAnim = function(type, el, callback) { switch (type) { case this.FADE_IN: return new YAHOO.widget.TVFadeIn(el, callback); case this.FADE_OUT: return new YAHOO.widget.TVFadeOut(el, callback); default: return null; } }; /** * Returns true if the specified animation class is available * * @param type {string} the type of animation * @return {boolean} true if valid, false if not */ this.isValid = function(type) { return ( "undefined" != eval("typeof " + type) ); };};/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. *//** * 1/2 second fade-in * * @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 animation dom ref */ this.el = el; /** * the callback to invoke when the animation is complete * * @type function */ this.callback = callback; /** * @private */};/** * Performs the animation */YAHOO.widget.TVFadeIn.prototype = { animate: function() { var tvanim = this; var s = this.el.style; s.opacity = 0.1; s.filter = "alpha(opacity=10)"; s.display = ""; // var dur = ( navigator.userAgent.match(/msie/gi) ) ? 0.05 : 0.4; var dur = 0.4; // var a = new ygAnim_Fade(this.el, dur, 1); // a.setStart(0.1); // a.onComplete = function() { tvanim.onComplete(); }; // var a = new YAHOO.util.Anim(this.el, 'opacity', 0.1, 1); 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 */ onComplete: function() { this.callback(); }};/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. *//** * 1/2 second fade out * * @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 animation dom ref */ this.el = el; /** * the callback to invoke when the animation is complete * * @type function */ this.callback = callback; /** * @private */};/** * Performs the animation */YAHOO.widget.TVFadeOut.prototype = { animate: function() { var tvanim = this; // var dur = ( navigator.userAgent.match(/msie/gi) ) ? 0.05 : 0.4; var dur = 0.4; // var a = new ygAnim_Fade(this.el, dur, 0.1); // a.onComplete = function() { tvanim.onComplete(); }; // var a = new YAHOO.util.Anim(this.el, 'opacity', 1, 0.1); 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 */ onComplete: function() { var s = this.el.style; s.display = "none"; // s.opacity = 1; s.filter = "alpha(opacity=100)"; this.callback(); }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -