--- a/org.symbian.tools.wrttools.previewer/preview/script/nokia.js Mon Jun 28 10:47:32 2010 -0700
+++ b/org.symbian.tools.wrttools.previewer/preview/script/nokia.js Tue Jun 29 13:44:16 2010 -0700
@@ -127,7 +127,9 @@
this.helper.getInfo('Info.plist', NOKIA.helper.getInfoCallback);
// For getting Icon.png
- this.helper.getInfo('Icon.png', NOKIA.helper.getIconCallback);
+ this.helper.getInfo('Icon.png', NOKIA.helper.getIconCallback);
+
+ new RotationSupport(accelerationCallback);
};
/*
@@ -139,1325 +141,30 @@
NOKIA.deviceList = data;
};
-
-
/*
* NOKIA.emulator
*/
NOKIA.namespace('menu');
- NOKIA.menu = {
- is_menu_visible : false, // true/false
- is_softkeys_visible : false, // true : only when MenuItem's are displayed
- softkeys_visibility : true, // true/false : for hide/show SFK's
- is_dimmed : false,
- is_rsk_overridden : false,
- log_counter : 1,
- enable_log : false,
- rsk_label : '',
- rsk_event : false,
- highlighted_item : null,
-
- hide : function()
- {
- $("#MenuItemsArea").fadeIn("slow");
-
- // Hide the SFK's If user hidden them from his code
- if(NOKIA.menu.softkeys_visibility)
- $("#SoftKeysArea").fadeIn("slow");
-
- NOKIA.menu.is_softkeys_visible = false;
- },
-
- log : function(str)
- {
- if(!this.enable_log)
- return false;
- NOKIA.layout.log("log", NOKIA.menu.log_counter + ' ' +str);
- NOKIA.layout.log("log", 'is_rsk_overridden: '+NOKIA.menu.is_rsk_overridden);
- NOKIA.layout.log("log", 'rsk_label: '+NOKIA.menu.rsk_label);
- NOKIA.layout.log("log", 'rsk_event: '+NOKIA.menu.rsk_event);
-
- NOKIA.menu.log_counter++;
- },
-
- show : function()
- {
- if(NOKIA.menu.is_dimmed)
- return false;
-
- NOKIA.menu.showSoftKeys();
-
- NOKIA.menu.is_menu_visible = true;
- $("#MenuItemsArea").show();
-
- NOKIA.menu.highlighted_item = $("#MenuItemsArea > ul > li")[0];
- NOKIA.menu.highlighted_item.className = 'active';
-
-
- $("#MenuItemsArea > ul > li").mouseover(function(){
- if(NOKIA.menu.highlighted_item != null)
- {
- NOKIA.menu.highlighted_item.className = '';
- NOKIA.menu.highlighted_item = null;
- }
-
- NOKIA.menu.highlighted_item = this;
- NOKIA.menu.highlighted_item.className = 'active';
- });
-
- $("#SoftKeysArea").mouseout(function(){
- if (!NOKIA.menu.is_menu_visible) {
- return false;
- }
-
- if (NOKIA.helper.intervalId) {
- clearInterval(NOKIA.helper.intervalId);
- }
- NOKIA.helper.intervalId = setTimeout(function(){
- NOKIA.menu.cancel();
- }, 500);
- });
-
-
- // Change the label "Options" to "Select" to LSK
- $("#LskLabel > a")[0].innerHTML = "Select";
- NOKIA.menu.setLsk(NOKIA.menu.selectMenu);
-
- // Change the label "Exit" to "Cancel" to RSK
- $("#RskLabel > a")[0].innerHTML = 'Cancel';
- NOKIA.menu.setRsk(NOKIA.menu.cancel);
-
-
- NOKIA.emulator.setMenuItemsStyle();
-
- },
-
- selectMenu : function(){
- try {
- if(typeof NOKIA.menu.highlighted_item.onclick != 'undefined'){
- eval(NOKIA.menu.highlighted_item.onclick)();
- }
- } catch (e) {
-
- }
-// NOKIA.menu.cancel();
- },
-
-
- cancel : function()
- {
- if(NOKIA.menu.is_dimmed)
- return false;
-
- NOKIA.menu.hideSoftKeys();
-
- NOKIA.menu.is_menu_visible = false;
- $("#MenuItemsArea").hide();
-
- // Reset the "OPTION" label to LSK
- $("#LskLabel > a")[0].innerHTML = 'Options';
- NOKIA.menu.setLsk(NOKIA.emulator.child.menu.show);
-
- // Change the label "CANCEL" to "EXIT" to RSK
- if(!NOKIA.menu.is_rsk_overridden)
- {
- $("#RskLabel > a")[0].innerHTML = 'Exit';
- NOKIA.menu.setRsk(NOKIA.menu.exit);
- }
- else
- {
- $("#RskLabel > a")[0].innerHTML = NOKIA.menu.rsk_label;
- NOKIA.menu.setRsk(NOKIA.menu.rsk_event);
- }
-
- },
-
- exit : function()
- {
- if(NOKIA.menu.is_dimmed)
- return false;
-
- if(NOKIA.helper.setHomeScreen())
- return false;
-
- // clear the Menu Settings
- NOKIA.menu.cancel();
- NOKIA.emulator.child.menu.setRightSoftkeyLabel('', null);
- NOKIA.emulator.child.menu.items = [];
- NOKIA.menu.softkeys_visibility = false;
-
- // Hide Widget DIV
- NOKIA.menu.hideSoftKeys();
- NOKIA.menu.setLsk(function(){});
- NOKIA.menu.setRsk(function(){});
-
- $("#WidgetArea").hide();
-
- // Show Icon
- var style = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode]['style'];
- $('#IconArea').css({
- 'width' : '100%',
- 'height' : style['widget']['height']+'px',
- 'float' : style['widget']['float']
- });
-
- $('#IconArea')[0].className = NOKIA.mode+NOKIA.currentDevice;
-
- var img = document.createElement('img');
- img.src = NOKIA.emulator.iconFile;
- img.border = 0;
-
- var div = document.createElement('div');
- var p = document.createElement('p');
-
- if(NOKIA.emulator.plist.DisplayName.length <= 12)
- p.innerHTML = NOKIA.emulator.plist.DisplayName;
- else
- p.innerHTML = NOKIA.emulator.plist.DisplayName.substr(0, 11) + '...';
-
- div.className = 'IconFile';
- div.style.marginTop = parseInt(parseInt(style['widget']['height']/2)-80) + 'px';
- div.appendChild(img);
- img.onclick = function(){
-
- // close the console DIV
- NOKIA.layout._console_enabled = false;
- NOKIA.layout.render();
-
- $("#loaderDiv").html("Widget is loading. Please wait...");
- $("#loaderDiv")[0].className = 'green';
- $("#loaderDiv").show();
- window.setTimeout(function(){
- document.location = document.location;
- }, 3000);
-
- };
-
- div.appendChild(p);
-
- $("#loaderDiv").html("Click on Icon to Launch Widget");
- $("#loaderDiv").show();
- $("#loaderDiv")[0].className = 'yellow';
-
- $('#IconArea').append(div);
- $('#IconArea').show();
-
- NOKIA.menu.is_dimmed = true;
-
- },
-
- setLsk : function(func)
- {
- // for RSK
- $('#LskArea')[0].onclick = function(){
- if(!NOKIA.menu.is_dimmed)
- func();
- };
-
- $('#LskLabel > a')[0].onclick = function(){
- if(!NOKIA.menu.is_dimmed)
- func();
- };
-
- return true;
- },
-
- setRsk : function(func)
- {
- // for RSK
- $('#RskArea')[0].onclick = function(){
- if(!NOKIA.menu.is_dimmed)
- func();
- };
-
- $('#RskLabel > a')[0].onclick = function(){
- if(!NOKIA.menu.is_dimmed)
- func();
- };
-
- return true;
- },
-
-
- triggerLsk : function(event)
- {
- var callback;
- if(NOKIA.mode == 'portrait')
- callback = NOKIA.menu.lsk_event;
- else if( (NOKIA.mode == 'landscape') && (event.id =='LskLabel') )
- callback = NOKIA.menu.lsk_event;
- else
- callback = NOKIA.menu.rsk_event;
-
- if(typeof callback == 'function' && !NOKIA.menu.is_dimmed)
- {
- callback();
- }
- },
-
- triggerRsk : function(event)
- {
- var callback;
- if(NOKIA.mode == 'portrait')
- callback = NOKIA.menu.rsk_event;
- else if( (NOKIA.mode == 'landscape') && (event.id =='RskLabel') )
- callback = NOKIA.menu.rsk_event;
- else
- callback = NOKIA.menu.lsk_event;
-
- if(typeof callback == 'function')
- {
- if(!NOKIA.menu.is_dimmed)
- {
- callback();
- NOKIA.menu.cancel();
- }
- }
- },
-
- render : function()
- {
- if(!NOKIA.menu.softkeys_visibility)
- NOKIA.menu.hideSoftKeys();
- else
- NOKIA.menu.showSoftKeys();
-
- NOKIA.emulator.setWidgetStyle();
- },
-
-
- init : function()
- {
- NOKIA.menu.render();
- },
-
- createSFKArea : function()
- {
- var a = $('#SoftKeys > a');
- a.html('');
-
- var preferences = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode];
-
- var lsk = document.createElement('img');
- lsk.border="0";
- lsk.id = "LskArea";
- lsk.name ="LskArea";
- lsk.src = "preview/images/TransperantImage.png";
- lsk.style.width = preferences.style.softkeysImg.width;
- lsk.style.height = preferences.style.softkeysImg.height;
-
- var rsk = document.createElement('img');
- rsk.border = 0;
- rsk.id = "RskArea";
- rsk.name = "RskArea";
- rsk.src = "preview/images/TransperantImage.png";
- rsk.style.width = preferences.style.softkeysImg.width;
- rsk.style.height = preferences.style.softkeysImg.height;
-
- if(NOKIA.mode == 'portrait')
- {
- lsk.onclick = function(){
- $("#LskLabel > a").trigger('click');
- };
- a[0].appendChild(lsk);
-
- rsk.onclick = function(){
- $("#RskLabel > a").trigger('click');
- };
- a[1].appendChild(rsk);
-
- }else{
-
- rsk.onclick = function(){
- $("#RskLabel > a").trigger('click');
- };
- a[0].appendChild(rsk);
-
- lsk.onclick = function(){
- $("#LskLabel > a").trigger('click');
- };
- a[1].appendChild(lsk);
- }
-
-
- },
-
- showSoftKeys : function()
- {
- NOKIA.menu.is_softkeys_visible = true;
-
- NOKIA.emulator.setWidgetStyle();
- $("#SoftKeysArea").show();
- },
-
- hideSoftKeys : function()
- {
- // Hide the SFK's If user hidden them from his code
- if(!NOKIA.menu.softkeys_visibility)
- $("#SoftKeysArea").hide();
-
- NOKIA.menu.is_softkeys_visible = false;
-
- NOKIA.emulator.setWidgetStyle();
- }
- };
-
-
+ NOKIA.menu = new EmulatorMenu();
/*
* NOKIA.emulator
*/
NOKIA.namespace('emulator');
- NOKIA.emulator = {
- child : false,
- iconFile : 'preview/images/default-Icon.png',
- loaded : false,
- plist : {
- DisplayName : '',
- Identifier : '',
- MainHTML : '',
- AllowNetworkAccess : "false",
- Version : '',
- MiniViewEnabled : "false",
- is_browserReady : false
- },
-
- load : function()
- {
- if(this.loaded)
- return false;
- NOKIA.layout._console_minimized = (NOKIA.helper.getPreference('__SYM_NOKIA_CONSOLE_OPEN') != "true");
- // load the saved device Info
- var device = NOKIA.helper.getPreference('__SYM_NOKIA_EMULATOR_DEVICE');
- NOKIA.currentDevice = device || NOKIA.currentDevice;
-
- // load the saved device mode
- var mode = NOKIA.helper.getPreference('__SYM_NOKIA_EMULATOR_DEVICE_MODE');
- if(mode != null)
- NOKIA.mode = mode;
-
- var orientation = Number(NOKIA.helper.getPreference('__SYM_NOKIA_EMULATOR_ORIENTATION'));
- if (typeof orientation == "number" && orientation >= -90 && orientation <= 180)
- NOKIA.orientation = orientation;
-
- // SAVE the device DATA
- NOKIA.helper.setPreference('__SYM_NOKIA_EMULATOR_DEVICE', NOKIA.currentDevice);
- NOKIA.helper.setPreference('__SYM_NOKIA_EMULATOR_DEVICE_MODE', NOKIA.mode);
- NOKIA.helper.setPreference('__SYM_NOKIA_EMULATOR_ORIENTATION', NOKIA.orientation);
-
- this.loaded = true;
-
- },
-
- render : function()
- {
- this.load();
- // Selecting Resoltion
- var resOptions = $("#resOptions")[0];
- for(var i=0; i<NOKIA.resolution.length; i++)
- {
- if(NOKIA.resolution[i] == NOKIA.currentDevice)
- {
- resOptions.options[i].selected = true;
- break;
- }
- }
-
- if(!NOKIA.emulator.orientationSupports())
- NOKIA.mode = NOKIA.deviceList[NOKIA.currentDevice]['default'];
-
- if(typeof NOKIA.deviceList == 'undefined' || typeof NOKIA.deviceList[NOKIA.currentDevice] == 'undefined' || typeof NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode] == 'undefined')
- {
- alert('Deive resolution: '+NOKIA.currentDevice+' or the mode: '+NOKIA.mode+' not found');
- return false;
- }
-
- this.setStyle();
- var or = (NOKIA.mode == 'portrait') ? NOKIA.orientation : (NOKIA.orientation + 90);
- var val = "rotate(" + or + "deg)";
- $("#DeviceDisplayLayout").css("-moz-transform", val);
- $("#DeviceDisplayLayout").css("-webkit-transform", val);
- },
-
- setMode : function(mode)
- {
- NOKIA.mode = mode;
-
- // SAVE the device DATA
- NOKIA.helper.setPreference('__SYM_NOKIA_EMULATOR_DEVICE_MODE', NOKIA.mode);
-
- NOKIA.emulator.render();
- },
-
- toggle : function(o)
- {
- NOKIA.orientation = o;
- NOKIA.helper.setPreference('__SYM_NOKIA_EMULATOR_ORIENTATION', NOKIA.orientation);
- NOKIA.emulator.child.device.implementation.setOrientation(o, 0);
- if (NOKIA.emulator.orientationSupports() && (o == 0 || o == -90)) {
- NOKIA.emulator.setMode(o == 0 ? 'portrait' : 'landscape');
- } else {
- NOKIA.emulator.render();
- }
- },
-
- orientationSupports : function()
- {
- return NOKIA.deviceList[NOKIA.currentDevice]['orientation'];
- },
-
- setStyle:function()
- {
- if(!NOKIA.helper.checkDependencies())
- {
- setTimeout(NOKIA.emulator.setStyle, 1000);
- }
-
- var deviceProperties = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode];
- var style = deviceProperties['style'];
-
- // Apply Style and propertis to Device layers
- $("#DeviceDisplayLayout").css(style['layout']);
- $('#DisplayArea').css(style['display']);
-
- NOKIA.emulator.setWidgetStyle();
-
- $('#SoftKeysArea').css({
- 'width' : style['menu']['width']+'px',
- 'height' : style['menu']['height']+'px',
- 'float' : style['menu']['float']
- });
-
- $('#SoftKeysArea > ul > li').css('width', parseInt(style['menu']['width']/2)-10);
-
-
- NOKIA.emulator.setMenuItemsStyle();
-
- $('#SoftKeys').css(style['softkeys']);
-// $('#SoftKeys > a > img').css(style['softkeysImg']);
-
- NOKIA.menu.createSFKArea();
-
- $("#DeviceDisplayLayout").show();
- $("#InspectorTab").show();
-
- if (/chrome/.test( navigator.userAgent.toLowerCase())) {
- $("#InspectorBtn").show();
- }
- if (/mac/.test( navigator.userAgent.toLowerCase())) {
- $("#MacShortcut").show();
- } else {
- $("#UniversalShortcut").show();
- }
- },
-
- setWidgetStyle : function()
- {
- var style = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode]['style'];
- var height;
- if(NOKIA.menu.softkeys_visibility || NOKIA.menu.is_softkeys_visible)
- height = parseInt(style['widget']['height'] - style['menu']['height']);
- else
- height = style['widget']['height'];
-
- $('#WidgetArea').css({
- 'width' : style['widget']['width']+'px',
- 'height' : height+'px',
- 'float' : style['widget']['float']
- });
- },
-
- setMenuItemsStyle : function()
- {
- var style = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode]['style'];
- var count = 1;
- try {
- if (NOKIA.emulator.child.menu) {
- count = parseInt(NOKIA.helper.getElementsLengthInObject(NOKIA.emulator.child.menu.items)) + 1;
- }
- } catch (e) {
- count = 1;
- }
- var height = parseInt(count*style['menu']['optionKeysheight']) + 10;
- var top = parseInt(style['widget']['height'] - height);
-
- $('#MenuItemsArea').css({
- 'width' : style['widget']['width']+'px',
- 'height' : height+'px',
- 'marginTop' : '-2px',
- 'top' : (style['widget']['height']-height-style['menu']['height']+2)+'px',
- 'position' : 'relative'
- });
- }
- };
+ NOKIA.emulator = new Emulator();
/*
* NOKIA.helper functions
*/
NOKIA.namespace('helper.loadScript');
- NOKIA.helper = {
- path : document.location.pathname,
- errorDailog : null,
- prefDailog : null,
- inspectorDailog : null,
- intervalId : null,
- infoPlistCounter : false,
- IconFileCounter : false,
- loadScript : function(path)
- {
- var head = document.getElementsByTagName("head")[0] || document.documentElement;
- var script = document.createElement("script");
-
- script.type = "text/javascript";
- script.src = src;
- head.appendChild( script );
- },
-
- loadPreferences : function()
- {
- if(/dreamweaver/i.test(navigator.userAgent))
- {
- $("#dwDeviceHelp")[0].className = '';
-// $("#resSupportLink")[0].className = 'hide';
- }
- // Selecting Resoltion
- var resOptions = $("#resOptions")[0];
- for(var i=0; i<NOKIA.resolution.length; i++)
- {
- if(NOKIA.resolution[i] == NOKIA.currentDevice)
- {
- resOptions.options[i].selected = true;
- break;
- }
- }
-
- // Selecting Version
- if(NOKIA.version == 'WRT 1.0')
- $('#wrt_version_1_0')[0].checked = true;
- else
- $('#wrt_version_1_1')[0].checked = true;
-
- // HomeScreen Support
- if(NOKIA.deviceList[NOKIA.currentDevice].homeScreenSupport)
- {
- if (typeof NOKIA.emulator.plist.MiniViewEnabled != 'undefined') {
- if (NOKIA.emulator.plist.MiniViewEnabled == 'false')
- $('#HS_Control_Info').html("<span id='wrt-help' onclick='javascipt:NOKIA.helper.showMiniviewHelp();'></span><strong>Not Enabled</strong><br/><small>Click on help to read more about enabling Mini view support</small>");
- else
- $('#HS_Control_Info').html("Supported");
- }
- else
- $('#HS_Control_Info').html("<span id='wrt-help'></span>Not Supported");
-
- $('#HS_Control_Info').show();
-
- }
- else
- {
- $('#HS_Control_Info').html("Not Supported for the selected Device resolution");
- $('#HS_Control_Info').show();
- }
- },
-
- getInfo : function(url, callback)
- {
- try {
- var xhr = this.ajax();
-
- if ((/AppleWebKit/i.test(navigator.userAgent)))
- xhr.open("GET", url, false);
- else
- xhr.open("GET", url, true);
-
-
- xhr.onreadystatechange = function()
- {
- // readyState = 4 ; "complete"
- if (xhr.readyState==4)
- {
- // status = 200 ; "ok"
- if( (xhr.status == 200) || (!xhr.status) )
- {
- callback(true, xhr);
- }
- else
- {
- callback(false, xhr);
- }
- }
-
- };
- xhr.send(null);
- } catch (e) {
- if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
- callback(false, xhr);
- }
- }
- },
-
- getInfoCallback : function(flag, xhr)
- {
- // If Info.plis NOT FOUND / FAILED LOAD
- // an ERROR!, unable to proceed further
- // STOP there
- if(!flag)
- {
- if(!NOKIA.helper.infoPlistCounter)
- {
- NOKIA.helper.infoPlistCounter = true;
- NOKIA.helper.getInfo('info.plist', NOKIA.helper.getInfoCallback);
- return false;
- }
-
- NOKIA.helper.error('WRT Previewer: Initialization failed. Could not open Info.plist file.<br/>Please ensure <strong style="color:#efe352;">Info.plist</strong> file exists in the project root folder and that it is named properly.');
- return false;
- }
- else{
-
- var xmlString = xhr.responseText;
-
- // do some cheating here
- xmlString = xmlString.replace(/<!--(.|[\n\r])*?-->/gm, "");
- xmlString = xmlString.replace(/<\s*true\s*\/>/gi, "<string>true</string>");
- xmlString = xmlString.replace(/<\s*false\s*\/>/gi, "<string>false</string>");
- xmlString = xmlString.replace(/[\n\r]/gi, "");
- // return the JSON Object
- NOKIA.helper.validate(xmlString);
- }
-
- },
-
- getIconCallback : function(flag, xhr)
- {
-
- if(!flag)
- {
- if(!NOKIA.helper.IconFileCounter)
- {
- NOKIA.helper.IconFileCounter = true;
- NOKIA.helper.getInfo('icon.png', NOKIA.helper.getIconCallback);
- return false;
- }
- }
- else
- NOKIA.emulator.iconFile = (NOKIA.helper.IconFileCounter) ? "icon.png" : "Icon.png";
- },
-
-
- validate : function(xmlObject)
- {
- var values = xmlObject.match(/.*<plist.*?(<dict.*?>\s*(<key[^>]*?>[^<]*?<\/key>\s*<string[^>]*?>[^<]*?<\/string>)*\s*<\/dict>)\s*<\/plist>/)[1];
- if(values == null || values == undefined)
- {
- NOKIA.helper.error('Corrupted Info.plist file');
- return false;
- }
- values = values.replace(/<dict.*?(<key.*?>\s*.*\s*<\/string>)\s*<\/dict>/, "{ $1 }");
- values = values.replace(/\s*<key.*?>\s*(.*?)\s*<\/key>\s*<string.*?>\s*(.*?)\s*<\/string>\s*/g, "\"$1\" : \"$2\", ");
- values = values.replace(/"\s*?,\s*?}/g, "\" }");
- try {
- NOKIA.emulator.plist = JSON.parse(values);
- } catch (exception) {
- NOKIA.helper.error('Corrupted Info.plist file');
- return false;
- }
-
- try {
- if(typeof NOKIA.emulator.plist.DisplayName != 'undefined'){
- document.title = NOKIA.emulator.plist.DisplayName + ' - ' + document.title;
- }
- } catch (e) {}
-
- // Add UI-Event listeners
- NOKIA.helper.addListeners();
- NOKIA.layout.init();
- NOKIA.emulator.render();
- },
-
-
- ajax : function()
- {
- // xmlHttpRequest object
- var request = null;
-
- // branch for native XMLHttpRequest object
- if(window.XMLHttpRequest && !(window.ActiveXObject)) {
- try
- {
- request = new XMLHttpRequest();
- try
- {
- // attach the Bypass code, if the browser is firefox
- if(netscape.security.PrivilegeManager.enablePrivilege)
- {
- // duplicate the function
- request._open = request.open;
-
- // redefine the function definition
- request.open = function(method, url, flag)
- {
- try
- {
- // Enable Universal Browser Read
- netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
-
- // call the native XmlHttpRequest.open method
- this._open(method, url, flag);
- }catch(e)
- {
- // call the native XmlHttpRequest.open method
- this._open(method, url, flag);
- }
- };
- }
- }
- catch(e)
- {
- // eatup all exceptions
- }
- }
- catch(e) {
- request = null;
- }
- // branch for IE/Windows ActiveX version
- } else if(window.ActiveXObject) {
- try {
- request = new ActiveXObject("Msxml2.XMLHTTP");
- } catch(e) {
- try {
- request = new ActiveXObject("Microsoft.XMLHTTP");
- } catch(e) {
- alert('Failed to create XmlHttprequest');
- return null;
- }
- }
- }
-
- return (request);
- },
-
- error : function(msg)
- {
- if(NOKIA.menu.enable_log)
- NOKIA.layout.log("log", msg);
-
- $("#Dialog").html(msg);
- $("#Dialog").dialog('open');
- },
-
- setPreference : function(name,value)
- {
- if (NOKIA.emulator.prefs[name] != value) {
- NOKIA.emulator.prefs[name] = value;
- $.post("preview/preferences.js", JSON.stringify({ "key" : name, "value" : value }), undefined, "json");
- }
- },
-
- getPreference : function(name)
- {
- return NOKIA.emulator.prefs[name];
- },
-
- rotateCW : function() {
- var newOrient = NOKIA.orientation + 90;
- NOKIA.emulator.toggle(newOrient - (newOrient > 180 ? 360 : 0));
- },
- rotateCCW : function() {
- var newOrient = NOKIA.orientation - 90;
- NOKIA.emulator.toggle(newOrient + (newOrient <= -180 ? 360 : 0));
- },
-
- version : function(ele)
- {
- if (confirm('Would you like to reload the widget to apply the changes on the Version settings?'))
- {
- NOKIA.helper.setPreference('__SYM_WRT_VERSION', ele.value);
- $("#loaderDiv").html("Applying the " + ele.value + ", please wait...");
- $("#loaderDiv").show();
- $("#loaderDiv")[0].className = 'green';
-
- window.setTimeout(function(){
- document.location = document.location;
- }, 3000);
- }
- else
- {
- ele.checked = false;
- if(ele.value != 'WRT 1.0')
- $("#wrt_version_1_0")[0].checked = true;
- else
- $("#wrt_version_1_1")[0].checked = true;
- }
- },
-
- addListeners : function()
- {
- NOKIA.helper.loadPreferences();
- /*
- * Render Emulator for Interaction
- */
- NOKIA.helper.inspectorDailog = $("#InspectorTab").dialog({
- width: 370, minWidth: 300, minHeight: 200, height: 250, autoOpen: false, position : top, title : ' ',
- buttons : {
- "Close" : function(){
- $("#InspectorTab").dialog('close');
- },
- "Disconnect Debugger" : function(){
- $.ajax({url : "__sym_command/terminateDebug"});
- }}
- });
-
- $('#InspectorBtn').click(function(){
- $('#InspectorTab').dialog('open');
- // Hack for Mac firefox
- if(/Mac/i.test(navigator.userAgent))
- {
- $("#WidgetArea iframe").css({overflow:'hidden'});
- }
- });
-
- $('#rotateCW').click(function(){
- NOKIA.helper.rotateCW();
- });
- $('#rotateCCW').click(function(){
- NOKIA.helper.rotateCCW();
- });
- $('#resOptions').change(function(ele){
- ele = ele.target || this;
-
- NOKIA.currentDevice = ele.options[ele.selectedIndex].text;
-
- // SAVE the device DATA
- NOKIA.helper.setPreference('__SYM_NOKIA_EMULATOR_DEVICE', NOKIA.currentDevice);
-
- NOKIA.emulator.render();
- NOKIA.helper.loadPreferences();
- });
-
- // Hack for Mac firefox
- if (/Mac/i.test(navigator.userAgent)) {
- if (!(/AppleWebKit/i.test(navigator.userAgent))) {
- $("#resOptions")[0].size = '4';
- }
- }
-
-
- // WRT Version controls
- $('#wrt_version_1_0').change(function(){
- NOKIA.helper.version(this);
- });
-
- $('#wrt_version_1_1').change(function(){
- NOKIA.helper.version(this);
- });
-
-
- $("#orientationIcon").click(function(){
- var mode = (NOKIA.mode == 'portrait') ? 'landscape' : 'portrait';
- NOKIA.emulator.setMode(mode);
- $("#WidgetArea")[0].className = 'hs_'+NOKIA.mode;
- });
-
-
- $("#iframeMask").click(function(){
- $("#orientationIcon").hide();
- $("#iframeMask").hide();
- $("#loaderDiv").hide();
-
- NOKIA.menu.is_dimmed = false;
-
- $("#WidgetArea")[0].className = '';
-
- NOKIA.menu.softkeys_visibility = true;
- NOKIA.menu.showSoftKeys();
-
- });
-
-
- // MenuItems DIV events
- $("#MenuItemsArea").mouseover(function(){
- if(NOKIA.helper.intervalId)
- clearInterval(NOKIA.helper.intervalId);
-
- $("#MenuItemsArea").show();
- });
-
- $("#MenuItemsArea").mouseout(function(){
- if(NOKIA.helper.intervalId)
- clearInterval(NOKIA.helper.intervalId);
-
- NOKIA.helper.intervalId = setTimeout(function(){
- NOKIA.menu.cancel();
- }, 500);
- });
-
-
- // Tabs
- $('#tabs').tabs({
-// select : function(event, ui){
-// switch (ui.index) {
-// case 1:
-// $("event-battery-info").show();
-// break;
-// case 2:
-// $("event-messaging-info").show();
-// break;
-// case 3:
-// $("event-memory-info").show();
-// break;
-// case 4:
-// $("settings-view").show();
-// break;
-//
-// }}
- });
- $(".tabs-bottom .ui-tabs-nav, .tabs-bottom .ui-tabs-nav > *")
- .removeClass("ui-corner-all ui-corner-top")
- .addClass("ui-corner-bottom");
-
- /*
- * Event triggering
- */
-
- // for battery
- $("#event-battery").click(function(event){
- if(event.target.className == 'active')
- {
- $("#event-icons").hide();
- $("#event-battery-info").show();
-
-/*
- $('#slider').slider('option', 'value', NOKIA.emulator.child._BRIDGE_REF.helper.getBatteryStrength());
- NOKIA.emulator.child._BRIDGE_REF.helper.getBatteryStrength()
- $('#slider').slider('option', 'value', 10);
- $('#slider').slider();
-*/
- }
- });
-
- $("#event-battery-back").click(function(event){
- $("#event-icons").show();
- $("#event-battery-info").hide();
- });
-
-
- // for messaging
- $("#event-messaging").click(function(event){
- if(event.target.className == 'active')
- {
- $("#event-icons").hide();
- $("#event-messaging-info").show();
- }
- });
-
- $("#event-messaging-back").click(function(event){
- $("#event-icons").show();
- $("#event-messaging-info").hide();
- });
-
-
- // for memory
- $("#event-memory").click(function(event){
- if(event.target.className == 'active')
- {
- $("#event-icons").hide();
- $("#event-memory-info").show();
- }
- });
-
- $("#event-memory-back").click(function(event){
- $("#event-icons").show();
- $("#event-memory-info").hide();
- });
-
-
- // for minView more info
- $("#mini-view-back").click(function(event){
- $("#settings-view").show();
- $("#mini-view-info").hide();
- });
-
-
- // Slider
- $('#slider').slider({
- min : 0,
- max : 100,
- step : 1,
- value : 10,
- animate: true,
- slide: function(event, ui) {
- $("#slider-value-panel > span").html(ui.value.toString() + "%");
- },
- change: function(event, ui) {
- var chargeValue = ui.value;
- NOKIA.helper.trigger("power", "chargelevel", chargeValue);
- if(NOKIA.version == 'WRT 1.1')
- NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.BatteryStrength", {Status: chargeValue});
- }
- });
- $("#slider-value-panel > span").html("10%");
-
- var cc = $("#close-camera");
- cc.click(NOKIA.helper.hideCamera);
- // Bind Buttons to trigger values to WRT 1.0 / 1.1 bindings
-
- $("#connect-charger").click(NOKIA.helper.triggerEvents);
- $("#disconnect-charger").click(NOKIA.helper.triggerEvents);
-
- $("#send-sms").click(NOKIA.helper.triggerEvents);
- $("#send-mms").click(NOKIA.helper.triggerEvents);
-
- $("#connect-memory-card").click(NOKIA.helper.triggerEvents);
- $("#disconnect-memory-card").click(NOKIA.helper.triggerEvents);
-
-
- },
-
- setHomeScreen : function()
- {
- // HomeScreen Support
- if (NOKIA.deviceList[NOKIA.currentDevice].homeScreenSupport) {
-
- if (typeof NOKIA.emulator.plist.MiniViewEnabled != 'undefined') {
- if (NOKIA.emulator.plist.MiniViewEnabled != 'false')
- {
- $("#WidgetArea")[0].className = 'hs_' + NOKIA.mode;
-
- // menu handlining
- NOKIA.menu.softkeys_visibility = false;
- NOKIA.menu.cancel();
- NOKIA.menu.is_dimmed = true;
-
-
- $("#loaderDiv").html("Click on widget for Return to Full view");
- $("#loaderDiv")[0].className = 'green';
- $("#loaderDiv").show();
-
- $("#iframeMask").show();
- $("#orientationIcon").show();
-
- return true;
- }
- }
- }
- return false;
- },
-
- getElementsLengthInObject : function(items){
- var count = 0;
- for (var i in items)
- {
- if(!items[i].isDimmed)
- count++;
- }
-
- return count;
- },
-
- showCamera : function() {
- $("#camera").show();
- $("#WidgetArea").hide();
- },
-
- hideCamera : function() {
- $("#camera").hide();
- $("#WidgetArea").show();
- },
-
- triggerEvents : function(event)
- {
- if(typeof event.target.id == 'undefined')
- return false;
-
- switch(event.target.id)
- {
- // for battery
- case 'connect-charger':
- NOKIA.helper.trigger("power", "chargerconnected", 1);
- if(NOKIA.version == 'WRT 1.1')
- NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.ChargingStatus", {Status: 1});
- break;
-
- case 'disconnect-charger':
- NOKIA.helper.trigger("power", "chargerconnected", 0);
- if(NOKIA.version == 'WRT 1.1')
- NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.ChargingStatus", {Status: 0});
- break;
-
- // for messaging
- case 'send-sms':
- if(NOKIA.version == 'WRT 1.1')
- NOKIA.helper.triggerSapi("Service.Messaging", "NewMessage", {MessageType: 'SMS'});
- break;
- case 'send-mms':
- if(NOKIA.version == 'WRT 1.1')
- NOKIA.helper.triggerSapi("Service.Messaging", "NewMessage", {MessageType: 'MMS'});
- break;
-
- // for memory
- case 'connect-memory-card':
- if(NOKIA.version == 'WRT 1.1')
- NOKIA.helper.triggerSapi("Service.SysInfo", "Memory.MemoryCard", {Status: 1});
- break;
- case 'disconnect-memory-card':
- if(NOKIA.version == 'WRT 1.1')
- NOKIA.helper.triggerSapi("Service.SysInfo", "Memory.MemoryCard", {Status: 0});
- break;
- }
- },
-
- triggerSapi : function(provider, eventType, data){
- NOKIA.emulator.child.device.implementation.triggerListener(provider, eventType, data);
- },
-
- trigger : function(provider, eventType, data){
- NOKIA.emulator.child.widget.triggerListener(provider, eventType, data);
- },
-
- showMiniviewHelp : function(){
- $("#settings-view").hide();
- $("#mini-view-info").show();
- },
-
- checkDependencies : function(){
-
- for(var key in NOKIA.scriptsLoaded)
- {
- if(!NOKIA.scriptsLoaded[key])
- return false;
- }
-
- // for LSK
- NOKIA.menu.setLsk(NOKIA.emulator.child.menu.show);
-
- // for RSK
- NOKIA.menu.setRsk(NOKIA.menu.exit);
-
- return true;
- }
- };
+ NOKIA.helper = new EmulatorHelper();
/*
* NOKIA.layout functions
*/
NOKIA.namespace('layout');
- NOKIA.layout = {
- _console_minimized : true,
- _console_enabled : false,
- _consoleWindowHeight : 290,
- _consoleHeaderHeight : 31,
- _tabHeight : 27,
-
- init : function(){
-
- // Toggle console window
- $('#preview-ui-bottom-header').click(function(){
- NOKIA.layout._console_minimized = (NOKIA.layout._console_minimized) ? false : true;
- NOKIA.layout.render();
- NOKIA.helper.setPreference("__SYM_NOKIA_CONSOLE_OPEN", !NOKIA.layout._console_minimized);
- });
-
- // clear Log
- $("#Console-Clear-Button").click(function(){
- $("#preview-ui-bottom-body")[0].innerHTML = '';
- });
-
-
- $('#preview-ui-bottom').show();
- NOKIA.layout.render();
- },
-
- log : function(type, msg){
- var p = document.createElement('p');
- p.className = type;
- p.innerHTML = msg;
- var divBody = $('#preview-ui-bottom-body');
- divBody.append(p);
- divBody[0].scrollTop = divBody[0].scrollHeight;
- },
-
-
- render : function(){
- var _width = parseInt(window.innerWidth);
- var _height = parseInt(window.innerHeight);
-
- if(!NOKIA.layout._console_enabled)
- {
- $('#preview-ui-bottom').css({
- display: 'none'
- });
-
- $('#preview-ui-top').css({
- height: _height+'px'
- });
-
- return false;
- }
-
-
- if(!NOKIA.layout._console_minimized)
- {
- $('#Console-Toggle-Button')[0].className = 'open';
-
- // set STYLE details for TOP window
- $('#preview-ui-top').css({
- height: parseInt(_height - NOKIA.layout._consoleWindowHeight) + 'px'
- });
-
- // set STYLE details for Bottom window
- $('#preview-ui-bottom').css({
- height: NOKIA.layout._consoleWindowHeight + 'px',
- display : 'block'
- });
-
- $('#preview-ui-bottom-header').css({
- height: NOKIA.layout._consoleHeaderHeight + 'px'
- });
-
- $('#tabs').css({
- height: parseInt(NOKIA.layout._consoleWindowHeight - NOKIA.layout._consoleHeaderHeight) + 'px',
- display : 'block'
- });
- $('#console').css({
- height : parseInt(NOKIA.layout._consoleWindowHeight
- - NOKIA.layout._consoleHeaderHeight
- - NOKIA.layout._tabHeight * 2)
- + 'px',
- display : 'block'
- });
-
- // Auto scroll when console window opened from MINIMIZED => MAXIMIZED state
- window.setTimeout(function(){
- $('#preview-ui-bottom-body')[0].scrollTop = $('#preview-ui-bottom-body')[0].scrollHeight;
- }, 100);
-
- }else{
- $('#Console-Toggle-Button')[0].className = 'close';
-
- // set STYLE details for TOP window
- $('#preview-ui-top').css({
- height: parseInt(_height - NOKIA.layout._consoleHeaderHeight) + 'px'
- });
-
- // set STYLE details for Bottom window
- $('#preview-ui-bottom').css({
- height: NOKIA.layout._consoleHeaderHeight + 'px',
- display : 'block'
- });
-
- $('#preview-ui-bottom-header').css({
- height: NOKIA.layout._consoleHeaderHeight + 'px',
- display : 'block'
- });
-// TODO
-// $('#preview-ui-bottom-body').css({
-// display : 'none'
-// });
- }
- }
-
- };
+ NOKIA.layout = new EmulatorLayout();
}
$(document).ready(function () {