1 /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
4 * This implementation takes either a string or object for the
5 * oData argument. If is it a string, we will use it for the display
6 * of this node (and it can contain any html code). If the parameter
7 * is an object, we look for a parameter called "html" that will be
8 * used for this node's display.
10 * @extends YAHOO.widget.Node
12 * @param oData {object} a string or object containing the data that will
13 * be used to render this node
14 * @param oParent {YAHOO.widget.Node} this node's parent node
15 * @param expanded {boolean} the initial expanded/collapsed state
16 * @param hasIcon {boolean} specifies whether or not leaf nodes should
19 YAHOO.widget.HTMLNode = function(oData, oParent, expanded, hasIcon) {
21 this.init(oData, oParent, expanded);
22 this.initContent(oData, hasIcon);
26 YAHOO.widget.HTMLNode.prototype = new YAHOO.widget.Node();
29 * The CSS class for the label href. Defaults to ygtvlabel, but can be
30 * overridden to provide a custom presentation for a specific node.
34 YAHOO.widget.HTMLNode.prototype.contentStyle = "ygtvhtml";
37 * The generated id that will contain the data passed in by the implementer.
41 YAHOO.widget.HTMLNode.prototype.contentElId = null;
44 * The HTML content to use for this node's display
48 YAHOO.widget.HTMLNode.prototype.content = null;
51 * Sets up the node label
53 * @param {object} An html string or object containing an html property
54 * @param {boolean} hasIcon determines if the node will be rendered with an
57 YAHOO.widget.HTMLNode.prototype.initContent = function(oData, hasIcon) {
58 if (typeof oData == "string") {
59 oData = { html: oData };
62 this.html = oData.html;
63 this.contentElId = "ygtvcontentel" + this.index;
64 this.hasIcon = hasIcon;
68 * Returns the outer html element for this node's content
70 * @return {HTMLElement} the element
72 YAHOO.widget.HTMLNode.prototype.getContentEl = function() {
73 return document.getElementById(this.contentElId);
76 // overrides YAHOO.widget.Node
77 YAHOO.widget.HTMLNode.prototype.getNodeHtml = function() {
80 sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
81 sb[sb.length] = '<tr>';
83 for (i=0;i<this.depth;++i) {
84 sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '"> </td>';
88 sb[sb.length] = '<td';
89 sb[sb.length] = ' id="' + this.getToggleElId() + '"';
90 sb[sb.length] = ' class="' + this.getStyle() + '"';
91 sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '"> ';
92 if (this.hasChildren(true)) {
93 sb[sb.length] = ' onmouseover="this.className=';
94 sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
95 sb[sb.length] = this.tree.id + '\',' + this.index + ').getHoverStyle()"';
96 sb[sb.length] = ' onmouseout="this.className=';
97 sb[sb.length] = 'YAHOO.widget.TreeView.getNode(\'';
98 sb[sb.length] = this.tree.id + '\',' + this.index + ').getStyle()"';
100 sb[sb.length] = '</td>';
103 sb[sb.length] = '<td';
104 sb[sb.length] = ' id="' + this.contentElId + '"';
105 sb[sb.length] = ' class="' + this.contentStyle + '"';
106 sb[sb.length] = ' >';
107 sb[sb.length] = this.html;
108 sb[sb.length] = '</td>';
109 sb[sb.length] = '</tr>';
110 sb[sb.length] = '</table>';