Changed to MADDE; moved sb1 files to zouba.sb1 and made new zouba.madde for madde...
[ptas] / zouba.sb1 / wrt / 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(name){\r
49                 return _BRIDGE_REF.nokia.helper.readCookie(name);\r
50         }\r
51         \r
52         \r
53         /**\r
54          * Stores the key associated with the specified preference\r
55          * @param {String} Preference value to be stored\r
56          * @param {String} Key Preference value associated to\r
57          *     setPreferenceForKey()\r
58          * @return {Void}\r
59          */\r
60         widget.setPreferenceForKey = function(preference, key){\r
61                 _BRIDGE_REF.nokia.helper.createCookie(key, preference);\r
62         }\r
63         \r
64         \r
65         \r
66         /**\r
67          * Toggle between Tabbed navigation mode or Cursor mode\r
68          * @param {Boolean} Value\r
69          *     setNavigationEnabled()\r
70          * @return {Void}\r
71          */\r
72         widget.setNavigationEnabled = function(bool){\r
73                 //This function can not be used on preview browser\r
74         }\r
75         \r
76         \r
77         \r
78         /**\r
79          * Open S0-Application identified by UID along with the specified params\r
80          * @param {Integer} Uid hexadecimal value to a specified application\r
81          * @param {String} Value\r
82          *     openApplication()\r
83          * @return {Void}\r
84          */\r
85         widget.openApplication = function(Uid, param){\r
86                 alert("openApplication function won't be simulated in this application");\r
87         }\r
88         \r
89         \r
90         \r
91         /**\r
92          * Prepares the Widget.to do transition to specified transitionState\r
93          * @param {String} Value Transition state\r
94          *     prepareForTransition()\r
95          * @return {Void}\r
96          */\r
97         widget.prepareForTransition = function(transitionState){\r
98                 this.isFront = ("" + transitionState).toLowerCase() != "toback";\r
99                 window.document.getElementsByTagName("body")[0].style.opacity = "0.3";\r
100         }\r
101         \r
102         \r
103         \r
104         \r
105         /**\r
106          * Does the animation to make the transition between the specified transitionState\r
107          * @param {Void}\r
108          *     performTransition()\r
109          * @return {Void}\r
110          */\r
111         widget.performTransition = function(){\r
112                 var _self = this;\r
113                 this.opacity = 0;\r
114                 this.interval = window.setInterval(function(){\r
115                         _self.opacity += 0.2;\r
116                         if (_self.opacity > 1) {\r
117                                 _self.opacity = 1;\r
118                         }\r
119                         window.document.getElementsByTagName("body")[0].style.opacity = _self.opacity + "";\r
120                         if (_self.opacity >= 1) {\r
121                                 window.clearInterval(_self.interval);\r
122                                 window.document.getElementsByTagName("body")[0].style.opacity = "1";\r
123                         }\r
124                         //do nothing\r
125                 }, 50);\r
126                 //do nothing\r
127         }\r
128         \r
129         \r
130         \r
131         \r
132         \r
133         /**\r
134          * Set the preferred screen orientation to landscape.\r
135          * The display will flip if the phone display orientation\r
136          * is portrait and the phone supports landscape mode.\r
137          * @param {Void}\r
138          *     setDisplayLandscape()\r
139          * @return {Void}\r
140          */\r
141         widget.setDisplayLandscape = function(){\r
142                 try {\r
143                         if (this.isrotationsupported && _BRIDGE_REF.nokia.emulator.orientationSupports()) {\r
144                                 _BRIDGE_REF.nokia.emulator.setMode('landscape');\r
145                         }\r
146                 } \r
147                 catch (e) {\r
148                 }\r
149         }\r
150         \r
151         \r
152         \r
153         \r
154         /**\r
155          * Set the preferred screen orientation to portrait.\r
156          * The display will flip if the phone display orientation\r
157          * is landscape and the phone supports portrait mode.\r
158          * @param {Void}\r
159          *     setDisplayPortrait()\r
160          * @return {Void}\r
161          */\r
162         widget.setDisplayPortrait = function(){\r
163                 try {\r
164                         if (this.isrotationsupported && _BRIDGE_REF.nokia.emulator.orientationSupports()) {\r
165                                 _BRIDGE_REF.nokia.emulator.setMode('portrait');\r
166                         }\r
167                 } \r
168                 catch (e) {\r
169                 }\r
170         }\r
171         \r
172         /**\r
173          * Allows the definition of a function to be called\r
174          * when a Widget.is displayed\r
175          * @param {Void}\r
176          *     onshow()\r
177          * @return {Void}\r
178          */\r
179         widget.onshow = function(){\r
180                 // to be implemented\r
181         }\r
182         \r
183         \r
184         \r
185         \r
186         /**\r
187          * Allows the definition of a function to be called\r
188          * when a Widget.sent into the background (hidden)\r
189          * @param {Void}\r
190          *     onhide()\r
191          * @return {Void}\r
192          */\r
193         widget.onhide = function(){\r
194                 // to be implemented\r
195         }\r
196         \r
197         \r
198         \r
199         /**\r
200          * This function returns the System API if sysinfo is included in document embed\r
201          */\r
202         widget.enableSystemApi = function(){\r
203         \r
204                 //      Identify, and Attach System-Info-Object properties\r
205                 try {\r
206                         var parentIframeRef = window.parent.frames[0];\r
207                         if (typeof parentIframeRef == 'object') {\r
208                                 if (parentIframeRef.document.embeds.length > 0) {\r
209                                         for (var i = 0; i < parentIframeRef.document.embeds.length; i++) {\r
210                                                 //match the system Info API embed tag\r
211                                                 if (parentIframeRef.document.embeds[i].type == 'application/x-systeminfo-widget') {\r
212                                                         new systemAPI(parentIframeRef.document.embeds[i]);\r
213 //                                                      widget.sysInfo = parentIframeRef.document.embeds[i];\r
214                                                         \r
215                                                         // hide the <embed> object\r
216                                                         parentIframeRef.document.embeds[i].style.display='none';\r
217                                                         \r
218                                                         // push the reference object into widget\r
219                                                         widget.sysInfo.push(parentIframeRef.document.embeds[i]);\r
220                                                 }\r
221                                         }\r
222                                 }\r
223                         }\r
224                 } \r
225                 catch (e) {\r
226                         alert('Error in attachSysInfo: ' + e);\r
227                 }\r
228         }\r
229         \r
230         /**\r
231          * \r
232          */\r
233         \r
234         widget.triggerListener = function(provider, eventType, data){\r
235                 if(widget.sysInfo.length){\r
236                         for(var i=0; i<widget.sysInfo.length; i++){\r
237                                 if(provider == "power"){\r
238                                         switch(eventType){\r
239                                                 case "chargerconnected" : \r
240                                                                                                   widget.sysInfo[i].chargerconnected = data;\r
241                                                                                                   if(widget.sysInfo[i].onchargerconnected != null){\r
242                                                                                                         setTimeout(widget.sysInfo[i].onchargerconnected, 0);\r
243                                                                                                   }else{\r
244                                                                                                                 console.info("System API-1.0 Notice -- no listeners defined for eventType:"+eventType);\r
245                                                                                                   }\r
246                                                                                                   break;\r
247 \r
248                                                 case "chargelevel"              :\r
249                                                                                                   widget.sysInfo[i].chargelevel = data;\r
250                                                                                                   if(widget.sysInfo[i].onchargelevel != null){\r
251                                                                                                         setTimeout(widget.sysInfo[i].onchargelevel, 0);\r
252                                                                                                   }else{\r
253                                                                                                                 console.info("System API-1.0 Notice -- no listeners defined for eventType:"+eventType);\r
254                                                                                                   }\r
255                                                                                                  break;\r
256                                         }\r
257                                 }\r
258                         }\r
259                 }else{\r
260                         console.info("System API-1.0 Notice -- no listeners defined for eventType:"+eventType);\r
261                 }\r
262         }\r
263         \r
264         //      make TRUE widget.js script loaded\r
265         window.parent.NOKIA.scriptsLoaded.widget = true;\r
266 }\r
267 \r
268 (function(){\r
269 \r
270         //      attach the System-Info api specific functionality\r
271         _BRIDGE_REF.helper.addEvent(window, 'load', function(){\r
272                 widget.enableSystemApi();\r
273                 \r
274         });\r
275 \r
276         if (_BRIDGE_REF.nokia) {\r
277                 _BRIDGE_REF.nokia.menu.lsk_event = function(){\r
278                         _BRIDGE_REF.nokia.emulator.child.menu.show();\r
279                 };\r
280                 \r
281                 //      Add THIS window Reference on FRAME WINDOW\r
282                 //      NOKIA.emulator.child object reference\r
283                 _BRIDGE_REF.nokia.emulator.child = window;\r
284                 _BRIDGE_REF.nokia.menu.init();\r
285         }       \r
286 })()\r