1 /* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
4 * The default node presentation. The first parameter should be
5 * either a string that will be used as the node's label, or an object
6 * that has a string propery called label. By default, the clicking the
7 * label will toggle the expanded/collapsed state of the node. By
8 * changing the href property of the instance, this behavior can be
9 * changed so that the label will go to the specified href.
11 * @extends YAHOO.widget.Node
13 * @param oData {object} a string or object containing the data that will
14 * be used to render this node
15 * @param oParent {YAHOO.widget.Node} this node's parent node
16 * @param expanded {boolean} the initial expanded/collapsed state
18 YAHOO.widget.TextNode = function(oData, oParent, expanded) {
20 this.init(oData, oParent, expanded);
21 this.setUpLabel(oData);
25 YAHOO.widget.TextNode.prototype = new YAHOO.widget.Node();
28 * The CSS class for the label href. Defaults to ygtvlabel, but can be
29 * overridden to provide a custom presentation for a specific node.
33 YAHOO.widget.TextNode.prototype.labelStyle = "ygtvlabel";
36 * The derived element id of the label for this node
40 YAHOO.widget.TextNode.prototype.labelElId = null;
43 * The text for the label. It is assumed that the oData parameter will
44 * either be a string that will be used as the label, or an object that
45 * has a property called "label" that we will use.
49 YAHOO.widget.TextNode.prototype.label = null;
52 * Sets up the node label
54 * @param oData string containing the label, or an object with a label property
56 YAHOO.widget.TextNode.prototype.setUpLabel = function(oData) {
57 if (typeof oData == "string") {
58 oData = { label: oData };
60 this.label = oData.label;
64 this.href = oData.href;
69 this.target = oData.target;
72 this.labelElId = "ygtvlabelel" + this.index;
76 * Returns the label element
78 * @return {object} the element
80 YAHOO.widget.TextNode.prototype.getLabelEl = function() {
81 return document.getElementById(this.labelElId);
84 // overrides YAHOO.widget.Node
85 YAHOO.widget.TextNode.prototype.getNodeHtml = function() {
88 sb[sb.length] = '<table border="0" cellpadding="0" cellspacing="0">';
89 sb[sb.length] = '<tr>';
91 for (i=0;i<this.depth;++i) {
92 // sb[sb.length] = '<td class="ygtvdepthcell"> </td>';
93 sb[sb.length] = '<td class="' + this.getDepthStyle(i) + '"> </td>';
96 var getNode = 'YAHOO.widget.TreeView.getNode(\'' +
97 this.tree.id + '\',' + this.index + ')';
99 sb[sb.length] = '<td';
100 // sb[sb.length] = ' onselectstart="return false"';
101 sb[sb.length] = ' id="' + this.getToggleElId() + '"';
102 sb[sb.length] = ' class="' + this.getStyle() + '"';
103 if (this.hasChildren(true)) {
104 sb[sb.length] = ' onmouseover="this.className=';
105 sb[sb.length] = getNode + '.getHoverStyle()"';
106 sb[sb.length] = ' onmouseout="this.className=';
107 sb[sb.length] = getNode + '.getStyle()"';
109 sb[sb.length] = ' onclick="javascript:' + this.getToggleLink() + '"> ';
110 sb[sb.length] = '</td>';
111 sb[sb.length] = '<td>';
112 sb[sb.length] = '<a';
113 sb[sb.length] = ' id="' + this.labelElId + '"';
114 sb[sb.length] = ' class="' + this.labelStyle + '"';
115 // sb[sb.length] = ' href="' + this.href + '"';
116 sb[sb.length] = ' href="javascript:set_selected_node(\''+this.tree.id + '\',\''+this.index+'\');'+ this.href +'"';
117 sb[sb.length] = ' target="' + this.target + '"';
118 if (this.hasChildren(true)) {
119 sb[sb.length] = ' onmouseover="document.getElementById(\'';
120 sb[sb.length] = this.getToggleElId() + '\').className=';
121 sb[sb.length] = getNode + '.getHoverStyle()"';
122 sb[sb.length] = ' onmouseout="document.getElementById(\'';
123 sb[sb.length] = this.getToggleElId() + '\').className=';
124 sb[sb.length] = getNode + '.getStyle()"';
126 sb[sb.length] = ' >';
127 sb[sb.length] = this.label;
128 sb[sb.length] = '</a>';
129 sb[sb.length] = '</td>';
130 sb[sb.length] = '</tr>';
131 sb[sb.length] = '</table>';