Added wrt files, prior to converting into Qt/C++.
[ptas] / wrt / misc / rss / preview / script / lib / widget.js
1 /**\r
2  * widget object constructor\r
3  * @param {void}\r
4  *     widget()\r
5  * @return {void}\r
6  */ \r
7 \r
8 if (typeof window.widget == "undefined" || !window.widget) {\r
9         window.widget = {\r
10                 author : 'Nokia WRT Emulation Library',\r
11                 //      widget identifier, dummy value\r
12                 identifier: 14021981,\r
13                 isrotationsupported: true,\r
14                 \r
15                 //      widget event triggers\r
16                 onshow: null,\r
17                 onhide: null,\r
18                 \r
19                 sysInfo: [],\r
20                 onload: null,\r
21                 opacity: 50,\r
22                 interval: 20,\r
23                 isFront: false,\r
24                 preferenceArray: [],\r
25                 preferenceKey: 0\r
26         };\r
27         \r
28         \r
29         /**\r
30          * Launches the browser with the specified url\r
31          * @param {String} url\r
32          *     openURL()\r
33          * @return {Void}\r
34          */\r
35         widget.openURL = function(url){\r
36                 if (url) {\r
37                         window.open(url, "New Widget Window", 'height=200 width=250');\r
38                 }\r
39         }\r
40         \r
41         \r
42         /**\r
43          * Returns previously stored preference associated with the specified key\r
44          * @param {String} Key preference value to be fetch\r
45          *     preferenceForKey()\r
46          * @return {String} Value\r
47          */\r
48         widget.preferenceForKey = function(key){\r
49 \r
50                 var name = key; //"Nokia_WRT#" + this.path + "#" + key;\r
51 \r
52                 var result = _BRIDGE_REF.helper.readCookie(name);\r
53                 return result;\r
54         }\r
55         \r
56         \r
57         /**\r
58          * Stores the key associated with the specified preference\r
59          * @param {String} Preference value to be stored\r
60          * @param {String} Key Preference value associated to\r
61          *     setPreferenceForKey()\r
62          * @return {Void}\r
63          */\r
64         widget.setPreferenceForKey = function(preference, key){\r
65                 var value;\r
66                 //Specifying null for the preference parameter removes the specified key from the preferences\r
67                 if (key == null) {\r
68                         if (this.preferenceKey > 0) {\r
69                                 this.preferenceKey--;\r
70                         }\r
71                         //delete from cookies\r
72                 }\r
73                 value = key;//"Nokia_WRT#" + this.path + "#" + key;\r
74                 this.preferenceArray[this.preferenceKey] = value;\r
75                 \r
76                 _BRIDGE_REF.helper.createCookie(value, preference, 240000);\r
77                 this.preferenceKey++;\r
78                 \r
79                 //save cookie for cookies\r
80                 _BRIDGE_REF.helper.updateMainCookie(document);\r
81         }\r
82         \r
83         \r
84         \r
85         /**\r
86          * Toggle between Tabbed navigation mode or Cursor mode\r
87          * @param {Boolean} Value\r
88          *     setNavigationEnabled()\r
89          * @return {Void}\r
90          */\r
91         widget.setNavigationEnabled = function(bool){\r
92                 //This function can not be used on preview browser\r
93         }\r
94         \r
95         \r
96         \r
97         /**\r
98          * Open S0-Application identified by UID along with the specified params\r
99          * @param {Integer} Uid hexadecimal value to a specified application\r
100          * @param {String} Value\r
101          *     openApplication()\r
102          * @return {Void}\r
103          */\r
104         widget.openApplication = function(Uid, param){\r
105                 alert("openApplication function won't be simulated in this application");\r
106         }\r
107         \r
108         \r
109         \r
110         /**\r
111          * Prepares the Widget.to do transition to specified transitionState\r
112          * @param {String} Value Transition state\r
113          *     prepareForTransition()\r
114          * @return {Void}\r
115          */\r
116         widget.prepareForTransition = function(transitionState){\r
117                 this.isFront = ("" + transitionState).toLowerCase() != "toback";\r
118                 window.document.getElementsByTagName("body")[0].style.opacity = "0.3";\r
119         }\r
120         \r
121         \r
122         \r
123         \r
124         /**\r
125          * Does the animation to make the transition between the specified transitionState\r
126          * @param {Void}\r
127          *     performTransition()\r
128          * @return {Void}\r
129          */\r
130         widget.performTransition = function(){\r
131                 var _self = this;\r
132                 this.opacity = 0;\r
133                 this.interval = window.setInterval(function(){\r
134                         _self.opacity += 0.2;\r
135                         if (_self.opacity > 1) {\r
136                                 _self.opacity = 1;\r
137                         }\r
138                         window.document.getElementsByTagName("body")[0].style.opacity = _self.opacity + "";\r
139                         if (_self.opacity >= 1) {\r
140                                 window.clearInterval(_self.interval);\r
141                                 window.document.getElementsByTagName("body")[0].style.opacity = "1";\r
142                         }\r
143                         //do nothing\r
144                 }, 50);\r
145                 //do nothing\r
146         }\r
147         \r
148         \r
149         \r
150         \r
151         \r
152         /**\r
153          * Set the preferred screen orientation to landscape.\r
154          * The display will flip if the phone display orientation\r
155          * is portrait and the phone supports landscape mode.\r
156          * @param {Void}\r
157          *     setDisplayLandscape()\r
158          * @return {Void}\r
159          */\r
160         widget.setDisplayLandscape = function(){\r
161                 try {\r
162                         if (this.isrotationsupported && _BRIDGE_REF.nokia.emulator.orientationSupports()) {\r
163                                 _BRIDGE_REF.nokia.emulator.setMode('landscape');\r
164                         }\r
165                 } \r
166                 catch (e) {\r
167                 }\r
168         }\r
169         \r
170         \r
171         \r
172         \r
173         /**\r
174          * Set the preferred screen orientation to portrait.\r
175          * The display will flip if the phone display orientation\r
176          * is landscape and the phone supports portrait mode.\r
177          * @param {Void}\r
178          *     setDisplayPortrait()\r
179          * @return {Void}\r
180          */\r
181         widget.setDisplayPortrait = function(){\r
182                 try {\r
183                         if (this.isrotationsupported && _BRIDGE_REF.nokia.emulator.orientationSupports()) {\r
184                                 _BRIDGE_REF.nokia.emulator.setMode('portrait');\r
185                         }\r
186                 } \r
187                 catch (e) {\r
188                 }\r
189         }\r
190         \r
191         /**\r
192          * Allows the definition of a function to be called\r
193          * when a Widget.is displayed\r
194          * @param {Void}\r
195          *     onshow()\r
196          * @return {Void}\r
197          */\r
198         widget.onshow = function(){\r
199                 // to be implemented\r
200         }\r
201         \r
202         \r
203         \r
204         \r
205         /**\r
206          * Allows the definition of a function to be called\r
207          * when a Widget.sent into the background (hidden)\r
208          * @param {Void}\r
209          *     onhide()\r
210          * @return {Void}\r
211          */\r
212         widget.onhide = function(){\r
213                 // to be implemented\r
214         }\r
215         \r
216         \r
217         \r
218         /**\r
219          * This function returns the System API if sysinfo is included in document embed\r
220          */\r
221         widget.enableSystemApi = function(){\r
222         \r
223                 //      Identify, and Attach System-Info-Object properties\r
224                 try {\r
225                         var parentIframeRef = window.parent.frames[0];\r
226                         if (typeof parentIframeRef == 'object') {\r
227                                 if (parentIframeRef.document.embeds.length > 0) {\r
228                                         for (var i = 0; i < parentIframeRef.document.embeds.length; i++) {\r
229                                                 //match the system Info API embed tag\r
230                                                 if (parentIframeRef.document.embeds[i].type == 'application/x-systeminfo-widget') {\r
231                                                         new systemAPI(parentIframeRef.document.embeds[i]);\r
232 //                                                      widget.sysInfo = parentIframeRef.document.embeds[i];\r
233                                                         \r
234                                                         // hide the <embed> object\r
235                                                         parentIframeRef.document.embeds[i].style.display='none';\r
236                                                         \r
237                                                         // push the reference object into widget\r
238                                                         widget.sysInfo.push(parentIframeRef.document.embeds[i]);\r
239                                                 }\r
240                                         }\r
241                                 }\r
242                         }\r
243                 } \r
244                 catch (e) {\r
245                         alert('Error in attachSysInfo: ' + e);\r
246                 }\r
247         }\r
248         \r
249         /**\r
250          * \r
251          */\r
252         \r
253         widget.triggerListener = function(provider, eventType, data){\r
254                 if(widget.sysInfo.length){\r
255                         for(var i=0; i<widget.sysInfo.length; i++){\r
256                                 if(provider == "power"){\r
257                                         switch(eventType){\r
258                                                 case "chargerconnected" : \r
259                                                                                                   widget.sysInfo[i].chargerconnected = data;\r
260                                                                                                   if(typeof widget.sysInfo[i].onchargerconnected != 'undefined'){\r
261                                                                                                         // widget.sysInfo[i].onchargerconnected();\r
262                                                                                                         setTimeout(widget.sysInfo[i].onchargerconnected, 0);\r
263                                                                                                   }\r
264                                                                                                   break;\r
265 \r
266                                                 case "chargelevel"              :\r
267                                                                                                   widget.sysInfo[i].chargelevel = data;\r
268                                                                                                   if(typeof widget.sysInfo[i].onchargelevel != 'undefined'){\r
269                                                                                                         // widget.sysInfo[i].onchargelevel();\r
270                                                                                                         setTimeout(widget.sysInfo[i].onchargelevel, 0);\r
271                                                                                                   }\r
272                                                                                                  break;\r
273                                         }\r
274                                 }\r
275                         }\r
276                 }\r
277         }\r
278         \r
279         //      make TRUE widget.js script loaded\r
280         window.parent.NOKIA.scriptsLoaded.widget = true;\r
281 }\r
282 \r
283 (function(){\r
284 \r
285         //      attach the System-Info api specific functionality\r
286         _BRIDGE_REF.helper.addEvent(window, 'load', function(){\r
287                 widget.enableSystemApi();\r
288                 \r
289         });\r
290 \r
291         if (_BRIDGE_REF.nokia) {\r
292                 _BRIDGE_REF.nokia.menu.lsk_event = function(){\r
293                         _BRIDGE_REF.nokia.emulator.child.menu.show();\r
294                 };\r
295                 \r
296                 //      Add THIS window Reference on FRAME WINDOW\r
297                 //      NOKIA.emulator.child object reference\r
298                 _BRIDGE_REF.nokia.emulator.child = window;\r
299                 _BRIDGE_REF.nokia.menu.init();\r
300         }       \r
301 })()\r