X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=project%2Fjs%2Fmain.js;h=1e308b43a34c92eef2a0c242729586410804e50e;hb=b37c4dc99f726e5ce8883ff92b2b23ae95ce1b1a;hp=f9de5958aa5694e2884468f9ca310df93a1a3727;hpb=df64cfb6dda47b1c6c63939cb5f6026464c50b54;p=apps%2Fweb%2Fsample%2FSystemInfo.git diff --git a/project/js/main.js b/project/js/main.js index f9de595..1e308b4 100644 --- a/project/js/main.js +++ b/project/js/main.js @@ -14,136 +14,159 @@ * limitations under the License. */ -var gInfoTitle = "", gInfo = "", gBatteryListener; - -$(document).delegate("#main", "pageinit", function() { - $("#storage-info").bind("vclick", function() { - getSystemProperty("STORAGE", onStorageSuccess); - return false; - }); - $("#battery-info").bind("vclick", function() { - getSystemProperty("BATTERY", onBatterySuccess); - return false; - }); - $("#cpu-info").bind("vclick", function() { - getSystemProperty("CPU", onCpuInfoSuccess); - return false; - }); - $("#display-info").bind("vclick", function() { - getSystemProperty("DISPLAY", onDisplaySuccess); - return false; - }); - - $("#orientation-info").bind("vclick", function() { - getSystemProperty("DEVICE_ORIENTATION", onOrientationSuccess); - return false; - }); - - $(window).on('tizenhwkey', function (e) { - if (e.originalEvent.keyName === "back") { - if ($.mobile.activePage.attr('id') === 'main') { - tizen.application.getCurrentApplication().exit(); - } else { - history.back(); - } - } - }); -}); +/*jslint devel: true*/ +/*global $, tizen, window*/ + +var gInfoTitle = '', gInfo = '', gBatteryListener; -$(document).delegate("#info", "pageinit", function() { - $("#info").bind("pagebeforeshow", function() { - $("#info-title").html(gInfoTitle); - $("#info-list").html(gInfo).trigger("create").listview("refresh"); - }); +$(document).delegate('#info', 'pageinit', function () { + 'use strict'; + $('#info').bind('pagebeforeshow', function () { + $('#info-title').html(gInfoTitle); + $('#info-list').html(gInfo).trigger('create').listview('refresh'); + }); }); function onError(e) { - alert("Error: " + e.message); + 'use strict'; + alert('Error: ' + e.message); } function make2lineListItem(title, value) { - return '
  • ' - + title - + '' - + value - + '
  • '; + 'use strict'; + return '
  • ' + + title + + '' + + value + + '
  • '; } function make1lineListItem(value) { - return '
  • ' + value + '
  • '; + 'use strict'; + return '
  • ' + value + '
  • '; } function makeDividerListItem(value) { - return '
  • ' + value + '
  • '; + 'use strict'; + return '
  • ' + value + '
  • '; } function onStorageSuccess(storages) { - gInfoTitle = "Storages (" + storages.units.length + ")"; - gInfo = ""; - for (var i = 0; i < storages.units.length; i++) { - gInfo += makeDividerListItem("Storage " + (i + 1)) - + make2lineListItem("Type", storages.units[i].type) - + make2lineListItem("Capacity", Math.floor(storages.units[i].capacity / 1000000) + " MB") - + make2lineListItem("Available capacity", Math.floor(storages.units[i].availableCapacity / 1000000) + " MB") - + make2lineListItem("Removable", (storages.units[i].isRemoveable == true ? "Yes" : "No")); - } - - $.mobile.changePage("#info"); + 'use strict'; + var i; + gInfoTitle = 'Storages (' + storages.units.length + ')'; + gInfo = ''; + for (i = 0; i < storages.units.length; i = i + 1) { + gInfo += makeDividerListItem('Storage ' + (i + 1)) + + make2lineListItem('Type', storages.units[i].type) + + make2lineListItem('Capacity', + Math.floor(storages.units[i].capacity / 1000000) + ' MB') + + make2lineListItem('Available capacity', + Math.floor(storages.units[i].availableCapacity / 1000000) + + ' MB') + + make2lineListItem('Removable', + (storages.units[i].isRemoveable === true ? 'Yes' : 'No')); + } + + $.mobile.changePage('#info'); } function onBatterySuccess(battery) { - gInfoTitle = "Battery"; - gInfo = make2lineListItem("Level", battery.level) - + make2lineListItem("Charging", (battery.isCharging == true ? "Yes" : "No")); + 'use strict'; + gInfoTitle = 'Battery'; + gInfo = make2lineListItem('Level', battery.level) + + make2lineListItem('Charging', + (battery.isCharging === true ? 'Yes' : 'No')); - $.mobile.changePage("#info"); + $.mobile.changePage('#info'); } function onCpuInfoSuccess(cpu) { - gInfoTitle = "CPU"; - gInfo = make2lineListItem("Load", cpu.load); + 'use strict'; + gInfoTitle = 'CPU'; + gInfo = make2lineListItem('Load', cpu.load); - $.mobile.changePage("#info"); + $.mobile.changePage('#info'); } function onDisplaySuccess(display) { - gInfoTitle = "Display"; - gInfo = makeDividerListItem("Resolution") - + make2lineListItem("Width", display.resolutionWidth) - + make2lineListItem("Height", display.resolutionHeight) - + makeDividerListItem("Dots per inch") - + make2lineListItem("Horizontal", display.dotsPerInchWidth) - + make2lineListItem("Vertical", display.dotsPerInchHeight) - + makeDividerListItem("Physical size") - + make2lineListItem("Width", display.physicalWidth) - + make2lineListItem("Height", display.physicalHeight) - + makeDividerListItem("Brightness") - + make1lineListItem(display.brightness); - - $.mobile.changePage("#info"); + 'use strict'; + gInfoTitle = 'Display'; + gInfo = makeDividerListItem('Resolution') + + make2lineListItem('Width', display.resolutionWidth) + + make2lineListItem('Height', display.resolutionHeight) + + makeDividerListItem('Dots per inch') + + make2lineListItem('Horizontal', display.dotsPerInchWidth) + + make2lineListItem('Vertical', display.dotsPerInchHeight) + + makeDividerListItem('Physical size') + + make2lineListItem('Width', display.physicalWidth) + + make2lineListItem('Height', display.physicalHeight) + + makeDividerListItem('Brightness') + + make1lineListItem(display.brightness); + + $.mobile.changePage('#info'); } function onDeviceSuccess(device) { - gInfoTitle = "Device"; - gInfo = make2lineListItem("IMEI", device.imei) - + make2lineListItem("Model", device.model) - + make2lineListItem("Version", device.version) - + make2lineListItem("Vendor", device.vendor); - - $.mobile.changePage("#info"); + 'use strict'; + gInfoTitle = 'Device'; + gInfo = make2lineListItem('IMEI', device.imei) + + make2lineListItem('Model', device.model) + + make2lineListItem('Version', device.version) + + make2lineListItem('Vendor', device.vendor); + + $.mobile.changePage('#info'); } function onOrientationSuccess(orientation) { - gInfoTitle = "Device orientation"; - gInfo = make2lineListItem("Status", orientation.status); + 'use strict'; + gInfoTitle = 'Device orientation'; + gInfo = make2lineListItem('Status', orientation.status); - $.mobile.changePage("#info"); + $.mobile.changePage('#info'); } function getSystemProperty(property, onSuccess) { - try { - tizen.systeminfo.getPropertyValue(property, onSuccess, onError); - } catch (e) { - alert("Exception: " + e.message); - } + 'use strict'; + try { + tizen.systeminfo.getPropertyValue(property, onSuccess, onError); + } catch (e) { + alert('Exception: ' + e.message); + } } + +$(document).delegate('#main', 'pageinit', function () { + 'use strict'; + $('#storage-info').bind('vclick', function () { + getSystemProperty('STORAGE', onStorageSuccess); + return false; + }); + $('#battery-info').bind('vclick', function () { + getSystemProperty('BATTERY', onBatterySuccess); + return false; + }); + $('#cpu-info').bind('vclick', function () { + getSystemProperty('CPU', onCpuInfoSuccess); + return false; + }); + $('#display-info').bind('vclick', function () { + getSystemProperty('DISPLAY', onDisplaySuccess); + return false; + }); + + $('#orientation-info').bind('vclick', function () { + getSystemProperty('DEVICE_ORIENTATION', onOrientationSuccess); + return false; + }); + + $(window).on('tizenhwkey', function (e) { + if (e.originalEvent.keyName === 'back') { + if ($.mobile.activePage.attr('id') === 'main') { + tizen.application.getCurrentApplication().exit(); + } else { + history.back(); + } + } + }); +}); +