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(key){
\r
50 var name = key; //"Nokia_WRT#" + this.path + "#" + key;
\r
52 var result = _BRIDGE_REF.helper.readCookie(name);
\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
64 widget.setPreferenceForKey = function(preference, key){
\r
66 //Specifying null for the preference parameter removes the specified key from the preferences
\r
68 if (this.preferenceKey > 0) {
\r
69 this.preferenceKey--;
\r
71 //delete from cookies
\r
73 value = key;//"Nokia_WRT#" + this.path + "#" + key;
\r
74 this.preferenceArray[this.preferenceKey] = value;
\r
76 _BRIDGE_REF.helper.createCookie(value, preference, 240000);
\r
77 this.preferenceKey++;
\r
79 //save cookie for cookies
\r
80 _BRIDGE_REF.helper.updateMainCookie(document);
\r
86 * Toggle between Tabbed navigation mode or Cursor mode
\r
87 * @param {Boolean} Value
\r
88 * setNavigationEnabled()
\r
91 widget.setNavigationEnabled = function(bool){
\r
92 //This function can not be used on preview browser
\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
104 widget.openApplication = function(Uid, param){
\r
105 alert("openApplication function won't be simulated in this application");
\r
111 * Prepares the Widget.to do transition to specified transitionState
\r
112 * @param {String} Value Transition state
\r
113 * prepareForTransition()
\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
125 * Does the animation to make the transition between the specified transitionState
\r
127 * performTransition()
\r
130 widget.performTransition = function(){
\r
133 this.interval = window.setInterval(function(){
\r
134 _self.opacity += 0.2;
\r
135 if (_self.opacity > 1) {
\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
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
157 * setDisplayLandscape()
\r
160 widget.setDisplayLandscape = function(){
\r
162 if (this.isrotationsupported && _BRIDGE_REF.nokia.emulator.orientationSupports()) {
\r
163 _BRIDGE_REF.nokia.emulator.setMode('landscape');
\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
178 * setDisplayPortrait()
\r
181 widget.setDisplayPortrait = function(){
\r
183 if (this.isrotationsupported && _BRIDGE_REF.nokia.emulator.orientationSupports()) {
\r
184 _BRIDGE_REF.nokia.emulator.setMode('portrait');
\r
192 * Allows the definition of a function to be called
\r
193 * when a Widget.is displayed
\r
198 widget.onshow = function(){
\r
199 // to be implemented
\r
206 * Allows the definition of a function to be called
\r
207 * when a Widget.sent into the background (hidden)
\r
212 widget.onhide = function(){
\r
213 // to be implemented
\r
219 * This function returns the System API if sysinfo is included in document embed
\r
221 widget.enableSystemApi = function(){
\r
223 // Identify, and Attach System-Info-Object properties
\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
234 // hide the <embed> object
\r
235 parentIframeRef.document.embeds[i].style.display='none';
\r
237 // push the reference object into widget
\r
238 widget.sysInfo.push(parentIframeRef.document.embeds[i]);
\r
245 alert('Error in attachSysInfo: ' + e);
\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
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
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
279 // make TRUE widget.js script loaded
\r
280 window.parent.NOKIA.scriptsLoaded.widget = true;
\r
285 // attach the System-Info api specific functionality
\r
286 _BRIDGE_REF.helper.addEvent(window, 'load', function(){
\r
287 widget.enableSystemApi();
\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
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