5 if(typeof NOKIA == "undefined" || !NOKIA)
9 currentDevice : '240x320',
11 resolution : ['240x320', '320x240', '360x640', '800x352'],
21 NOKIA.namespace = function(name)
23 var parts = name.split('.');
25 for(var key in parts){
26 if(!current[parts[key]]){
27 current[parts[key]] = {};
29 current = current[parts[key]];
33 NOKIA.init = function()
35 // Not-Supported Browser check
36 NOKIA.emulator.is_browserReady = (/MSIE/i.test(navigator.userAgent));
37 if(NOKIA.emulator.is_browserReady)
39 var notSupportedBrowser = NOKIA.helper.readCookie('NOKIA_NOT_SUPPORTED_BROWSER');
40 if (notSupportedBrowser != 1) {
41 $("#NotificationDiv")[0].className = 'show';
42 $("#NotificationDiv").dialog({
49 title: 'Notification window',
52 $("#NotificationDiv").dialog('close');
55 $("#NotificationDiv").dialog('close');
56 NOKIA.helper.createCookie('NOKIA_NOT_SUPPORTED_BROWSER', 1);
63 $("#BrowserNotificationBar").css({display:'block'});
64 $("#BrowserNotificationBar > p > a").click(function(){ $("#BrowserNotificationBar").hide(); });
68 $('iframe')[0].src = "wrt_preview_main.html";
70 NOKIA.data.load(deviceResolutionList);
72 var url = window.location.toString();
80 for(var i=pointer; i<url.length-1; i++){ t = t + url[i] + '/'; }
82 NOKIA.emulator.url = 'file:///' + t;
84 NOKIA.emulator.url = 'http://' + t;
86 // Common Error/Notification Dialog
87 NOKIA.helper.errorDailog = $("#Dialog").dialog({
88 bgiframe: true, minHeight: 150, width: 450, modal: true, autoOpen: false,
90 Cancel: function(){ $(this).dialog('close'); },
92 $(this).dialog('close');
93 $("#loaderDiv").html("Widget is reloading. Please wait...");
94 $("#loaderDiv")[0].className = 'green';
95 $("#loaderDiv").show();
96 window.setTimeout(function(){
97 document.location = document.location;
103 // validating Info.plist
104 this.helper.getInfo('Info.plist', NOKIA.helper.getInfoCallback);
106 // For getting Icon.png
107 this.helper.getInfo('Icon.png', NOKIA.helper.getIconCallback);
113 NOKIA.namespace('data.load');
115 NOKIA.data.load = function(data){
116 NOKIA.deviceList = data;
124 NOKIA.namespace('menu');
126 is_menu_visible : false, // true/false
127 is_softkeys_visible : false, // true : only when MenuItem's are displayed
128 softkeys_visibility : true, // true/false : for hide/show SFK's
130 is_rsk_overridden : false,
135 highlighted_item : null,
139 $("#MenuItemsArea").fadeIn("slow");
141 // Hide the SFK's If user hidden them from his code
142 if(NOKIA.menu.softkeys_visibility)
143 $("#SoftKeysArea").fadeIn("slow");
145 NOKIA.menu.is_softkeys_visible = false;
152 NOKIA.layout.log("log", NOKIA.menu.log_counter + ' ' +str);
153 NOKIA.layout.log("log", 'is_rsk_overridden: '+NOKIA.menu.is_rsk_overridden);
154 NOKIA.layout.log("log", 'rsk_label: '+NOKIA.menu.rsk_label);
155 NOKIA.layout.log("log", 'rsk_event: '+NOKIA.menu.rsk_event);
157 NOKIA.menu.log_counter++;
162 if(NOKIA.menu.is_dimmed)
165 NOKIA.menu.showSoftKeys();
167 NOKIA.menu.is_menu_visible = true;
168 $("#MenuItemsArea").show();
170 NOKIA.menu.highlighted_item = $("#MenuItemsArea > ul > li")[0];
171 NOKIA.menu.highlighted_item.className = 'active';
174 $("#MenuItemsArea > ul > li").mouseover(function(){
175 if(NOKIA.menu.highlighted_item != null)
177 NOKIA.menu.highlighted_item.className = '';
178 NOKIA.menu.highlighted_item = null;
181 NOKIA.menu.highlighted_item = this;
182 NOKIA.menu.highlighted_item.className = 'active';
185 $("#SoftKeysArea").mouseout(function(){
186 if (!NOKIA.menu.is_menu_visible) {
190 if (NOKIA.helper.intervalId) {
191 clearInterval(NOKIA.helper.intervalId);
193 NOKIA.helper.intervalId = setTimeout(function(){
199 // Change the label "Options" to "Select" to LSK
200 $("#LskLabel > a")[0].innerHTML = "Select";
201 NOKIA.menu.setLsk(NOKIA.menu.selectMenu);
203 // Change the label "Exit" to "Cancel" to RSK
204 $("#RskLabel > a")[0].innerHTML = 'Cancel';
205 NOKIA.menu.setRsk(NOKIA.menu.cancel);
208 NOKIA.emulator.setMenuItemsStyle();
212 selectMenu : function(){
214 if(typeof NOKIA.menu.highlighted_item.onclick != 'undefined'){
215 eval(NOKIA.menu.highlighted_item.onclick)();
220 // NOKIA.menu.cancel();
226 if(NOKIA.menu.is_dimmed)
229 NOKIA.menu.hideSoftKeys();
231 NOKIA.menu.is_menu_visible = false;
232 $("#MenuItemsArea").hide();
234 // Reset the "OPTION" label to LSK
235 $("#LskLabel > a")[0].innerHTML = 'Options';
236 NOKIA.menu.setLsk(NOKIA.emulator.child.menu.show);
238 // Change the label "CANCEL" to "EXIT" to RSK
239 if(!NOKIA.menu.is_rsk_overridden)
241 $("#RskLabel > a")[0].innerHTML = 'Exit';
242 NOKIA.menu.setRsk(NOKIA.menu.exit);
246 $("#RskLabel > a")[0].innerHTML = NOKIA.menu.rsk_label;
247 NOKIA.menu.setRsk(NOKIA.menu.rsk_event);
254 if(NOKIA.menu.is_dimmed)
257 if(NOKIA.helper.setHomeScreen())
260 // clear the Menu Settings
262 NOKIA.emulator.child.menu.setRightSoftkeyLabel('', null);
263 NOKIA.emulator.child.menu.items = [];
264 NOKIA.menu.softkeys_visibility = false;
267 NOKIA.menu.hideSoftKeys();
268 NOKIA.menu.setLsk(function(){});
269 NOKIA.menu.setRsk(function(){});
271 $("#WidgetArea").hide();
274 var style = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode]['style'];
277 'height' : style['widget']['height']+'px',
278 'float' : style['widget']['float']
281 $('#IconArea')[0].className = NOKIA.mode+NOKIA.currentDevice;
283 var img = document.createElement('img');
284 img.src = NOKIA.emulator.iconFile;
287 var div = document.createElement('div');
288 var p = document.createElement('p');
290 if(NOKIA.emulator.plist.DisplayName.length <= 12)
291 p.innerHTML = NOKIA.emulator.plist.DisplayName;
293 p.innerHTML = NOKIA.emulator.plist.DisplayName.substr(0, 11) + '...'
295 div.className = 'IconFile';
296 div.style.marginTop = parseInt(parseInt(style['widget']['height']/2)-80) + 'px';
297 div.appendChild(img);
298 img.onclick = function(){
300 // close the console DIV
301 NOKIA.layout._console_enabled = false;
302 NOKIA.layout.render();
304 $("#loaderDiv").html("Widget is loading. Please wait...");
305 $("#loaderDiv")[0].className = 'green';
306 $("#loaderDiv").show();
307 window.setTimeout(function(){
308 document.location = document.location;
315 $("#loaderDiv").html("Click on Icon to Launch Widget");
316 $("#loaderDiv").show();
317 $("#loaderDiv")[0].className = 'yellow';
319 $('#IconArea').append(div);
320 $('#IconArea').show();
322 NOKIA.menu.is_dimmed = true;
324 $("#PreferencesBtn").hide();
325 $("#PreferencesTab").dialog('close');
329 setLsk : function(func)
332 $('#LskArea')[0].onclick = function(){
333 if(!NOKIA.menu.is_dimmed)
337 $('#LskLabel > a')[0].onclick = function(){
338 if(!NOKIA.menu.is_dimmed)
345 setRsk : function(func)
348 $('#RskArea')[0].onclick = function(){
349 if(!NOKIA.menu.is_dimmed)
353 $('#RskLabel > a')[0].onclick = function(){
354 if(!NOKIA.menu.is_dimmed)
362 triggerLsk : function(event)
365 if(NOKIA.mode == 'portrait')
366 callback = NOKIA.menu.lsk_event;
367 else if( (NOKIA.mode == 'landscape') && (event.id =='LskLabel') )
368 callback = NOKIA.menu.lsk_event;
370 callback = NOKIA.menu.rsk_event;
372 if(typeof callback == 'function' && !NOKIA.menu.is_dimmed)
378 triggerRsk : function(event)
381 if(NOKIA.mode == 'portrait')
382 callback = NOKIA.menu.rsk_event;
383 else if( (NOKIA.mode == 'landscape') && (event.id =='RskLabel') )
384 callback = NOKIA.menu.rsk_event;
386 callback = NOKIA.menu.lsk_event;
388 if(typeof callback == 'function')
390 if(!NOKIA.menu.is_dimmed)
400 if(!NOKIA.menu.softkeys_visibility)
401 NOKIA.menu.hideSoftKeys();
403 NOKIA.menu.showSoftKeys();
405 NOKIA.emulator.setWidgetStyle();
414 createSFKArea : function()
416 var a = $('#SoftKeys > a');
419 var preferences = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode];
421 var lsk = document.createElement('img');
425 lsk.src = "preview/images/TransperantImage.png";
426 lsk.style.width = preferences.style.softkeysImg.width;
427 lsk.style.height = preferences.style.softkeysImg.height;
429 var rsk = document.createElement('img');
432 rsk.name = "RskArea";
433 rsk.src = "preview/images/TransperantImage.png";
434 rsk.style.width = preferences.style.softkeysImg.width;
435 rsk.style.height = preferences.style.softkeysImg.height;
437 if(NOKIA.mode == 'portrait')
439 lsk.onclick = function(){
440 $("#LskLabel > a").trigger('click');
442 a[0].appendChild(lsk);
444 rsk.onclick = function(){
445 $("#RskLabel > a").trigger('click');
447 a[1].appendChild(rsk);
451 rsk.onclick = function(){
452 $("#RskLabel > a").trigger('click');
454 a[0].appendChild(rsk);
456 lsk.onclick = function(){
457 $("#LskLabel > a").trigger('click');
459 a[1].appendChild(lsk);
465 showSoftKeys : function()
467 NOKIA.menu.is_softkeys_visible = true;
469 NOKIA.emulator.setWidgetStyle();
470 $("#SoftKeysArea").show();
473 hideSoftKeys : function()
475 // Hide the SFK's If user hidden them from his code
476 if(!NOKIA.menu.softkeys_visibility)
477 $("#SoftKeysArea").hide();
479 NOKIA.menu.is_softkeys_visible = false;
481 NOKIA.emulator.setWidgetStyle();
490 NOKIA.namespace('emulator');
493 iconFile : 'preview/images/default-Icon.png',
499 AllowNetworkAccess : "false",
501 MiniViewEnabled : "false",
502 is_browserReady : false
510 // load the saved device Info
511 var device = NOKIA.helper.readCookie('NOKIA_EMULATOR_DEVICE');
512 NOKIA.currentDevice = device || NOKIA.currentDevice;
515 // load the saved device mode
516 var mode = NOKIA.helper.readCookie('NOKIA_EMULATOR_DEVICE_MODE');
520 // SAVE the device DATA
521 NOKIA.helper.createCookie('NOKIA_EMULATOR_DEVICE', NOKIA.currentDevice);
522 NOKIA.helper.createCookie('NOKIA_EMULATOR_DEVICE_MODE', NOKIA.mode);
532 if(!NOKIA.emulator.orientationSupports())
533 NOKIA.mode = NOKIA.deviceList[NOKIA.currentDevice]['default'];
535 if(typeof NOKIA.deviceList == 'undefined' || typeof NOKIA.deviceList[NOKIA.currentDevice] == 'undefined' || typeof NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode] == 'undefined')
537 alert('Deive resolution: '+NOKIA.currentDevice+' or the mode: '+NOKIA.mode+' not found');
544 setMode : function(mode)
548 // SAVE the device DATA
549 NOKIA.helper.createCookie('NOKIA_EMULATOR_DEVICE_MODE', NOKIA.mode);
551 NOKIA.emulator.render();
554 orientationSupports : function()
556 return NOKIA.deviceList[NOKIA.currentDevice]['orientation'];
561 if(!NOKIA.helper.checkDependencies())
563 setTimeout(NOKIA.emulator.setStyle, 1000);
566 var deviceProperties = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode];
567 var style = deviceProperties['style'];
569 // Apply Style and propertis to Device layers
570 $("#DeviceDisplayLayout").css(style['layout']);
571 $('#DisplayArea').css(style['display']);
573 NOKIA.emulator.setWidgetStyle();
575 $('#SoftKeysArea').css({
576 'width' : style['menu']['width']+'px',
577 'height' : style['menu']['height']+'px',
578 'float' : style['menu']['float']
581 $('#SoftKeysArea > ul > li').css('width', parseInt(style['menu']['width']/2)-10);
584 NOKIA.emulator.setMenuItemsStyle();
586 $('#SoftKeys').css(style['softkeys']);
587 // $('#SoftKeys > a > img').css(style['softkeysImg']);
589 NOKIA.menu.createSFKArea();
591 $("#DeviceDisplayLayout").show();
592 $("#PreferencesTab").show();
594 if(!NOKIA.menu.is_dimmed)
595 $("#PreferencesBtn").show();
598 setWidgetStyle : function()
600 var style = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode]['style'];
602 if(NOKIA.menu.softkeys_visibility || NOKIA.menu.is_softkeys_visible)
603 height = parseInt(style['widget']['height'] - style['menu']['height']);
605 height = style['widget']['height'];
607 $('#WidgetArea').css({
608 'width' : style['widget']['width']+'px',
609 'height' : height+'px',
610 'float' : style['widget']['float']
614 setMenuItemsStyle : function()
616 var style = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode]['style'];
619 count = parseInt(NOKIA.helper.getElementsLengthInObject(NOKIA.emulator.child.menu.items))+1;
623 var height = parseInt(count*style['menu']['optionKeysheight']) + 10;
624 var top = parseInt(style['widget']['height'] - height);
626 $('#MenuItemsArea').css({
627 'width' : style['widget']['width']+'px',
628 'height' : height+'px',
629 'marginTop' : '-2px',
630 'top' : (style['widget']['height']-height-style['menu']['height']+2)+'px',
631 'position' : 'relative'
637 * NOKIA.helper functions
639 NOKIA.namespace('helper.loadScript');
641 path : document.location.pathname,
645 infoPlistCounter : false,
646 IconFileCounter : false,
647 loadScript : function(path)
649 var head = document.getElementsByTagName("head")[0] || document.documentElement;
650 var script = document.createElement("script");
652 script.type = "text/javascript";
654 head.appendChild( script );
657 loadPreferences : function()
659 // Selecting Resoltion
660 var resOptions = $("#resOptions")[0];
661 for(var i=0; i<NOKIA.resolution.length; i++)
663 if(NOKIA.resolution[i] == NOKIA.currentDevice)
665 resOptions.options[i].selected = true;
666 $("#resSupportLink")[0].href = resOptions.options[i].value;
671 // Selecting Orientation
672 if(NOKIA.mode == 'portrait')
673 $('#input_portrait')[0].checked = true;
675 $('#input_landscape')[0].checked = true;
677 if (!NOKIA.emulator.orientationSupports()) {
678 if (NOKIA.mode == 'portrait')
679 $("#input_landscape")[0].disabled = true;
681 $("#input_portrait")[0].disabled = true;
683 $("#Orientation_Info").html("Not supported");
684 $("#Orientation_Info").show();
685 $("#Orientation_Controls").hide();
688 $("#input_landscape")[0].disabled = false;
689 $("#input_portrait")[0].disabled = false;
691 $("#Orientation_Info").hide();
692 $("#Orientation_Controls").show();
696 if(NOKIA.version == 'WRT 1.0')
697 $('#wrt_version_1_0')[0].checked = true;
699 $('#wrt_version_1_1')[0].checked = true;
701 // HomeScreen Support
702 if(NOKIA.deviceList[NOKIA.currentDevice].homeScreenSupport)
704 if (typeof NOKIA.emulator.plist.MiniViewEnabled != 'undefined') {
705 if (NOKIA.emulator.plist.MiniViewEnabled == 'false')
706 $('#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>");
708 $('#HS_Control_Info').html("Supported");
711 $('#HS_Control_Info').html("<span id='wrt-help'></span>Not Supported");
713 $('#HS_Control_Info').show();
718 $('#HS_Control_Info').html("Not Supported for the selected Device resolution");
719 $('#HS_Control_Info').show();
723 getInfo : function(url, callback)
726 var xhr = this.ajax();
728 if ((/AppleWebKit/i.test(navigator.userAgent)))
729 xhr.open("GET", url, false);
731 xhr.open("GET", url, true);
734 xhr.onreadystatechange = function()
736 // readyState = 4 ; "complete"
737 if (xhr.readyState==4)
739 // status = 200 ; "ok"
740 if( (xhr.status == 200) || (!xhr.status) )
746 callback(false, xhr);
753 if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
754 callback(false, xhr);
759 getInfoCallback : function(flag, xhr)
761 // If Info.plis NOT FOUND / FAILED LOAD
762 // an ERROR!, unable to proceed further
766 if(!NOKIA.helper.infoPlistCounter)
768 NOKIA.helper.infoPlistCounter = true;
769 NOKIA.helper.getInfo('info.plist', NOKIA.helper.getInfoCallback);
773 NOKIA.helper.error('Unable to intialize the widget, failed to process Info.plist file. <br/>Please ensure <strong style="color:#efe352;">Info.plist</strong> file exists on the widget root folder <br/>or check the filename of <strong style="color:#efe352;">Info.plist</strong> It is case-sensitive');
778 var xmlString = xhr.responseText;
780 // do some cheating here
781 xmlString = xmlString.replace(/<\s*true\s*\/>/gi, "<string>true</string>");
782 xmlString = xmlString.replace(/<\s*false\s*\/>/gi, "<string>false</string>");
786 var appXml = new DOMParser();
787 var xmlobject = appXml.parseFromString(xmlString, "text/xml");
790 // return the JSON Object
791 NOKIA.helper.validate(xml2json.parser(xmlString));
796 getIconCallback : function(flag, xhr)
801 if(!NOKIA.helper.IconFileCounter)
803 NOKIA.helper.IconFileCounter = true;
804 NOKIA.helper.getInfo('icon.png', NOKIA.helper.getIconCallback);
809 NOKIA.emulator.iconFile = (NOKIA.helper.IconFileCounter) ? "icon.png" : "Icon.png";
813 validate : function(xmlObject)
815 window.xmlObject = xmlObject;
818 if(typeof xmlObject.plist != 'object' || xmlObject.plist == 'undefined')
820 NOKIA.helper.error('Corrupted Info.plist file');
824 xmlObject = xmlObject.plist;
825 if(typeof xmlObject.dict != 'object' || xmlObject.dict == 'undefined')
827 NOKIA.helper.error('Corrupted Info.plist file');
832 xmlObject = xmlObject.dict;
833 if(typeof xmlObject.key != 'object' || xmlObject.key == 'undefined')
835 NOKIA.helper.error('Corrupted Info.plist file');
840 if(typeof xmlObject.string != 'object' || xmlObject.string == 'undefined')
842 NOKIA.helper.error('Corrupted Info.plist file');
846 // num of <key> = num of <string>
847 if(xmlObject.key.length != xmlObject.string.length)
849 NOKIA.helper.error('Corrupted Info.plist file');
853 for(var val in xmlObject.key)
855 if(NOKIA.emulator.plist[xmlObject.key[val]] != 'undefined'){
856 NOKIA.emulator.plist[xmlObject.key[val]] = xmlObject.string[val].toString();
861 if(typeof NOKIA.emulator.plist.DisplayName != 'undefined'){
862 document.title = NOKIA.emulator.plist.DisplayName + ' - ' + document.title;
866 // Add UI-Event listeners
867 NOKIA.helper.addListeners();
869 NOKIA.emulator.render();
875 // xmlHttpRequest object
878 // branch for native XMLHttpRequest object
879 if(window.XMLHttpRequest && !(window.ActiveXObject)) {
882 request = new XMLHttpRequest();
885 // attach the Bypass code, if the browser is firefox
886 if(netscape.security.PrivilegeManager.enablePrivilege)
888 // duplicate the function
889 request._open = request.open;
891 // redefine the function definition
892 request.open = function(method, url, flag)
896 // Enable Universal Browser Read
897 netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
899 // call the native XmlHttpRequest.open method
900 this._open(method, url, flag);
903 // call the native XmlHttpRequest.open method
904 this._open(method, url, flag);
911 // eatup all exceptions
917 // branch for IE/Windows ActiveX version
918 } else if(window.ActiveXObject) {
920 request = new ActiveXObject("Msxml2.XMLHTTP");
923 request = new ActiveXObject("Microsoft.XMLHTTP");
925 alert('Failed to create XmlHttprequest');
934 error : function(msg)
936 if(NOKIA.menu.enable_log)
937 NOKIA.layout.log("log", msg);
939 $("#Dialog").html(msg);
940 $("#Dialog").dialog('open');
943 createCookie : function(name,value)
947 var date = new Date();
948 date.setTime(date.getTime()+(days*24*60*60*1000));
949 var expires = "; expires="+date.toGMTString();
951 else var expires = "";
952 var value = "Nokia_WRT#"+NOKIA.helper.path+"#"+name+"="+value;
953 document.cookie = value+expires+"; Emulator.path=/"
956 readCookie : function(name)
958 name = "Nokia_WRT#" + NOKIA.helper.path + "#" + name;
959 var nameEQ = name + "=";
960 var ca = document.cookie.split(';');
961 for(var i=0;i < ca.length;i++) {
963 while (c.charAt(0)==' ') c = c.substring(1,c.length);
964 if (c.indexOf(nameEQ) == 0) {
965 return c.substring(nameEQ.length,c.length);
971 toggle : function(ele)
973 if (NOKIA.emulator.orientationSupports()) {
974 // var mode = (NOKIA.mode == 'portrait') ? 'landscape' : 'portrait';
975 NOKIA.emulator.setMode(ele.value);
980 if(ele.value == 'portrait')
981 $("#input_landscape")[0].checked = true;
983 $("#input_portrait")[0].checked = true;
987 version : function(ele)
989 if (confirm('Would you like to reload the widget to apply the changes on the Version settings?'))
991 NOKIA.helper.createCookie('_WRT_VERSION', ele.value);
992 $("#loaderDiv").html("Applying the " + ele.value + ", please wait...");
993 $("#loaderDiv").show();
994 $("#loaderDiv")[0].className = 'green';
996 $("#PreferencesTab").dialog('close');
998 window.setTimeout(function(){
999 document.location = document.location;
1004 ele.checked = false;
1005 if(ele.value != 'WRT 1.0')
1006 $("#wrt_version_1_0")[0].checked = true;
1008 $("#wrt_version_1_1")[0].checked = true;
1012 addListeners : function()
1015 * Render Emulator for Interaction
1017 NOKIA.helper.prefDailog = $("#PreferencesTab").dialog({
1018 width: 550, minWidth: 550, minHeight: 350, height: 350, autoOpen: false, position : top, title : ' ',
1021 $("#PreferencesTab").dialog('close');
1023 // Hack for Mac firefox
1024 if(/Mac/i.test(navigator.userAgent))
1026 $("#WidgetArea iframe").css({overflow:'auto'});
1029 // select index : 0 tab selected
1030 $('#tabs').tabs( 'select' , 0);
1035 $('#PreferencesBtn').click(function(){
1037 NOKIA.helper.loadPreferences();
1038 $('#PreferencesTab').dialog('open');
1040 // Hack for Mac firefox
1041 if(/Mac/i.test(navigator.userAgent))
1043 $("#WidgetArea iframe").css({overflow:'hidden'});
1047 $('#input_portrait').change(function(){
1048 NOKIA.helper.toggle(this);
1051 $('#input_landscape').change(function(){
1052 NOKIA.helper.toggle(this);
1055 $('#resOptions').change(function(ele){
1056 ele = ele.target || this;
1058 NOKIA.currentDevice = ele.options[ele.selectedIndex].text;
1059 $("#resSupportLink")[0].href = ele.value;
1061 // SAVE the device DATA
1062 NOKIA.helper.createCookie('NOKIA_EMULATOR_DEVICE', NOKIA.currentDevice);
1064 NOKIA.emulator.render();
1065 NOKIA.helper.loadPreferences();
1068 // Hack for Mac firefox
1069 if (/Mac/i.test(navigator.userAgent)) {
1070 if (!(/AppleWebKit/i.test(navigator.userAgent))) {
1071 $("#resOptions")[0].size = '4';
1076 // WRT Version controls
1077 $('#wrt_version_1_0').change(function(){
1078 NOKIA.helper.version(this);
1081 $('#wrt_version_1_1').change(function(){
1082 NOKIA.helper.version(this);
1086 $("#orientationIcon").click(function(){
1087 var mode = (NOKIA.mode == 'portrait') ? 'landscape' : 'portrait';
1088 NOKIA.emulator.setMode(mode);
1089 $("#WidgetArea")[0].className = 'hs_'+NOKIA.mode;
1093 $("#iframeMask").click(function(){
1095 $("#PreferencesBtn").show();
1096 $("#orientationIcon").hide();
1097 $("#iframeMask").hide();
1098 $("#loaderDiv").hide();
1100 NOKIA.menu.is_dimmed = false;
1102 $("#WidgetArea")[0].className = '';
1104 NOKIA.menu.softkeys_visibility = true;
1105 NOKIA.menu.showSoftKeys();
1110 // MenuItems DIV events
1111 $("#MenuItemsArea").mouseover(function(){
1112 if(NOKIA.helper.intervalId)
1113 clearInterval(NOKIA.helper.intervalId);
1115 $("#MenuItemsArea").show();
1118 $("#MenuItemsArea").mouseout(function(){
1119 if(NOKIA.helper.intervalId)
1120 clearInterval(NOKIA.helper.intervalId);
1122 NOKIA.helper.intervalId = setTimeout(function(){
1130 select : function(event, ui){
1131 if(parseInt(ui.index) == 1)
1133 $("#event-icons").show();
1134 $("#event-battery-info").hide();
1135 $("#event-messaging-info").hide();
1136 $("#event-memory-info").hide();
1138 // WRT versionn check
1139 if(NOKIA.version == 'WRT 1.1')
1141 $("#event-messaging")[0].className = 'active';
1142 $("#event-memory")[0].className = 'active';
1145 $("#event-messaging")[0].className = 'inactive';
1146 $("#event-memory")[0].className = 'inactive';
1148 $("#event-battery")[0].className = 'active';
1149 }else if(parseInt(ui.index) == 0)
1151 $("#settings-view").show();
1152 $("#mini-view-info").hide();
1163 $("#event-battery").click(function(event){
1164 if(event.target.className == 'active')
1166 $("#event-icons").hide();
1167 $("#event-battery-info").show();
1170 $('#slider').slider('option', 'value', NOKIA.emulator.child._BRIDGE_REF.helper.getBatteryStrength());
1171 NOKIA.emulator.child._BRIDGE_REF.helper.getBatteryStrength()
1172 $('#slider').slider('option', 'value', 10);
1173 $('#slider').slider();
1178 $("#event-battery-back").click(function(event){
1179 $("#event-icons").show();
1180 $("#event-battery-info").hide();
1185 $("#event-messaging").click(function(event){
1186 if(event.target.className == 'active')
1188 $("#event-icons").hide();
1189 $("#event-messaging-info").show();
1193 $("#event-messaging-back").click(function(event){
1194 $("#event-icons").show();
1195 $("#event-messaging-info").hide();
1200 $("#event-memory").click(function(event){
1201 if(event.target.className == 'active')
1203 $("#event-icons").hide();
1204 $("#event-memory-info").show();
1208 $("#event-memory-back").click(function(event){
1209 $("#event-icons").show();
1210 $("#event-memory-info").hide();
1214 // for minView more info
1215 $("#mini-view-back").click(function(event){
1216 $("#settings-view").show();
1217 $("#mini-view-info").hide();
1222 $('#slider').slider({
1229 slide: function(event, ui) {
1230 $("#slider-value-panel > span").html(ui.value.toString());
1234 // Bind Buttons to trigger values to WRT 1.0 / 1.1 bindings
1236 $("#connect-charger").click(NOKIA.helper.triggerEvents);
1237 $("#disconnect-charger").click(NOKIA.helper.triggerEvents);
1238 $("#update-batter-strength").click(NOKIA.helper.triggerEvents);
1240 $("#send-sms").click(NOKIA.helper.triggerEvents);
1241 $("#send-mms").click(NOKIA.helper.triggerEvents);
1243 $("#connect-memory-card").click(NOKIA.helper.triggerEvents);
1244 $("#disconnect-memory-card").click(NOKIA.helper.triggerEvents);
1248 setHomeScreen : function()
1250 // HomeScreen Support
1251 if (NOKIA.deviceList[NOKIA.currentDevice].homeScreenSupport) {
1253 if (typeof NOKIA.emulator.plist.MiniViewEnabled != 'undefined') {
1254 if (NOKIA.emulator.plist.MiniViewEnabled != 'false')
1256 $("#WidgetArea")[0].className = 'hs_' + NOKIA.mode;
1259 NOKIA.menu.softkeys_visibility = false;
1260 NOKIA.menu.cancel();
1261 NOKIA.menu.is_dimmed = true;
1264 $("#loaderDiv").html("Click on widget for Return to Full view");
1265 $("#loaderDiv")[0].className = 'green';
1266 $("#loaderDiv").show();
1268 $("#iframeMask").show();
1269 $("#orientationIcon").show();
1270 $("#PreferencesBtn").hide();
1272 $("#PreferencesTab").dialog('close');
1280 getElementsLengthInObject : function(items){
1282 for (var i in items)
1284 if(!items[i].isDimmed)
1291 triggerEvents : function(event)
1293 if(typeof event.target.id == 'undefined')
1296 switch(event.target.id)
1299 case 'connect-charger':
1300 NOKIA.helper.trigger("power", "chargerconnected", 1);
1301 if(NOKIA.version == 'WRT 1.1')
1302 NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.ChargingStatus", {Status: 1});
1305 case 'disconnect-charger':
1306 NOKIA.helper.trigger("power", "chargerconnected", 0);
1307 if(NOKIA.version == 'WRT 1.1')
1308 NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.ChargingStatus", {Status: 0});
1311 case 'update-batter-strength':
1312 var chargeValue = parseInt($('#slider').slider('value'));
1313 NOKIA.helper.trigger("power", "chargelevel", chargeValue);
1314 if(NOKIA.version == 'WRT 1.1')
1315 NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.BatteryStrength", {Status: chargeValue});
1320 if(NOKIA.version == 'WRT 1.1')
1321 NOKIA.helper.triggerSapi("Service.Messaging", "NewMessage", {MessageType: 'SMS'});
1324 if(NOKIA.version == 'WRT 1.1')
1325 NOKIA.helper.triggerSapi("Service.Messaging", "NewMessage", {MessageType: 'MMS'});
1329 case 'connect-memory-card':
1330 if(NOKIA.version == 'WRT 1.1')
1331 NOKIA.helper.triggerSapi("Service.SysInfo", "Memory.MemoryCard", {Status: 1});
1333 case 'disconnect-memory-card':
1334 if(NOKIA.version == 'WRT 1.1')
1335 NOKIA.helper.triggerSapi("Service.SysInfo", "Memory.MemoryCard", {Status: 0});
1340 triggerSapi : function(provider, eventType, data){
1341 NOKIA.emulator.child.device.implementation.triggerListener(provider, eventType, data);
1344 trigger : function(provider, eventType, data){
1345 NOKIA.emulator.child.widget.triggerListener(provider, eventType, data);
1348 showMiniviewHelp : function(){
1349 $("#settings-view").hide();
1350 $("#mini-view-info").show();
1353 checkDependencies : function(){
1355 for(var key in NOKIA.scriptsLoaded)
1357 if(!NOKIA.scriptsLoaded[key])
1362 NOKIA.menu.setLsk(NOKIA.emulator.child.menu.show);
1365 NOKIA.menu.setRsk(NOKIA.menu.exit);
1373 * NOKIA.layout functions
1375 NOKIA.namespace('layout');
1377 _console_minimized : true,
1378 _console_enabled : false,
1379 _consoleWindowHeight : 200,
1380 _consoleHeaderHeight : 31,
1384 // Toggle console window
1385 $('#Console-Toggle-Button').click(function(){
1387 NOKIA.layout._console_minimized = (NOKIA.layout._console_minimized) ? false : true;
1388 NOKIA.layout.render();
1392 $("#Console-Clear-Button").click(function(){
1393 $("#preview-ui-bottom-body")[0].innerHTML = '';
1397 $('#preview-ui-bottom').show();
1398 NOKIA.layout.render();
1401 log : function(type, msg){
1402 var p = document.createElement('p');
1405 var divBody = $('#preview-ui-bottom-body')
1407 divBody[0].scrollTop = divBody[0].scrollHeight;
1411 render : function(){
1412 var _width = parseInt(window.innerWidth);
1413 var _height = parseInt(window.innerHeight);
1415 if(!NOKIA.layout._console_enabled)
1417 $('#preview-ui-bottom').css({
1421 $('#preview-ui-top').css({
1422 height: _height+'px'
1429 if(!NOKIA.layout._console_minimized)
1431 $('#Console-Toggle-Button')[0].className = 'open';
1433 // set STYLE details for TOP window
1434 $('#preview-ui-top').css({
1435 height: parseInt(_height - NOKIA.layout._consoleWindowHeight) + 'px'
1438 // set STYLE details for Bottom window
1439 $('#preview-ui-bottom').css({
1440 height: NOKIA.layout._consoleWindowHeight + 'px',
1444 $('#preview-ui-bottom-header').css({
1445 height: NOKIA.layout._consoleHeaderHeight + 'px'
1448 $('#preview-ui-bottom-body').css({
1449 height: parseInt(NOKIA.layout._consoleWindowHeight - NOKIA.layout._consoleHeaderHeight) + 'px',
1453 // Auto scroll when console window opened from MINIMIZED => MAXIMIZED state
1454 window.setTimeout(function(){
1455 $('#preview-ui-bottom-body')[0].scrollTop = $('#preview-ui-bottom-body')[0].scrollHeight;
1459 $('#Console-Toggle-Button')[0].className = 'close';
1461 // set STYLE details for TOP window
1462 $('#preview-ui-top').css({
1463 height: parseInt(_height - NOKIA.layout._consoleHeaderHeight) + 'px'
1466 // set STYLE details for Bottom window
1467 $('#preview-ui-bottom').css({
1468 height: NOKIA.layout._consoleHeaderHeight + 'px',
1472 $('#preview-ui-bottom-header').css({
1473 height: NOKIA.layout._consoleHeaderHeight + 'px',
1477 $('#preview-ui-bottom-body').css({
1486 $(document).ready(function () {
1490 window.onresize = NOKIA.layout.render;