You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/03/01 20:49:14 UTC

[1/2] git commit: blasting Camera Constants onto the camera plugin

Updated Branches:
  refs/heads/master 2d93bb435 -> 2468db948


blasting Camera Constants onto the camera plugin


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/2468db94
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/2468db94
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/2468db94

Branch: refs/heads/master
Commit: 2468db948b2a2b4d28d18b22d863e27bc5341fe3
Parents: f26ef4f
Author: Fil Maj <ma...@gmail.com>
Authored: Thu Mar 1 11:37:49 2012 -0800
Committer: Fil Maj <ma...@gmail.com>
Committed: Thu Mar 1 11:48:40 2012 -0800

----------------------------------------------------------------------
 lib/plugin/Camera.js |  123 ++++++++++++++++++++++++---------------------
 1 files changed, 65 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/2468db94/lib/plugin/Camera.js
----------------------------------------------------------------------
diff --git a/lib/plugin/Camera.js b/lib/plugin/Camera.js
index 816ae9d..5aa8025 100644
--- a/lib/plugin/Camera.js
+++ b/lib/plugin/Camera.js
@@ -1,75 +1,82 @@
 var exec = require('cordova/exec'),
     Camera = require('cordova/plugin/CameraConstants');
 
-module.exports = {
-    /**
-     * Gets a picture from source defined by "options.sourceType", and returns the
-     * image as defined by the "options.destinationType" option.
+var cameraExport = {};
 
-     * The defaults are sourceType=CAMERA and destinationType=FILE_URL.
-     *
-     * @param {Function} successCallback
-     * @param {Function} errorCallback
-     * @param {Object} options
-     */
-    getPicture: function (successCallback, errorCallback, options) {
+// Tack on the Camera Constants to the base camera plugin.
+for (var key in Camera) {
+    cameraExport[key] = Camera[key];
+}
 
-        // successCallback required
-        if (typeof successCallback != "function") {
-            console.log("Camera Error: successCallback is not a function");
-            return;
-        }
+/**
+ * Gets a picture from source defined by "options.sourceType", and returns the
+ * image as defined by the "options.destinationType" option.
 
-        // errorCallback optional
-        if (errorCallback && (typeof errorCallback != "function")) {
-            console.log("Camera Error: errorCallback is not a function");
-            return;
-        }
+ * The defaults are sourceType=CAMERA and destinationType=FILE_URL.
+ *
+ * @param {Function} successCallback
+ * @param {Function} errorCallback
+ * @param {Object} options
+ */
+cameraExport.getPicture = function(successCallback, errorCallback, options) {
+    // successCallback required
+    if (typeof successCallback != "function") {
+        console.log("Camera Error: successCallback is not a function");
+        return;
+    }
 
-        if (options && typeof options.quality == "number") {
-            quality = options.quality;
-        } else if (options && typeof options.quality == "string") {
-            var qlity = parseInt(options.quality, 10);
-            if (isNaN(qlity) === false) {
-                quality = qlity.valueOf();
-            }
-        }
+    // errorCallback optional
+    if (errorCallback && (typeof errorCallback != "function")) {
+        console.log("Camera Error: errorCallback is not a function");
+        return;
+    }
 
-        var destinationType = Camera.DestinationType.FILE_URL;
-        if (typeof options.destinationType == "number") {
-            destinationType = options.destinationType;
-        }
 
-        var sourceType = Camera.PictureSourceType.CAMERA;
-        if (typeof options.sourceType == "number") {
-            sourceType = options.sourceType;
+    if (options && typeof options.quality == "number") {
+        quality = options.quality;
+    } else if (options && typeof options.quality == "string") {
+        var qlity = parseInt(options.quality, 10);
+        if (isNaN(qlity) === false) {
+            quality = qlity.valueOf();
         }
+    }
 
-        var targetWidth = -1;
-        if (typeof options.targetWidth == "number") {
-            targetWidth = options.targetWidth;
-        } else if (typeof options.targetWidth == "string") {
-            var width = parseInt(options.targetWidth, 10);
-            if (isNaN(width) === false) {
-                targetWidth = width.valueOf();
-            }
-        }
+    var destinationType = Camera.DestinationType.FILE_URL;
+    if (typeof options.destinationType == "number") {
+        destinationType = options.destinationType;
+    }
+
+    var sourceType = Camera.PictureSourceType.CAMERA;
+    if (typeof options.sourceType == "number") {
+        sourceType = options.sourceType;
+    }
 
-        var targetHeight = -1;
-        if (typeof options.targetHeight == "number") {
-            targetHeight = options.targetHeight;
-        } else if (typeof options.targetHeight == "string") {
-            var height = parseInt(options.targetHeight, 10);
-            if (isNaN(height) === false) {
-                targetHeight = height.valueOf();
-            }
+    var targetWidth = -1;
+    if (typeof options.targetWidth == "number") {
+        targetWidth = options.targetWidth;
+    } else if (typeof options.targetWidth == "string") {
+        var width = parseInt(options.targetWidth, 10);
+        if (isNaN(width) === false) {
+            targetWidth = width.valueOf();
         }
+    }
 
-        var encodingType = Camera.EncodingType.JPEG;
-        if (typeof options.encodingType == "number") {
-            encodingType = options.encodingType;
+    var targetHeight = -1;
+    if (typeof options.targetHeight == "number") {
+        targetHeight = options.targetHeight;
+    } else if (typeof options.targetHeight == "string") {
+        var height = parseInt(options.targetHeight, 10);
+        if (isNaN(height) === false) {
+            targetHeight = height.valueOf();
         }
+    }
 
-        exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType]);
+    var encodingType = Camera.EncodingType.JPEG;
+    if (typeof options.encodingType == "number") {
+        encodingType = options.encodingType;
     }
-};
+
+    exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType]);
+}
+
+module.exports = cameraExport;