author | Eugene Ostroukhov <eugeneo@symbian.org> |
Thu, 11 Mar 2010 13:41:06 -0800 | |
changeset 254 | 78b83bc27fa2 |
parent 211 | 7b148352159e |
child 273 | b1f63c2c240c |
permissions | -rw-r--r-- |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
1 |
/** |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
2 |
* Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies). |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
3 |
* All rights reserved. |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
8 |
* |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
9 |
* Initial Contributors: |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
10 |
* Symbian Foundation - initial contribution. |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
11 |
* Contributors: |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
12 |
*/ |
73 | 13 |
/* |
211 | 14 |
© Copyright 2008 Nokia Corporation. All rights reserved. |
73 | 15 |
|
16 |
IMPORTANT: The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia |
|
211 | 17 |
Corporation ("Nokia") in consideration of your agreement to the following terms. Your use, installation |
73 | 18 |
and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If |
19 |
you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example |
|
20 |
Widget files. |
|
21 |
||
22 |
In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia |
|
211 | 23 |
grants you a personal, non-exclusive license, under Nokia's copyrights in the WRTKit and Example |
73 | 24 |
Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML, |
25 |
CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60 |
|
26 |
Widgets. |
|
27 |
||
28 |
If you redistribute the WRTKit and Example files, you must retain this entire notice in all such |
|
29 |
redistributions of the WRTKit and Example files. |
|
30 |
||
31 |
You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products |
|
32 |
that include the WRTKit and Example files without the prior written explicit agreement with Nokia. |
|
33 |
Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by |
|
34 |
Nokia herein, including but not limited to any patent rights that may be infringed by your products that |
|
35 |
incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files |
|
36 |
may be incorporated. |
|
37 |
||
38 |
The WRTKit and Example files are provided on an "AS IS" basis. NOKIA MAKES NO |
|
39 |
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED |
|
40 |
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A |
|
41 |
PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION |
|
42 |
ALONE OR IN COMBINATION WITH YOUR PRODUCTS. |
|
43 |
||
44 |
IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR |
|
45 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
46 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
47 |
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR |
|
48 |
DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY |
|
49 |
OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, |
|
50 |
EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
51 |
||
52 |
*/ |
|
53 |
||
54 |
/////////////////////////////////////////////////////////////////////////////// |
|
55 |
// The NavigationButton class implements a button control for use in |
|
56 |
// navigational contexts in menu-style UIs. |
|
57 |
||
58 |
// Constructor. |
|
59 |
function NavigationButton(id, image, text) { |
|
60 |
if (id != UI_NO_INIT_ID) { |
|
61 |
this.init(id, image, text); |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
// NavigationButton inherits from ActionControl. |
|
66 |
NavigationButton.prototype = new ActionControl(UI_NO_INIT_ID); |
|
67 |
||
68 |
// Button table element. |
|
69 |
NavigationButton.prototype.tableElement = null; |
|
70 |
||
71 |
// Button table row element. |
|
72 |
NavigationButton.prototype.tableRowElement = null; |
|
73 |
||
74 |
// Button table left cell element. |
|
75 |
NavigationButton.prototype.tableLeftCellElement = null; |
|
76 |
||
77 |
// Button table right cell element. |
|
78 |
NavigationButton.prototype.tableRightCellElement = null; |
|
79 |
||
80 |
// Button image element. |
|
81 |
NavigationButton.prototype.imageElement = null; |
|
82 |
||
83 |
// Button link element. |
|
84 |
NavigationButton.prototype.linkElement = null; |
|
85 |
||
86 |
// Button text element. |
|
87 |
NavigationButton.prototype.textElement = null; |
|
88 |
||
89 |
// Initializer - called from constructor. |
|
90 |
NavigationButton.prototype.init = function(id, image, text) { |
|
91 |
uiLogger.debug("NavigationButton.init(" + id + ", " + image + ", " + text + ")"); |
|
92 |
||
93 |
// call superclass initializer |
|
94 |
ActionControl.prototype.init.call(this, id, null); |
|
95 |
||
96 |
// remove caption element |
|
97 |
this.assemblyElement.removeChild(this.captionElement); |
|
98 |
||
99 |
// construct the button |
|
100 |
this.buttonElement = document.createElement("div"); |
|
101 |
this.tableElement = document.createElement("table"); |
|
102 |
this.tableRowElement = document.createElement("tr"); |
|
103 |
this.tableLeftCellElement = document.createElement("td"); |
|
104 |
this.tableRightCellElement = document.createElement("td"); |
|
105 |
this.imageElement = null; |
|
106 |
this.linkElement = document.createElement("a"); |
|
107 |
this.linkElement.href = "JavaScript:void(0)"; |
|
108 |
this.textElement = document.createElement("span"); |
|
109 |
this.tableElement.appendChild(this.tableRowElement); |
|
110 |
this.tableRowElement.appendChild(this.tableLeftCellElement); |
|
111 |
this.tableRowElement.appendChild(this.tableRightCellElement); |
|
112 |
this.tableRightCellElement.appendChild(this.linkElement); |
|
113 |
this.linkElement.appendChild(this.textElement); |
|
114 |
this.buttonElement.appendChild(this.tableElement); |
|
115 |
this.controlElement.appendChild(this.buttonElement); |
|
116 |
||
117 |
// set the image and text |
|
118 |
this.setImage(image); |
|
119 |
this.setText(text); |
|
120 |
||
121 |
// bind event listeners |
|
122 |
this.bindActionControlListeners(); |
|
123 |
||
124 |
// update the style |
|
125 |
this.updateStyleFromState(); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
126 |
}; |
73 | 127 |
|
128 |
// Sets the enabled state. |
|
129 |
NavigationButton.prototype.setEnabled = function(enabled) { |
|
130 |
uiLogger.debug("NavigationButton.setEnabled(" + enabled + ")"); |
|
131 |
||
132 |
// bail out early if there is no change in state |
|
133 |
if (this.enabled == enabled) { |
|
134 |
return; |
|
135 |
} |
|
136 |
||
137 |
// set the enabled state |
|
138 |
this.enabled = enabled; |
|
139 |
||
140 |
if (this.enabled) { |
|
141 |
// diabled -> enabled |
|
142 |
this.tableRightCellElement.removeChild(this.textElement); |
|
143 |
this.tableRightCellElement.appendChild(this.linkElement); |
|
144 |
this.linkElement.appendChild(this.textElement); |
|
145 |
} else { |
|
146 |
// enabled -> diabled |
|
147 |
this.linkElement.removeChild(this.textElement); |
|
148 |
this.tableRightCellElement.removeChild(this.linkElement); |
|
149 |
this.tableRightCellElement.appendChild(this.textElement); |
|
150 |
} |
|
151 |
||
152 |
// update the style |
|
153 |
this.updateStyleFromState(); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
154 |
}; |
73 | 155 |
|
156 |
// Returns the button image (URL); null if none. |
|
157 |
NavigationButton.prototype.getImage = function() { |
|
158 |
return (this.imageElement != null) ? this.imageElement.src : null; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
159 |
}; |
73 | 160 |
|
161 |
// Sets the button image (URL); null if none. |
|
162 |
NavigationButton.prototype.setImage = function(image) { |
|
163 |
uiLogger.debug("NavigationButton.setImage(" + image + ")"); |
|
164 |
||
165 |
if (image == null) { |
|
166 |
// remove image - if any |
|
167 |
if (this.imageElement != null) { |
|
168 |
this.tableLeftCellElement.removeChild(this.imageElement); |
|
169 |
} |
|
170 |
} else { |
|
171 |
// default to not append image element |
|
172 |
var append = false; |
|
173 |
||
174 |
// create image element if one doesn't exist |
|
175 |
if (this.imageElement == null) { |
|
176 |
this.imageElement = document.createElement("img"); |
|
177 |
this.imageElement.setAttribute("alt", ""); |
|
178 |
append = true; |
|
179 |
} |
|
180 |
||
181 |
// set image source URL |
|
182 |
this.imageElement.src = image; |
|
183 |
||
184 |
// append the image element to the left cell? |
|
185 |
if (append) { |
|
186 |
this.tableLeftCellElement.appendChild(this.imageElement); |
|
187 |
} |
|
188 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
189 |
}; |
73 | 190 |
|
191 |
// Returns the button text. |
|
192 |
NavigationButton.prototype.getText = function() { |
|
193 |
return this.textElement.innerHTML; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
194 |
}; |
73 | 195 |
|
196 |
// Sets the button text. |
|
197 |
NavigationButton.prototype.setText = function(text) { |
|
198 |
uiLogger.debug("NavigationButton.setText(" + text + ")"); |
|
199 |
this.textElement.innerHTML = (text == null) ? "" : text;; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
200 |
}; |
73 | 201 |
|
202 |
// Updates the style of the control to reflects the state of the control. |
|
203 |
NavigationButton.prototype.updateStyleFromState = function() { |
|
204 |
uiLogger.debug("NavigationButton.updateStyleFromState()"); |
|
205 |
||
206 |
// determine the state name |
|
207 |
var stateName = this.getStyleStateName(); |
|
208 |
||
209 |
// set root element class name |
|
210 |
this.setClassName(this.rootElement, "Control"); |
|
211 |
||
212 |
// set the control assembly class names |
|
213 |
this.setClassName(this.assemblyElement, "ControlAssembly ControlAssembly" + stateName); |
|
214 |
||
215 |
// control element |
|
216 |
this.setClassName(this.controlElement, "ControlElement NavigationButtonControlElement"); |
|
217 |
||
218 |
// set the button table class names |
|
219 |
this.setClassName(this.buttonElement, "NavigationButton"); |
|
220 |
this.setClassName(this.tableElement, "NavigationButtonTable"); |
|
221 |
this.setClassName(this.tableRowElement, "NavigationButtonRow"); |
|
222 |
this.setClassName(this.tableLeftCellElement, "NavigationButtonImageCell"); |
|
223 |
this.setClassName(this.tableRightCellElement, "NavigationButtonTextCell"); |
|
224 |
||
225 |
// set image class names |
|
226 |
if (this.imageElement) { |
|
227 |
this.setClassName(this.imageElement, "NavigationButtonImage"); |
|
228 |
} |
|
229 |
||
230 |
// set the button text class name |
|
231 |
this.setClassName(this.textElement, "NavigationButtonText NavigationButtonText" + stateName); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
232 |
}; |