2 � Copyright 2008 Nokia Corporation. All rights reserved.
\r
4 IMPORTANT: The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia
\r
5 Corporation (�Nokia�) in consideration of your agreement to the following terms. Your use, installation
\r
6 and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If
\r
7 you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example
\r
10 In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia
\r
11 grants you a personal, non-exclusive license, under Nokia�s copyrights in the WRTKit and Example
\r
12 Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML,
\r
13 CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60
\r
16 If you redistribute the WRTKit and Example files, you must retain this entire notice in all such
\r
17 redistributions of the WRTKit and Example files.
\r
19 You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products
\r
20 that include the WRTKit and Example files without the prior written explicit agreement with Nokia.
\r
21 Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by
\r
22 Nokia herein, including but not limited to any patent rights that may be infringed by your products that
\r
23 incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files
\r
24 may be incorporated.
\r
26 The WRTKit and Example files are provided on an "AS IS" basis. NOKIA MAKES NO
\r
27 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
\r
28 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
\r
29 PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION
\r
30 ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
\r
32 IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
\r
33 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
34 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
35 INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR
\r
36 DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY
\r
37 OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE,
\r
38 EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
42 ///////////////////////////////////////////////////////////////////////////////
\r
43 // The NavigationButton class implements a button control for use in
\r
44 // navigational contexts in menu-style UIs.
\r
47 function NavigationButton(id, image, text) {
\r
48 if (id != UI_NO_INIT_ID) {
\r
49 this.init(id, image, text);
\r
53 // NavigationButton inherits from ActionControl.
\r
54 NavigationButton.prototype = new ActionControl(UI_NO_INIT_ID);
\r
56 // Button table element.
\r
57 NavigationButton.prototype.tableElement = null;
\r
59 // Button table row element.
\r
60 NavigationButton.prototype.tableRowElement = null;
\r
62 // Button table left cell element.
\r
63 NavigationButton.prototype.tableLeftCellElement = null;
\r
65 // Button table right cell element.
\r
66 NavigationButton.prototype.tableRightCellElement = null;
\r
68 // Button image element.
\r
69 NavigationButton.prototype.imageElement = null;
\r
71 // Button link element.
\r
72 NavigationButton.prototype.linkElement = null;
\r
74 // Button text element.
\r
75 NavigationButton.prototype.textElement = null;
\r
77 // Initializer - called from constructor.
\r
78 NavigationButton.prototype.init = function(id, image, text) {
\r
79 uiLogger.debug("NavigationButton.init(" + id + ", " + image + ", " + text + ")");
\r
81 // call superclass initializer
\r
82 ActionControl.prototype.init.call(this, id, null);
\r
84 // remove caption element
\r
85 this.assemblyElement.removeChild(this.captionElement);
\r
87 // construct the button
\r
88 this.buttonElement = document.createElement("div");
\r
89 this.tableElement = document.createElement("table");
\r
90 this.tableRowElement = document.createElement("tr");
\r
91 this.tableLeftCellElement = document.createElement("td");
\r
92 this.tableRightCellElement = document.createElement("td");
\r
93 this.imageElement = null;
\r
94 this.linkElement = document.createElement("a");
\r
95 this.linkElement.href = "JavaScript:void(0)";
\r
96 this.textElement = document.createElement("span");
\r
97 this.tableElement.appendChild(this.tableRowElement);
\r
98 this.tableRowElement.appendChild(this.tableLeftCellElement);
\r
99 this.tableRowElement.appendChild(this.tableRightCellElement);
\r
100 this.tableRightCellElement.appendChild(this.linkElement);
\r
101 this.linkElement.appendChild(this.textElement);
\r
102 this.buttonElement.appendChild(this.tableElement);
\r
103 this.controlElement.appendChild(this.buttonElement);
\r
105 // set the image and text
\r
106 this.setImage(image);
\r
107 this.setText(text);
\r
109 // bind event listeners
\r
110 this.bindActionControlListeners();
\r
112 // update the style
\r
113 this.updateStyleFromState();
\r
116 // Sets the enabled state.
\r
117 NavigationButton.prototype.setEnabled = function(enabled) {
\r
118 uiLogger.debug("NavigationButton.setEnabled(" + enabled + ")");
\r
120 // bail out early if there is no change in state
\r
121 if (this.enabled == enabled) {
\r
125 // set the enabled state
\r
126 this.enabled = enabled;
\r
128 if (this.enabled) {
\r
129 // diabled -> enabled
\r
130 this.tableRightCellElement.removeChild(this.textElement);
\r
131 this.tableRightCellElement.appendChild(this.linkElement);
\r
132 this.linkElement.appendChild(this.textElement);
\r
134 // enabled -> diabled
\r
135 this.linkElement.removeChild(this.textElement);
\r
136 this.tableRightCellElement.removeChild(this.linkElement);
\r
137 this.tableRightCellElement.appendChild(this.textElement);
\r
140 // update the style
\r
141 this.updateStyleFromState();
\r
144 // Returns the button image (URL); null if none.
\r
145 NavigationButton.prototype.getImage = function() {
\r
146 return (this.imageElement != null) ? this.imageElement.src : null;
\r
149 // Sets the button image (URL); null if none.
\r
150 NavigationButton.prototype.setImage = function(image) {
\r
151 uiLogger.debug("NavigationButton.setImage(" + image + ")");
\r
153 if (image == null) {
\r
154 // remove image - if any
\r
155 if (this.imageElement != null) {
\r
156 this.tableLeftCellElement.removeChild(this.imageElement);
\r
159 // default to not append image element
\r
160 var append = false;
\r
162 // create image element if one doesn't exist
\r
163 if (this.imageElement == null) {
\r
164 this.imageElement = document.createElement("img");
\r
165 this.imageElement.setAttribute("alt", "");
\r
169 // set image source URL
\r
170 this.imageElement.src = image;
\r
172 // append the image element to the left cell?
\r
174 this.tableLeftCellElement.appendChild(this.imageElement);
\r
179 // Returns the button text.
\r
180 NavigationButton.prototype.getText = function() {
\r
181 return this.textElement.innerHTML;
\r
184 // Sets the button text.
\r
185 NavigationButton.prototype.setText = function(text) {
\r
186 uiLogger.debug("NavigationButton.setText(" + text + ")");
\r
187 this.textElement.innerHTML = (text == null) ? "" : text;;
\r
190 // Updates the style of the control to reflects the state of the control.
\r
191 NavigationButton.prototype.updateStyleFromState = function() {
\r
192 uiLogger.debug("NavigationButton.updateStyleFromState()");
\r
194 // determine the state name
\r
195 var stateName = this.getStyleStateName();
\r
197 // set root element class name
\r
198 this.setClassName(this.rootElement, "Control");
\r
200 // set the control assembly class names
\r
201 this.setClassName(this.assemblyElement, "ControlAssembly ControlAssembly" + stateName);
\r
204 this.setClassName(this.controlElement, "ControlElement NavigationButtonControlElement");
\r
206 // set the button table class names
\r
207 this.setClassName(this.buttonElement, "NavigationButton");
\r
208 this.setClassName(this.tableElement, "NavigationButtonTable");
\r
209 this.setClassName(this.tableRowElement, "NavigationButtonRow");
\r
210 this.setClassName(this.tableLeftCellElement, "NavigationButtonImageCell");
\r
211 this.setClassName(this.tableRightCellElement, "NavigationButtonTextCell");
\r
213 // set image class names
\r
214 if (this.imageElement) {
\r
215 this.setClassName(this.imageElement, "NavigationButtonImage");
\r
218 // set the button text class name
\r
219 this.setClassName(this.textElement, "NavigationButtonText NavigationButtonText" + stateName);
\r