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 if (NOKIA.emulator.child.menu) {
620 count = parseInt(NOKIA.helper.getElementsLengthInObject(NOKIA.emulator.child.menu.items)) + 1;
625 var height = parseInt(count*style['menu']['optionKeysheight']) + 10;
626 var top = parseInt(style['widget']['height'] - height);
628 $('#MenuItemsArea').css({
629 'width' : style['widget']['width']+'px',
630 'height' : height+'px',
631 'marginTop' : '-2px',
632 'top' : (style['widget']['height']-height-style['menu']['height']+2)+'px',
633 'position' : 'relative'
639 * NOKIA.helper functions
641 NOKIA.namespace('helper.loadScript');
643 path : document.location.pathname,
647 infoPlistCounter : false,
648 IconFileCounter : false,
649 loadScript : function(path)
651 var head = document.getElementsByTagName("head")[0] || document.documentElement;
652 var script = document.createElement("script");
654 script.type = "text/javascript";
656 head.appendChild( script );
659 loadPreferences : function()
661 if(/dreamweaver/i.test(navigator.userAgent))
663 $("#dwDeviceHelp")[0].className = '';
664 $("#resSupportLink")[0].className = 'hide';
666 // Selecting Resoltion
667 var resOptions = $("#resOptions")[0];
668 for(var i=0; i<NOKIA.resolution.length; i++)
670 if(NOKIA.resolution[i] == NOKIA.currentDevice)
672 resOptions.options[i].selected = true;
673 $("#resSupportLink")[0].href = resOptions.options[i].value;
678 // Selecting Orientation
679 if(NOKIA.mode == 'portrait')
680 $('#input_portrait')[0].checked = true;
682 $('#input_landscape')[0].checked = true;
684 if (!NOKIA.emulator.orientationSupports()) {
685 if (NOKIA.mode == 'portrait')
686 $("#input_landscape")[0].disabled = true;
688 $("#input_portrait")[0].disabled = true;
690 $("#Orientation_Info").html("Not supported");
691 $("#Orientation_Info").show();
692 $("#Orientation_Controls").hide();
695 $("#input_landscape")[0].disabled = false;
696 $("#input_portrait")[0].disabled = false;
698 $("#Orientation_Info").hide();
699 $("#Orientation_Controls").show();
703 if(NOKIA.version == 'WRT 1.0')
704 $('#wrt_version_1_0')[0].checked = true;
706 $('#wrt_version_1_1')[0].checked = true;
708 // HomeScreen Support
709 if(NOKIA.deviceList[NOKIA.currentDevice].homeScreenSupport)
711 if (typeof NOKIA.emulator.plist.MiniViewEnabled != 'undefined') {
712 if (NOKIA.emulator.plist.MiniViewEnabled == 'false')
713 $('#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>");
715 $('#HS_Control_Info').html("Supported");
718 $('#HS_Control_Info').html("<span id='wrt-help'></span>Not Supported");
720 $('#HS_Control_Info').show();
725 $('#HS_Control_Info').html("Not Supported for the selected Device resolution");
726 $('#HS_Control_Info').show();
730 getInfo : function(url, callback)
733 var xhr = this.ajax();
735 if ((/AppleWebKit/i.test(navigator.userAgent)))
736 xhr.open("GET", url, false);
738 xhr.open("GET", url, true);
741 xhr.onreadystatechange = function()
743 // readyState = 4 ; "complete"
744 if (xhr.readyState==4)
746 // status = 200 ; "ok"
747 if( (xhr.status == 200) || (!xhr.status) )
753 callback(false, xhr);
760 if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
761 callback(false, xhr);
766 getInfoCallback : function(flag, xhr)
768 // If Info.plis NOT FOUND / FAILED LOAD
769 // an ERROR!, unable to proceed further
773 if(!NOKIA.helper.infoPlistCounter)
775 NOKIA.helper.infoPlistCounter = true;
776 NOKIA.helper.getInfo('info.plist', NOKIA.helper.getInfoCallback);
780 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');
785 var xmlString = xhr.responseText;
787 // do some cheating here
788 xmlString = xmlString.replace(/<\s*true\s*\/>/gi, "<string>true</string>");
789 xmlString = xmlString.replace(/<\s*false\s*\/>/gi, "<string>false</string>");
793 var appXml = new DOMParser();
794 var xmlobject = appXml.parseFromString(xmlString, "text/xml");
797 // return the JSON Object
798 NOKIA.helper.validate(xml2json.parser(xmlString));
803 getIconCallback : function(flag, xhr)
808 if(!NOKIA.helper.IconFileCounter)
810 NOKIA.helper.IconFileCounter = true;
811 NOKIA.helper.getInfo('icon.png', NOKIA.helper.getIconCallback);
816 NOKIA.emulator.iconFile = (NOKIA.helper.IconFileCounter) ? "icon.png" : "Icon.png";
820 validate : function(xmlObject)
822 window.xmlObject = xmlObject;
825 if(typeof xmlObject.plist != 'object' || xmlObject.plist == 'undefined')
827 NOKIA.helper.error('Corrupted Info.plist file');
831 xmlObject = xmlObject.plist;
832 if(typeof xmlObject.dict != 'object' || xmlObject.dict == 'undefined')
834 NOKIA.helper.error('Corrupted Info.plist file');
839 xmlObject = xmlObject.dict;
840 if(typeof xmlObject.key != 'object' || xmlObject.key == 'undefined')
842 NOKIA.helper.error('Corrupted Info.plist file');
847 if(typeof xmlObject.string != 'object' || xmlObject.string == 'undefined')
849 NOKIA.helper.error('Corrupted Info.plist file');
853 // num of <key> = num of <string>
854 if(xmlObject.key.length != xmlObject.string.length)
856 NOKIA.helper.error('Corrupted Info.plist file');
860 for(var val in xmlObject.key)
862 if(NOKIA.emulator.plist[xmlObject.key[val]] != 'undefined'){
863 NOKIA.emulator.plist[xmlObject.key[val]] = xmlObject.string[val].toString();
868 if(typeof NOKIA.emulator.plist.DisplayName != 'undefined'){
869 document.title = NOKIA.emulator.plist.DisplayName + ' - ' + document.title;
873 // Add UI-Event listeners
874 NOKIA.helper.addListeners();
876 NOKIA.emulator.render();
882 // xmlHttpRequest object
885 // branch for native XMLHttpRequest object
886 if(window.XMLHttpRequest && !(window.ActiveXObject)) {
889 request = new XMLHttpRequest();
892 // attach the Bypass code, if the browser is firefox
893 if(netscape.security.PrivilegeManager.enablePrivilege)
895 // duplicate the function
896 request._open = request.open;
898 // redefine the function definition
899 request.open = function(method, url, flag)
903 // Enable Universal Browser Read
904 netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
906 // call the native XmlHttpRequest.open method
907 this._open(method, url, flag);
910 // call the native XmlHttpRequest.open method
911 this._open(method, url, flag);
918 // eatup all exceptions
924 // branch for IE/Windows ActiveX version
925 } else if(window.ActiveXObject) {
927 request = new ActiveXObject("Msxml2.XMLHTTP");
930 request = new ActiveXObject("Microsoft.XMLHTTP");
932 alert('Failed to create XmlHttprequest');
941 error : function(msg)
943 if(NOKIA.menu.enable_log)
944 NOKIA.layout.log("log", msg);
946 $("#Dialog").html(msg);
947 $("#Dialog").dialog('open');
950 createCookie : function(name,value)
954 var date = new Date();
955 date.setTime(date.getTime()+(days*24*60*60*1000));
956 var expires = "; expires="+date.toGMTString();
958 else var expires = "";
959 document.cookie = "Nokia_WRT#" + NOKIA.helper.path + "#" + name + "=" + value + expires + "; path=/";
962 readCookie : function(name)
964 var nameEQ = "Nokia_WRT#" + NOKIA.helper.path + "#" + name + "=";
965 var ca = document.cookie.split(';');
966 for(var i=0;i < ca.length;i++) {
968 while (c.charAt(0)==' ') c = c.substring(1,c.length);
969 if (c.indexOf(nameEQ) == 0) {
970 return c.substring(nameEQ.length,c.length);
976 toggle : function(ele)
978 if (NOKIA.emulator.orientationSupports()) {
979 // var mode = (NOKIA.mode == 'portrait') ? 'landscape' : 'portrait';
980 NOKIA.emulator.setMode(ele.value);
985 if(ele.value == 'portrait')
986 $("#input_landscape")[0].checked = true;
988 $("#input_portrait")[0].checked = true;
992 version : function(ele)
994 if (confirm('Would you like to reload the widget to apply the changes on the Version settings?'))
996 NOKIA.helper.createCookie('_WRT_VERSION', ele.value);
997 $("#loaderDiv").html("Applying the " + ele.value + ", please wait...");
998 $("#loaderDiv").show();
999 $("#loaderDiv")[0].className = 'green';
1001 $("#PreferencesTab").dialog('close');
1003 window.setTimeout(function(){
1004 document.location = document.location;
1009 ele.checked = false;
1010 if(ele.value != 'WRT 1.0')
1011 $("#wrt_version_1_0")[0].checked = true;
1013 $("#wrt_version_1_1")[0].checked = true;
1017 addListeners : function()
1020 * Render Emulator for Interaction
1022 NOKIA.helper.prefDailog = $("#PreferencesTab").dialog({
1023 width: 550, minWidth: 550, minHeight: 350, height: 350, autoOpen: false, position : top, title : ' ',
1026 $("#PreferencesTab").dialog('close');
1028 // Hack for Mac firefox
1029 if(/Mac/i.test(navigator.userAgent))
1031 $("#WidgetArea iframe").css({overflow:'auto'});
1034 // select index : 0 tab selected
1035 $('#tabs').tabs( 'select' , 0);
1040 $('#PreferencesBtn').click(function(){
1042 NOKIA.helper.loadPreferences();
1043 $('#PreferencesTab').dialog('open');
1045 // Hack for Mac firefox
1046 if(/Mac/i.test(navigator.userAgent))
1048 $("#WidgetArea iframe").css({overflow:'hidden'});
1052 $('#input_portrait').change(function(){
1053 NOKIA.helper.toggle(this);
1056 $('#input_landscape').change(function(){
1057 NOKIA.helper.toggle(this);
1060 $('#resOptions').change(function(ele){
1061 ele = ele.target || this;
1063 NOKIA.currentDevice = ele.options[ele.selectedIndex].text;
1064 $("#resSupportLink")[0].href = ele.value;
1066 // SAVE the device DATA
1067 NOKIA.helper.createCookie('NOKIA_EMULATOR_DEVICE', NOKIA.currentDevice);
1069 NOKIA.emulator.render();
1070 NOKIA.helper.loadPreferences();
1073 // Hack for Mac firefox
1074 if (/Mac/i.test(navigator.userAgent)) {
1075 if (!(/AppleWebKit/i.test(navigator.userAgent))) {
1076 $("#resOptions")[0].size = '4';
1081 // WRT Version controls
1082 $('#wrt_version_1_0').change(function(){
1083 NOKIA.helper.version(this);
1086 $('#wrt_version_1_1').change(function(){
1087 NOKIA.helper.version(this);
1091 $("#orientationIcon").click(function(){
1092 var mode = (NOKIA.mode == 'portrait') ? 'landscape' : 'portrait';
1093 NOKIA.emulator.setMode(mode);
1094 $("#WidgetArea")[0].className = 'hs_'+NOKIA.mode;
1098 $("#iframeMask").click(function(){
1100 $("#PreferencesBtn").show();
1101 $("#orientationIcon").hide();
1102 $("#iframeMask").hide();
1103 $("#loaderDiv").hide();
1105 NOKIA.menu.is_dimmed = false;
1107 $("#WidgetArea")[0].className = '';
1109 NOKIA.menu.softkeys_visibility = true;
1110 NOKIA.menu.showSoftKeys();
1115 // MenuItems DIV events
1116 $("#MenuItemsArea").mouseover(function(){
1117 if(NOKIA.helper.intervalId)
1118 clearInterval(NOKIA.helper.intervalId);
1120 $("#MenuItemsArea").show();
1123 $("#MenuItemsArea").mouseout(function(){
1124 if(NOKIA.helper.intervalId)
1125 clearInterval(NOKIA.helper.intervalId);
1127 NOKIA.helper.intervalId = setTimeout(function(){
1135 select : function(event, ui){
1136 if(parseInt(ui.index) == 1)
1138 $("#event-icons").show();
1139 $("#event-battery-info").hide();
1140 $("#event-messaging-info").hide();
1141 $("#event-memory-info").hide();
1143 // WRT versionn check
1144 if(NOKIA.version == 'WRT 1.1')
1146 $("#event-messaging")[0].className = 'active';
1147 $("#event-memory")[0].className = 'active';
1150 $("#event-messaging")[0].className = 'inactive';
1151 $("#event-memory")[0].className = 'inactive';
1153 $("#event-battery")[0].className = 'active';
1154 }else if(parseInt(ui.index) == 0)
1156 $("#settings-view").show();
1157 $("#mini-view-info").hide();
1168 $("#event-battery").click(function(event){
1169 if(event.target.className == 'active')
1171 $("#event-icons").hide();
1172 $("#event-battery-info").show();
1175 $('#slider').slider('option', 'value', NOKIA.emulator.child._BRIDGE_REF.helper.getBatteryStrength());
1176 NOKIA.emulator.child._BRIDGE_REF.helper.getBatteryStrength()
1177 $('#slider').slider('option', 'value', 10);
1178 $('#slider').slider();
1183 $("#event-battery-back").click(function(event){
1184 $("#event-icons").show();
1185 $("#event-battery-info").hide();
1190 $("#event-messaging").click(function(event){
1191 if(event.target.className == 'active')
1193 $("#event-icons").hide();
1194 $("#event-messaging-info").show();
1198 $("#event-messaging-back").click(function(event){
1199 $("#event-icons").show();
1200 $("#event-messaging-info").hide();
1205 $("#event-memory").click(function(event){
1206 if(event.target.className == 'active')
1208 $("#event-icons").hide();
1209 $("#event-memory-info").show();
1213 $("#event-memory-back").click(function(event){
1214 $("#event-icons").show();
1215 $("#event-memory-info").hide();
1219 // for minView more info
1220 $("#mini-view-back").click(function(event){
1221 $("#settings-view").show();
1222 $("#mini-view-info").hide();
1227 $('#slider').slider({
1234 slide: function(event, ui) {
1235 $("#slider-value-panel > span").html(ui.value.toString());
1239 // Bind Buttons to trigger values to WRT 1.0 / 1.1 bindings
1241 $("#connect-charger").click(NOKIA.helper.triggerEvents);
1242 $("#disconnect-charger").click(NOKIA.helper.triggerEvents);
1243 $("#update-batter-strength").click(NOKIA.helper.triggerEvents);
1245 $("#send-sms").click(NOKIA.helper.triggerEvents);
1246 $("#send-mms").click(NOKIA.helper.triggerEvents);
1248 $("#connect-memory-card").click(NOKIA.helper.triggerEvents);
1249 $("#disconnect-memory-card").click(NOKIA.helper.triggerEvents);
1253 setHomeScreen : function()
1255 // HomeScreen Support
1256 if (NOKIA.deviceList[NOKIA.currentDevice].homeScreenSupport) {
1258 if (typeof NOKIA.emulator.plist.MiniViewEnabled != 'undefined') {
1259 if (NOKIA.emulator.plist.MiniViewEnabled != 'false')
1261 $("#WidgetArea")[0].className = 'hs_' + NOKIA.mode;
1264 NOKIA.menu.softkeys_visibility = false;
1265 NOKIA.menu.cancel();
1266 NOKIA.menu.is_dimmed = true;
1269 $("#loaderDiv").html("Click on widget for Return to Full view");
1270 $("#loaderDiv")[0].className = 'green';
1271 $("#loaderDiv").show();
1273 $("#iframeMask").show();
1274 $("#orientationIcon").show();
1275 $("#PreferencesBtn").hide();
1277 $("#PreferencesTab").dialog('close');
1285 getElementsLengthInObject : function(items){
1287 for (var i in items)
1289 if(!items[i].isDimmed)
1296 triggerEvents : function(event)
1298 if(typeof event.target.id == 'undefined')
1301 switch(event.target.id)
1304 case 'connect-charger':
1305 NOKIA.helper.trigger("power", "chargerconnected", 1);
1306 if(NOKIA.version == 'WRT 1.1')
1307 NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.ChargingStatus", {Status: 1});
1310 case 'disconnect-charger':
1311 NOKIA.helper.trigger("power", "chargerconnected", 0);
1312 if(NOKIA.version == 'WRT 1.1')
1313 NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.ChargingStatus", {Status: 0});
1316 case 'update-batter-strength':
1317 var chargeValue = parseInt($('#slider').slider('value'));
1318 NOKIA.helper.trigger("power", "chargelevel", chargeValue);
1319 if(NOKIA.version == 'WRT 1.1')
1320 NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.BatteryStrength", {Status: chargeValue});
1325 if(NOKIA.version == 'WRT 1.1')
1326 NOKIA.helper.triggerSapi("Service.Messaging", "NewMessage", {MessageType: 'SMS'});
1329 if(NOKIA.version == 'WRT 1.1')
1330 NOKIA.helper.triggerSapi("Service.Messaging", "NewMessage", {MessageType: 'MMS'});
1334 case 'connect-memory-card':
1335 if(NOKIA.version == 'WRT 1.1')
1336 NOKIA.helper.triggerSapi("Service.SysInfo", "Memory.MemoryCard", {Status: 1});
1338 case 'disconnect-memory-card':
1339 if(NOKIA.version == 'WRT 1.1')
1340 NOKIA.helper.triggerSapi("Service.SysInfo", "Memory.MemoryCard", {Status: 0});
1345 triggerSapi : function(provider, eventType, data){
1346 NOKIA.emulator.child.device.implementation.triggerListener(provider, eventType, data);
1349 trigger : function(provider, eventType, data){
1350 NOKIA.emulator.child.widget.triggerListener(provider, eventType, data);
1353 showMiniviewHelp : function(){
1354 $("#settings-view").hide();
1355 $("#mini-view-info").show();
1358 checkDependencies : function(){
1360 for(var key in NOKIA.scriptsLoaded)
1362 if(!NOKIA.scriptsLoaded[key])
1367 NOKIA.menu.setLsk(NOKIA.emulator.child.menu.show);
1370 NOKIA.menu.setRsk(NOKIA.menu.exit);
1378 * NOKIA.layout functions
1380 NOKIA.namespace('layout');
1382 _console_minimized : true,
1383 _console_enabled : false,
1384 _consoleWindowHeight : 200,
1385 _consoleHeaderHeight : 31,
1389 // Toggle console window
1390 $('#Console-Toggle-Button').click(function(){
1392 NOKIA.layout._console_minimized = (NOKIA.layout._console_minimized) ? false : true;
1393 NOKIA.layout.render();
1397 $("#Console-Clear-Button").click(function(){
1398 $("#preview-ui-bottom-body")[0].innerHTML = '';
1402 $('#preview-ui-bottom').show();
1403 NOKIA.layout.render();
1406 log : function(type, msg){
1407 var p = document.createElement('p');
1410 var divBody = $('#preview-ui-bottom-body')
1412 divBody[0].scrollTop = divBody[0].scrollHeight;
1416 render : function(){
1417 var _width = parseInt(window.innerWidth);
1418 var _height = parseInt(window.innerHeight);
1420 if(!NOKIA.layout._console_enabled)
1422 $('#preview-ui-bottom').css({
1426 $('#preview-ui-top').css({
1427 height: _height+'px'
1434 if(!NOKIA.layout._console_minimized)
1436 $('#Console-Toggle-Button')[0].className = 'open';
1438 // set STYLE details for TOP window
1439 $('#preview-ui-top').css({
1440 height: parseInt(_height - NOKIA.layout._consoleWindowHeight) + 'px'
1443 // set STYLE details for Bottom window
1444 $('#preview-ui-bottom').css({
1445 height: NOKIA.layout._consoleWindowHeight + 'px',
1449 $('#preview-ui-bottom-header').css({
1450 height: NOKIA.layout._consoleHeaderHeight + 'px'
1453 $('#preview-ui-bottom-body').css({
1454 height: parseInt(NOKIA.layout._consoleWindowHeight - NOKIA.layout._consoleHeaderHeight) + 'px',
1458 // Auto scroll when console window opened from MINIMIZED => MAXIMIZED state
1459 window.setTimeout(function(){
1460 $('#preview-ui-bottom-body')[0].scrollTop = $('#preview-ui-bottom-body')[0].scrollHeight;
1464 $('#Console-Toggle-Button')[0].className = 'close';
1466 // set STYLE details for TOP window
1467 $('#preview-ui-top').css({
1468 height: parseInt(_height - NOKIA.layout._consoleHeaderHeight) + 'px'
1471 // set STYLE details for Bottom window
1472 $('#preview-ui-bottom').css({
1473 height: NOKIA.layout._consoleHeaderHeight + 'px',
1477 $('#preview-ui-bottom-header').css({
1478 height: NOKIA.layout._consoleHeaderHeight + 'px',
1482 $('#preview-ui-bottom-body').css({
1491 $(document).ready(function () {
1495 window.onresize = NOKIA.layout.render;