2 * widget object constructor
\r
8 if (typeof window.widget == "undefined" || !window.widget) {
\r
10 author : 'Nokia WRT Emulation Library',
\r
11 // widget identifier, dummy value
\r
12 identifier: 14021981,
\r
13 isrotationsupported: true,
\r
15 // widget event triggers
\r
24 preferenceArray: [],
\r
30 * Launches the browser with the specified url
\r
31 * @param {String} url
\r
35 widget.openURL = function(url){
\r
37 window.open(url, "New Widget Window", 'height=200 width=250');
\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
48 widget.preferenceForKey = function(name){
\r
49 return _BRIDGE_REF.nokia.helper.readCookie(name);
\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
60 widget.setPreferenceForKey = function(preference, key){
\r
61 _BRIDGE_REF.nokia.helper.createCookie(key, preference);
\r
67 * Toggle between Tabbed navigation mode or Cursor mode
\r
68 * @param {Boolean} Value
\r
69 * setNavigationEnabled()
\r
72 widget.setNavigationEnabled = function(bool){
\r
73 //This function can not be used on preview browser
\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
85 widget.openApplication = function(Uid, param){
\r
86 alert("openApplication function won't be simulated in this application");
\r
92 * Prepares the Widget.to do transition to specified transitionState
\r
93 * @param {String} Value Transition state
\r
94 * prepareForTransition()
\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
106 * Does the animation to make the transition between the specified transitionState
\r
108 * performTransition()
\r
111 widget.performTransition = function(){
\r
114 this.interval = window.setInterval(function(){
\r
115 _self.opacity += 0.2;
\r
116 if (_self.opacity > 1) {
\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
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
138 * setDisplayLandscape()
\r
141 widget.setDisplayLandscape = function(){
\r
143 if (this.isrotationsupported && _BRIDGE_REF.nokia.emulator.orientationSupports()) {
\r
144 _BRIDGE_REF.nokia.emulator.setMode('landscape');
\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
159 * setDisplayPortrait()
\r
162 widget.setDisplayPortrait = function(){
\r
164 if (this.isrotationsupported && _BRIDGE_REF.nokia.emulator.orientationSupports()) {
\r
165 _BRIDGE_REF.nokia.emulator.setMode('portrait');
\r
173 * Allows the definition of a function to be called
\r
174 * when a Widget.is displayed
\r
179 widget.onshow = function(){
\r
180 // to be implemented
\r
187 * Allows the definition of a function to be called
\r
188 * when a Widget.sent into the background (hidden)
\r
193 widget.onhide = function(){
\r
194 // to be implemented
\r
200 * This function returns the System API if sysinfo is included in document embed
\r
202 widget.enableSystemApi = function(){
\r
204 // Identify, and Attach System-Info-Object properties
\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
215 // hide the <embed> object
\r
216 parentIframeRef.document.embeds[i].style.display='none';
\r
218 // push the reference object into widget
\r
219 widget.sysInfo.push(parentIframeRef.document.embeds[i]);
\r
226 alert('Error in attachSysInfo: ' + e);
\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
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
244 console.info("System API-1.0 Notice -- no listeners defined for eventType:"+eventType);
\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
253 console.info("System API-1.0 Notice -- no listeners defined for eventType:"+eventType);
\r
260 console.info("System API-1.0 Notice -- no listeners defined for eventType:"+eventType);
\r
264 // make TRUE widget.js script loaded
\r
265 window.parent.NOKIA.scriptsLoaded.widget = true;
\r
270 // attach the System-Info api specific functionality
\r
271 _BRIDGE_REF.helper.addEvent(window, 'load', function(){
\r
272 widget.enableSystemApi();
\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
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