2 * Emulator, which manages the device interacations
4 if (typeof _BRIDGE_REF == "undefined" || !_BRIDGE_REF) {
7 parent: window.parent || false,
8 nokia: window.parent.NOKIA || false,
12 _BRIDGE_REF.namespace = function(name){
13 var parts = name.split('.');
14 var current = _BRIDGE_REF;
15 for (var key in parts) {
16 if (!current[parts[key]]) {
17 current[parts[key]] = {};
19 current = current[parts[key]];
24 * _BRIDGE_REF.helper functions
26 _BRIDGE_REF.namespace('helper.loadScript');
27 _BRIDGE_REF.helper = {
28 path: document.location.pathname,
29 loadScript: function(path){
30 var head = document.getElementsByTagName("head")[0] || document.documentElement;
31 var script = document.createElement("script");
33 script.type = "text/javascript";
35 head.appendChild(script);
38 createCookie: function(name, value){
41 var date = new Date();
42 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
43 var expires = "; expires=" + date.toGMTString();
47 var value = "Nokia_WRT#" + _BRIDGE_REF.helper.path + "#" + name + "=" + value;
48 document.cookie = value + expires + "; Emulator.path=/"
51 readCookie: function(name){
52 name = "Nokia_WRT#" + _BRIDGE_REF.helper.path + "#" + name;
53 var nameEQ = name + "=";
54 var ca = document.cookie.split(';');
55 for (var i = 0; i < ca.length; i++) {
57 while (c.charAt(0) == ' ')
58 c = c.substring(1, c.length);
59 if (c.indexOf(nameEQ) == 0) {
60 return c.substring(nameEQ.length, c.length);
66 updateMainCookie: function(doucment){
68 name = "Nokia_WRT#" + widget.path;
69 for (var k = 0; k < widget.preferenceArray.length; k++) {
70 temp = temp + "|" + widget.preferenceArray[k];
72 this.createCookie(document, name, temp, 24000);
75 addEvent: function(obj, type, fn){
76 if (obj.addEventListener) {
77 obj.addEventListener(type, fn, false);
80 if (obj.attachEvent) {
81 obj["e" + type + fn] = fn;
82 obj[type + fn] = function(){
83 obj["e" + type + fn](window.event);
85 obj.attachEvent("on" + type, obj[type + fn]);
89 getElementsLengthInObject : function(items){
97 getBatteryStrength : function(){
99 /* if(!_BRIDGE_REF.sysInfoObject)
100 _BRIDGE_REF.sysInfoObject = device.getServiceObject("Service.SysInfo", "ISysInfo");
102 var result = _BRIDGE_REF.sysInfoObject.ISysInfo.GetInfo({
104 Key : 'ChargingStatus'
107 if(!result.ErrorCode)
109 return result.Status;
112 alert('Error in getting Battery Strength: '+result.ErrorCode);
115 if(typeof device.implementation.data["Service.SysInfo"].default.battery.batterystrength.Status != 'undefined')
116 return device.implementation.data["Service.SysInfo"].default.battery.batterystrength.Status;
122 console : function(){
123 if (!typeof window.console) {
124 _BRIDGE_REF.helper.loadScript("preview/script/lib/console.js");
134 _BRIDGE_REF.helper.loadScript("preview/script/lib/widget.js");
135 _BRIDGE_REF.helper.loadScript("preview/script/lib/systeminfo.js");
136 _BRIDGE_REF.helper.loadScript("preview/script/lib/menu.js");
137 _BRIDGE_REF.helper.loadScript("preview/script/lib/menuItem.js");
138 _BRIDGE_REF.helper.loadScript("preview/script/lib/console.js");
140 // Inject SAPI scripts
141 if (_BRIDGE_REF.nokia) {
142 var wrtVersion = _BRIDGE_REF.nokia.helper.readCookie('_WRT_VERSION');
143 if ((typeof wrtVersion == 'undefined') || (wrtVersion == 'WRT 1.1')) {
144 _BRIDGE_REF.nokia.version = 'WRT 1.1';
145 _BRIDGE_REF.nokia.helper.createCookie('_WRT_VERSION', 'WRT 1.1');
146 _BRIDGE_REF.helper.loadScript("preview/script/lib/device.js");
149 _BRIDGE_REF.nokia.version = 'WRT 1.0';
153 _BRIDGE_REF.helper.loadScript("preview/script/lib/device.js");
157 window native functions over-riding
159 if ( (typeof window.frameElement != 'undefined') && (typeof _BRIDGE_REF.nokia != 'undefined') && window !== window.parent) {
161 window.alert = function(msg){
162 return window.parent.alert(msg);
166 window.confirm = function(msg){
167 return window.parent.confirm(msg);
171 window.prompt = function(msg, str){
172 return window.parent.prompt(msg, str)
176 // make TRUE loader.js script loaded
177 window.parent.NOKIA.scriptsLoaded.loader = true;