Permalink
Browse files

Cleanup of webos code

- fixed all of the indentation problems
- refactored some of the code that felt weird
- added some Palm globals to .jshintrc
  • Loading branch information...
1 parent 6881d72 commit 1ded2d3a144a8bc2bd71fbffad1420aa004502c3 @gtanner gtanner committed Oct 19, 2012
View
@@ -28,7 +28,7 @@
"dojo": false,
// Custom predefined globals.
- "predef": ["jasmine", "blackberry", "define", "alert", "prompt", "org", "deviceapis", "Osp", "_cordovaExec", "WinJS", "Windows", "MSApp"],
+ "predef": ["jasmine", "blackberry", "define", "alert", "prompt", "org", "deviceapis", "Osp", "_cordovaExec", "WinJS", "Windows", "MSApp", "PalmSystem", "PalmServiceBridge", "Acceleration"],
// Development
@@ -25,10 +25,10 @@ module.exports = {
if (window.PalmSystem) {
window.PalmSystem.stageReady();
}
- Mojo = window.Mojo || {};
- Mojo.stageActivated = function() {
+ window.Mojo = window.Mojo || {};
+ window.Mojo.stageActivated = function() {
console.error("stageActivated");
- }
+ };
},
objects: {
requestFileSystem:{
@@ -20,35 +20,33 @@
*/
var callback;
-module.exports={
+module.exports = {
+ /*
+ * Tells WebOS to put higher priority on accelerometer resolution. Also relaxes the internal garbage collection events.
+ * @param {Boolean} state
+ * Dependencies: Mojo.windowProperties
+ * Example:
+ * navigator.accelerometer.setFastAccelerometer(true)
+ */
+ setFastAccelerometer: function(state) {
+ navigator.windowProperties.fastAccelerometer = state;
+ navigator.window.setWindowProperties();
+ },
-/*
- * Tells WebOS to put higher priority on accelerometer resolution. Also relaxes the internal garbage collection events.
- * @param {Boolean} state
- * Dependencies: Mojo.windowProperties
- * Example:
- * navigator.accelerometer.setFastAccelerometer(true)
- */
-setFastAccelerometer: function(state) {
- navigator.windowProperties.fastAccelerometer = state;
- navigator.window.setWindowProperties();
-},
-
-/*
- * Starts the native acceleration listener.
- */
-start: function(win,fail,args) {
- console.error("webos plugin accelerometer start");
- window.removeEventListener("acceleration", callback);
- callback=function(event) {
- var accel = new Acceleration(event.accelX*-9.81, event.accelY*-9.81, event.accelZ*-9.81);
- win(accel);
+ /*
+ * Starts the native acceleration listener.
+ */
+ start: function(win,fail,args) {
+ console.error("webos plugin accelerometer start");
+ window.removeEventListener("acceleration", callback);
+ callback = function(event) {
+ var accel = new Acceleration(event.accelX*-9.81, event.accelY*-9.81, event.accelZ*-9.81);
+ win(accel);
+ };
+ document.addEventListener("acceleration", callback);
+ },
+ stop: function (win,fail,args) {
+ console.error("webos plugin accelerometer stop");
+ window.removeEventListener("acceleration", callback);
}
- document.addEventListener("acceleration", callback);
-},
-stop: function (win,fail,args) {
- console.error("webos plugin accelerometer stop");
- window.removeEventListener("acceleration", callback);
-}
-
-}
+};
@@ -19,54 +19,52 @@
*
*/
-module.exports={
+module.exports = {
+ isActivated: function(inWindow) {
+ inWindow = inWindow || window;
+ if(inWindow.PalmSystem) {
+ return inWindow.PalmSystem.isActivated;
+ }
+ return false;
+ },
-isActivated: function(inWindow) {
- inWindow = inWindow || window;
- if(inWindow.PalmSystem) {
- return inWindow.PalmSystem.isActivated
- }
- return false;
-},
-
-/*
- * Tell webOS to activate the current page of your app, bringing it into focus.
- * Example:
- * navigator.application.activate();
- */
-activate: function(inWindow) {
- inWindow = inWindow || window;
- if(inWindow.PalmSystem) {
- inWindow.PalmSystem.activate();
- }
-},
+ /*
+ * Tell webOS to activate the current page of your app, bringing it into focus.
+ * Example:
+ * navigator.application.activate();
+ */
+ activate: function(inWindow) {
+ inWindow = inWindow || window;
+ if(inWindow.PalmSystem) {
+ inWindow.PalmSystem.activate();
+ }
+ },
-/*
- * Tell webOS to deactivate your app.
- * Example:
- * navigator.application.deactivate();
- */
-deactivate: function(inWindow) {
- inWindow = inWindow || window;
- if(inWindow.PalmSystem) {
- inWindow.PalmSystem.deactivate();
- }
-},
+ /*
+ * Tell webOS to deactivate your app.
+ * Example:
+ * navigator.application.deactivate();
+ */
+ deactivate: function(inWindow) {
+ inWindow = inWindow || window;
+ if(inWindow.PalmSystem) {
+ inWindow.PalmSystem.deactivate();
+ }
+ },
-/*
- * Returns the identifier of the current running application (e.g. com.yourdomain.yourapp).
- * Example:
- * navigator.application.getIdentifier();
- */
-getIdentifier: function() {
- return PalmSystem.identifier;
-},
+ /*
+ * Returns the identifier of the current running application (e.g. com.yourdomain.yourapp).
+ * Example:
+ * navigator.application.getIdentifier();
+ */
+ getIdentifier: function() {
+ return PalmSystem.identifier;
+ },
-fetchAppId: function() {
- if (window.PalmSystem) {
- // PalmSystem.identifier: <appid> <processid>
- return PalmSystem.identifier.split(" ")[0];
+ fetchAppId: function() {
+ if (window.PalmSystem) {
+ // PalmSystem.identifier: <appid> <processid>
+ return PalmSystem.identifier.split(" ")[0];
+ }
}
-}
-
-}
+};
@@ -19,32 +19,25 @@
*
*/
-var service=require('cordova/plugin/webos/service');
+var service = require('cordova/plugin/webos/service');
module.exports = {
+ takePicture: function(successCallback, errorCallback, options) {
+ var filename = (options || {}).filename | "";
-takePicture: function(successCallback, errorCallback, options) {
-
- var filename = "";
-
- if (typeof options != 'undefined' && typeof options.filename != 'undefined') {
- filename = options.filename;
+ service.Request('palm://com.palm.applicationManager', {
+ method: 'launch',
+ parameters: {
+ id: 'com.palm.app.camera',
+ params: {
+ appId: 'com.palm.app.camera',
+ name: 'capture',
+ sublaunch: true,
+ filename: filename
+ }
+ },
+ onSuccess: successCallback,
+ onFailure: errorCallback
+ });
}
-
- this.service = service.Request('palm://com.palm.applicationManager', {
- method: 'launch',
- parameters: {
- id: 'com.palm.app.camera',
- params: {
- appId: 'com.palm.app.camera',
- name: 'capture',
- sublaunch: true,
- filename: filename
- }
- },
- onSuccess: successCallback,
- onFailure: errorCallback
- });
-}
-
-}
+};
@@ -20,22 +20,20 @@
*/
var CompassHeading = require('cordova/plugin/CompassHeading'),
-CompassError = require('cordova/plugin/CompassError');
+ CompassError = require('cordova/plugin/CompassError');
-module.exports={
- getHeading: function(win,lose) {
+module.exports = {
+ getHeading: function (win, lose) {
// only TouchPad and Pre3 have a Compass/Gyro
- if (device.name!=="TouchPad" && device.name!=="Pr"+String.fromCharCode(275)+"3") {
+ if (window.device.name !== "TouchPad" && window.device.name !== "Prē3") {
lose({code: CompassError.COMPASS_NOT_SUPPORTED});
} else {
console.error("webos plugin compass getheading");
- var that = this;
- this.onReadingChanged = function(e) {
- var heading = new CompassHeading(event.magHeading,event.trueHeading);
- document.removeEventListener("compass",that.onReadingChanged);
- win(heading);
- }
- document.addEventListener("compass", this.onReadingChanged);
+ var onReadingChanged = function (e) {
+ document.removeEventListener("compass", onReadingChanged);
+ win(CompassHeading(e.magHeading, e.trueHeading));
+ };
+ document.addEventListener("compass", onReadingChanged);
}
}
-}
+};
@@ -19,35 +19,26 @@
*
*/
-var service=require('cordova/plugin/webos/service')
+var service = require('cordova/plugin/webos/service');
-module.exports={
+module.exports = {
getDeviceInfo: function(success, fail, args) {
- console.log("webOS Plugin: Device - getDeviceInfo");
-
- this.request = service.Request('palm://com.palm.preferences/systemProperties', {
- method:"Get",
- parameters:{"key": "com.palm.properties.nduid" },
- onSuccess: postData
- });
-
- function postData(result) {
-
- var uuid=result["com.palm.properties.nduid"];
-
- var parsedData = JSON.parse(PalmSystem.deviceInfo);
-
- // fixed data
- var info={};
- info.cordova = "2.0.0";
- info.platform = "HP webOS";
- // variable data
- info.name = parsedData.modelName;
- info.version = parsedData.platformVersion;
- info.uuid = uuid;
-
- success(info);
+ console.log("webOS Plugin: Device - getDeviceInfo");
+
+ service.Request('palm://com.palm.preferences/systemProperties', {
+ method:"Get",
+ parameters:{"key": "com.palm.properties.nduid" },
+ onSuccess: function (result) {
+ var parsedData = JSON.parse(PalmSystem.deviceInfo);
+
+ success({
+ cordova: "2.0.0",
+ platform: "HP webOS",
+ name: parsedData.modelName,
+ version: parsedData.platformVersion,
+ uuid: result["com.palm.properties.nduid"]
+ });
+ }
+ });
}
-
- }
};
Oops, something went wrong.

0 comments on commit 1ded2d3

Please sign in to comment.