org.symbian.tools.wrttools.previewer/preview/script/lib/loader.js
changeset 37 641b65b14318
child 210 0f7abfd6ae62
equal deleted inserted replaced
35:ec3f1313ae92 37:641b65b14318
       
     1 /*
       
     2  * Emulator, which manages the device interacations
       
     3  */
       
     4 if (typeof _BRIDGE_REF == "undefined" || !_BRIDGE_REF) {
       
     5 
       
     6 	var _BRIDGE_REF = {
       
     7 		parent: window.parent || false,
       
     8 		nokia: window.parent.NOKIA || false,
       
     9 		sysInfoObject : null
       
    10 	};
       
    11 
       
    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]] = {};
       
    18 			}
       
    19 			current = current[parts[key]];
       
    20 		}
       
    21 	};
       
    22 	
       
    23 	/*
       
    24 	 * _BRIDGE_REF.helper functions
       
    25 	 */
       
    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");
       
    32 			
       
    33 			script.type = "text/javascript";
       
    34 			script.src = path;
       
    35 			head.appendChild(script);
       
    36 		},
       
    37 		
       
    38 		addEvent: function(obj, type, fn){
       
    39 			if (obj.addEventListener) {
       
    40 				obj.addEventListener(type, fn, false);
       
    41 			}
       
    42 			else 
       
    43 				if (obj.attachEvent) {
       
    44 					obj["e" + type + fn] = fn;
       
    45 					obj[type + fn] = function(){
       
    46 						obj["e" + type + fn](window.event);
       
    47 					}
       
    48 					obj.attachEvent("on" + type, obj[type + fn]);
       
    49 				}
       
    50 		},
       
    51 		
       
    52 		getElementsLengthInObject : function(items){
       
    53 			var count = 0;
       
    54 			for (var i in items) 
       
    55 				count++;
       
    56 			
       
    57 			return count;
       
    58 		},
       
    59 		
       
    60 		getBatteryStrength : function(){
       
    61 			
       
    62 		},
       
    63 		
       
    64 		console : function(){
       
    65 			if (!typeof window.console) {
       
    66 				_BRIDGE_REF.helper.loadScript("preview/script/lib/console.js");
       
    67 			}			
       
    68 		}
       
    69 		
       
    70 	};
       
    71 	
       
    72 	
       
    73 	/*
       
    74 	 Load Scripts
       
    75 	 */
       
    76 	_BRIDGE_REF.helper.loadScript("preview/script/lib/widget.js");
       
    77 	_BRIDGE_REF.helper.loadScript("preview/script/lib/systeminfo.js");
       
    78 	_BRIDGE_REF.helper.loadScript("preview/script/lib/menu.js");
       
    79 	_BRIDGE_REF.helper.loadScript("preview/script/lib/menuItem.js");
       
    80 	_BRIDGE_REF.helper.loadScript("preview/script/lib/console.js");
       
    81 
       
    82 	//	Inject SAPI scripts	
       
    83 	if (_BRIDGE_REF.nokia) {
       
    84 		var wrtVersion = _BRIDGE_REF.nokia.helper.readCookie('_WRT_VERSION');
       
    85 		if ((typeof wrtVersion == 'undefined') || (wrtVersion == 'WRT 1.1')) {
       
    86 			_BRIDGE_REF.nokia.version = 'WRT 1.1';
       
    87 			_BRIDGE_REF.nokia.helper.createCookie('_WRT_VERSION', 'WRT 1.1');
       
    88 			_BRIDGE_REF.helper.loadScript("preview/script/lib/device.js");
       
    89 		}
       
    90 		else {
       
    91 			_BRIDGE_REF.nokia.version = 'WRT 1.0';
       
    92 		}
       
    93 	}
       
    94 	else {
       
    95 		_BRIDGE_REF.helper.loadScript("preview/script/lib/device.js");
       
    96 	}
       
    97 
       
    98 	/*
       
    99 	 window native functions over-riding
       
   100 	 */
       
   101 	if ( (typeof window.frameElement != 'undefined') && (typeof _BRIDGE_REF.nokia  != 'undefined') && window !== window.parent) {
       
   102 		//	alert
       
   103 		window.alert = function(msg){
       
   104 			return window.parent.alert(msg);
       
   105 		};
       
   106 		
       
   107 		//	confirm
       
   108 		window.confirm = function(msg){
       
   109 			return window.parent.confirm(msg);
       
   110 		};
       
   111 		
       
   112 		//	prompt
       
   113 		window.prompt = function(msg, str){
       
   114 			return window.parent.prompt(msg, str)
       
   115 		};
       
   116 	}
       
   117 
       
   118 	//	make TRUE loader.js script loaded
       
   119 	window.parent.NOKIA.scriptsLoaded.loader = true;
       
   120 
       
   121 }