mypackage_wrt/preview/script/lib/loader.js
author nithyar
Mon, 20 Sep 2010 13:47:38 +0100
changeset 61 3c5e0637d4d3
parent 42 20be4dd42b12
permissions -rwxr-xr-x
Integration plan updates, week37
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
     1
/*
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
     2
 * Emulator, which manages the device interacations
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
     3
 */
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
     4
if (typeof _BRIDGE_REF == "undefined" || !_BRIDGE_REF) {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
     5
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
     6
	var _BRIDGE_REF = {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
     7
		parent: window.parent || false,
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
     8
		nokia: window.parent.NOKIA || false,
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
     9
		sysInfoObject : null
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    10
	};
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    11
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    12
	_BRIDGE_REF.namespace = function(name){
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    13
		var parts = name.split('.');
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    14
		var current = _BRIDGE_REF;
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    15
		for (var key in parts) {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    16
			if (!current[parts[key]]) {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    17
				current[parts[key]] = {};
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    18
			}
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    19
			current = current[parts[key]];
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    20
		}
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    21
	};
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    22
	
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    23
	/*
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    24
	 * _BRIDGE_REF.helper functions
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    25
	 */
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    26
	_BRIDGE_REF.namespace('helper.loadScript');
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    27
	_BRIDGE_REF.helper = {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    28
		path: document.location.pathname,
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    29
		loadScript: function(path){
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    30
			var head = document.getElementsByTagName("head")[0] || document.documentElement;
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    31
			var script = document.createElement("script");
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    32
			
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    33
			script.type = "text/javascript";
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    34
			script.src = path;
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    35
			head.appendChild(script);
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    36
		},
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    37
		
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    38
		addEvent: function(obj, type, fn){
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    39
			if (obj.addEventListener) {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    40
				obj.addEventListener(type, fn, false);
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    41
			}
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    42
			else 
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    43
				if (obj.attachEvent) {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    44
					obj["e" + type + fn] = fn;
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    45
					obj[type + fn] = function(){
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    46
						obj["e" + type + fn](window.event);
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    47
					}
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    48
					obj.attachEvent("on" + type, obj[type + fn]);
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    49
				}
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    50
		},
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    51
		
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    52
		getElementsLengthInObject : function(items){
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    53
			var count = 0;
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    54
			for (var i in items) 
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    55
				count++;
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    56
			
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    57
			return count;
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    58
		},
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    59
		
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    60
		getBatteryStrength : function(){
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    61
			
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    62
		},
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    63
		
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    64
		console : function(){
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    65
			if (!typeof window.console) {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    66
				_BRIDGE_REF.helper.loadScript("preview/script/lib/console.js");
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    67
			}			
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    68
		}
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    69
		
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    70
	};
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    71
	
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    72
	
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    73
	/*
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    74
	 Load Scripts
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    75
	 */
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    76
	_BRIDGE_REF.helper.loadScript("preview/script/lib/widget.js");
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    77
	_BRIDGE_REF.helper.loadScript("preview/script/lib/systeminfo.js");
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    78
	_BRIDGE_REF.helper.loadScript("preview/script/lib/menu.js");
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    79
	_BRIDGE_REF.helper.loadScript("preview/script/lib/menuItem.js");
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    80
	_BRIDGE_REF.helper.loadScript("preview/script/lib/console.js");
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    81
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    82
	//	Inject SAPI scripts	
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    83
	if (_BRIDGE_REF.nokia) {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    84
		var wrtVersion = _BRIDGE_REF.nokia.helper.readCookie('_WRT_VERSION');
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    85
		if ((typeof wrtVersion == 'undefined') || (wrtVersion == 'WRT 1.1')) {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    86
			_BRIDGE_REF.nokia.version = 'WRT 1.1';
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    87
			_BRIDGE_REF.nokia.helper.createCookie('_WRT_VERSION', 'WRT 1.1');
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    88
			_BRIDGE_REF.helper.loadScript("preview/script/lib/device.js");
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    89
		}
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    90
		else {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    91
			_BRIDGE_REF.nokia.version = 'WRT 1.0';
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    92
		}
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    93
	}
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    94
	else {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    95
		_BRIDGE_REF.helper.loadScript("preview/script/lib/device.js");
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    96
	}
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    97
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    98
	/*
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
    99
	 window native functions over-riding
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   100
	 */
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   101
	if ( (typeof window.frameElement != 'undefined') && (typeof _BRIDGE_REF.nokia  != 'undefined') && window !== window.parent) {
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   102
		//	alert
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   103
		window.alert = function(msg){
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   104
			return window.parent.alert(msg);
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   105
		};
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   106
		
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   107
		//	confirm
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   108
		window.confirm = function(msg){
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   109
			return window.parent.confirm(msg);
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   110
		};
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   111
		
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   112
		//	prompt
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   113
		window.prompt = function(msg, str){
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   114
			return window.parent.prompt(msg, str)
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   115
		};
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   116
	}
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   117
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   118
	//	make TRUE loader.js script loaded
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   119
	window.parent.NOKIA.scriptsLoaded.loader = true;
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   120
20be4dd42b12 My package widget code
victorp@symbian.org
parents:
diff changeset
   121
}