|
1 /** |
|
2 * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** |
|
19 * widget object constructor |
|
20 * @param {void} |
|
21 * widget() |
|
22 * @return {void} |
|
23 */ |
|
24 |
|
25 if (typeof window.widget == "undefined" || !window.widget) { |
|
26 window.widget = { |
|
27 author : 'Nokia WRT Emulation Library', |
|
28 // widget identifier, dummy value |
|
29 identifier: 14021981, |
|
30 isrotationsupported: true, |
|
31 |
|
32 // widget event triggers |
|
33 onshow: null, |
|
34 onhide: null, |
|
35 |
|
36 sysInfo: [], |
|
37 onload: null, |
|
38 opacity: 50, |
|
39 interval: 20, |
|
40 isFront: false, |
|
41 preferenceArray: [], |
|
42 preferenceKey: 0, |
|
43 wrt : { |
|
44 version : "1.1", |
|
45 platform : { |
|
46 id : "S60", |
|
47 romVersion : "V 31.0.101 16-09-2009 RM-356 (C) NMP", |
|
48 manufacturer : "Nokia", |
|
49 packageVersion : "7.00(0)", |
|
50 model : "5800 XpressMusic" |
|
51 } |
|
52 } |
|
53 }; |
|
54 |
|
55 |
|
56 /** |
|
57 * Launches the browser with the specified url |
|
58 * @param {String} url |
|
59 * openURL() |
|
60 * @return {Void} |
|
61 */ |
|
62 widget.openURL = function(url){ |
|
63 if (url) { |
|
64 if (url.substring(0, 4) == "tel:") { |
|
65 var sz = "Number " + url.substring(4) + " was dialed"; |
|
66 window.alert(sz); |
|
67 } else { |
|
68 _BRIDGE_REF.nokia.layout.openApplication("preview/images/webbrowser.png", url); |
|
69 } |
|
70 } |
|
71 }; |
|
72 |
|
73 |
|
74 /** |
|
75 * Returns previously stored preference associated with the specified key |
|
76 * @param {String} Key preference value to be fetch |
|
77 * preferenceForKey() |
|
78 * @return {String} Value |
|
79 */ |
|
80 widget.preferenceForKey = function(name){ |
|
81 return _BRIDGE_REF.nokia.helper.getPreference(name); |
|
82 }; |
|
83 |
|
84 |
|
85 /** |
|
86 * Stores the key associated with the specified preference |
|
87 * @param {String} Preference value to be stored |
|
88 * @param {String} Key Preference value associated to |
|
89 * setPreferenceForKey() |
|
90 * @return {Void} |
|
91 */ |
|
92 widget.setPreferenceForKey = function(preference, key){ |
|
93 _BRIDGE_REF.nokia.helper.setPreference(key, preference); |
|
94 }; |
|
95 |
|
96 |
|
97 |
|
98 /** |
|
99 * Toggle between Tabbed navigation mode or Cursor mode |
|
100 * @param {Boolean} Value |
|
101 * setNavigationEnabled() |
|
102 * @return {Void} |
|
103 */ |
|
104 widget.setNavigationEnabled = function(bool){ |
|
105 //This function can not be used on preview browser |
|
106 }; |
|
107 |
|
108 |
|
109 |
|
110 /** |
|
111 * Open S0-Application identified by UID along with the specified params |
|
112 * @param {Integer} Uid hexadecimal value to a specified application |
|
113 * @param {String} Value |
|
114 * openApplication() |
|
115 * @return {Void} |
|
116 */ |
|
117 widget.openApplication = function(Uid, param){ |
|
118 if (Uid == 270501242) { // Camera |
|
119 _BRIDGE_REF.nokia.layout.openApplication("preview/images/camera.png"); |
|
120 } else { |
|
121 _BRIDGE_REF.nokia.layout.openApplication("Application UID: " + Uid + "Parameters are: " + param); |
|
122 } |
|
123 }; |
|
124 |
|
125 |
|
126 |
|
127 /** |
|
128 * Prepares the Widget.to do transition to specified transitionState |
|
129 * @param {String} Value Transition state |
|
130 * prepareForTransition() |
|
131 * @return {Void} |
|
132 */ |
|
133 widget.prepareForTransition = function(transitionState){ |
|
134 this.isFront = ("" + transitionState).toLowerCase() != "toback"; |
|
135 window.document.getElementsByTagName("body")[0].style.opacity = "0.3"; |
|
136 }; |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 /** |
|
142 * Does the animation to make the transition between the specified transitionState |
|
143 * @param {Void} |
|
144 * performTransition() |
|
145 * @return {Void} |
|
146 */ |
|
147 widget.performTransition = function(){ |
|
148 var _self = this; |
|
149 this.opacity = 0; |
|
150 this.interval = window.setInterval(function(){ |
|
151 _self.opacity += 0.2; |
|
152 if (_self.opacity > 1) { |
|
153 _self.opacity = 1; |
|
154 } |
|
155 window.document.getElementsByTagName("body")[0].style.opacity = _self.opacity + ""; |
|
156 if (_self.opacity >= 1) { |
|
157 window.clearInterval(_self.interval); |
|
158 window.document.getElementsByTagName("body")[0].style.opacity = "1"; |
|
159 } |
|
160 //do nothing |
|
161 }, 50); |
|
162 //do nothing |
|
163 }; |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 /** |
|
170 * Set the preferred screen orientation to landscape. |
|
171 * The display will flip if the phone display orientation |
|
172 * is portrait and the phone supports landscape mode. |
|
173 * @param {Void} |
|
174 * setDisplayLandscape() |
|
175 * @return {Void} |
|
176 */ |
|
177 widget.setDisplayLandscape = function(){ |
|
178 try { |
|
179 if (this.isrotationsupported && _BRIDGE_REF.nokia.emulator.orientationSupports()) { |
|
180 _BRIDGE_REF.nokia.emulator.setMode('landscape'); |
|
181 } |
|
182 } |
|
183 catch (e) { |
|
184 } |
|
185 }; |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 /** |
|
191 * Set the preferred screen orientation to portrait. |
|
192 * The display will flip if the phone display orientation |
|
193 * is landscape and the phone supports portrait mode. |
|
194 * @param {Void} |
|
195 * setDisplayPortrait() |
|
196 * @return {Void} |
|
197 */ |
|
198 widget.setDisplayPortrait = function(){ |
|
199 try { |
|
200 if (this.isrotationsupported && _BRIDGE_REF.nokia.emulator.orientationSupports()) { |
|
201 _BRIDGE_REF.nokia.emulator.setMode('portrait'); |
|
202 } |
|
203 } |
|
204 catch (e) { |
|
205 } |
|
206 }; |
|
207 |
|
208 /** |
|
209 * Allows the definition of a function to be called |
|
210 * when a Widget.is displayed |
|
211 * @param {Void} |
|
212 * onshow() |
|
213 * @return {Void} |
|
214 */ |
|
215 widget.onshow = function(){ |
|
216 // to be implemented |
|
217 }; |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 /** |
|
223 * Allows the definition of a function to be called |
|
224 * when a Widget.sent into the background (hidden) |
|
225 * @param {Void} |
|
226 * onhide() |
|
227 * @return {Void} |
|
228 */ |
|
229 widget.onhide = function(){ |
|
230 // to be implemented |
|
231 }; |
|
232 |
|
233 |
|
234 |
|
235 /** |
|
236 * This function returns the System API if sysinfo is included in document embed |
|
237 */ |
|
238 widget.enableSystemApi = function(){ |
|
239 |
|
240 // Identify, and Attach System-Info-Object properties |
|
241 try { |
|
242 var parentIframeRef = window.parent.frames[0]; |
|
243 if (typeof parentIframeRef == 'object') { |
|
244 if (parentIframeRef.document.embeds.length > 0) { |
|
245 for (var i = 0; i < parentIframeRef.document.embeds.length; i++) { |
|
246 //match the system Info API embed tag |
|
247 if (parentIframeRef.document.embeds[i].type == 'application/x-systeminfo-widget') { |
|
248 new systemAPI(parentIframeRef.document.embeds[i]); |
|
249 // widget.sysInfo = parentIframeRef.document.embeds[i]; |
|
250 |
|
251 // hide the <embed> object |
|
252 parentIframeRef.document.embeds[i].style.display='none'; |
|
253 |
|
254 // push the reference object into widget |
|
255 widget.sysInfo.push(parentIframeRef.document.embeds[i]); |
|
256 } |
|
257 } |
|
258 } |
|
259 } |
|
260 } |
|
261 catch (e) { |
|
262 alert('Error in attachSysInfo: ' + e); |
|
263 } |
|
264 }; |
|
265 |
|
266 /** |
|
267 * |
|
268 */ |
|
269 |
|
270 widget.triggerListener = function(provider, eventType, data){ |
|
271 if(widget.sysInfo.length){ |
|
272 for(var i=0; i<widget.sysInfo.length; i++){ |
|
273 if(provider == "power"){ |
|
274 switch(eventType){ |
|
275 case "chargerconnected" : |
|
276 widget.sysInfo[i].chargerconnected = data; |
|
277 if(widget.sysInfo[i].onchargerconnected != null){ |
|
278 setTimeout(widget.sysInfo[i].onchargerconnected, 0); |
|
279 }else{ |
|
280 console.info("System API-1.0 Notice -- no listeners defined for eventType:"+eventType); |
|
281 } |
|
282 break; |
|
283 |
|
284 case "chargelevel" : |
|
285 widget.sysInfo[i].chargelevel = data; |
|
286 if(widget.sysInfo[i].onchargelevel != null){ |
|
287 setTimeout(widget.sysInfo[i].onchargelevel, 0); |
|
288 }else{ |
|
289 console.info("System API-1.0 Notice -- no listeners defined for eventType:"+eventType); |
|
290 } |
|
291 break; |
|
292 } |
|
293 } |
|
294 } |
|
295 }else{ |
|
296 console.info("System API-1.0 Notice -- no listeners defined for eventType:"+eventType); |
|
297 } |
|
298 }; |
|
299 |
|
300 // make TRUE widget.js script loaded |
|
301 window.parent.NOKIA.scriptsLoaded.widget = true; |
|
302 } |
|
303 |
|
304 (function(){ |
|
305 |
|
306 // attach the System-Info api specific functionality |
|
307 _BRIDGE_REF.helper.addEvent(window, 'load', function(){ |
|
308 widget.enableSystemApi(); |
|
309 |
|
310 }); |
|
311 |
|
312 if (_BRIDGE_REF.nokia) { |
|
313 _BRIDGE_REF.nokia.menu.lsk_event = function(){ |
|
314 _BRIDGE_REF.nokia.emulator.child.menu.show(); |
|
315 }; |
|
316 |
|
317 // Add THIS window Reference on FRAME WINDOW |
|
318 // NOKIA.emulator.child object reference |
|
319 _BRIDGE_REF.nokia.emulator.child = window; |
|
320 _BRIDGE_REF.nokia.menu.init(); |
|
321 } |
|
322 })(); |