You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/01/10 15:33:34 UTC
js commit: [all] Shrink Camera.js by adding argscheck.getValue(val,
default).
Updated Branches:
refs/heads/master 46daf8446 -> b9f5ebd4f
[all] Shrink Camera.js by adding argscheck.getValue(val, default).
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/b9f5ebd4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/b9f5ebd4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/b9f5ebd4
Branch: refs/heads/master
Commit: b9f5ebd4f6e82cd3e26997aed9065dec268f34a3
Parents: 46daf84
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Dec 14 15:17:09 2012 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Jan 10 09:33:28 2013 -0500
----------------------------------------------------------------------
lib/common/argscheck.js | 5 ++
lib/common/plugin/Camera.js | 100 ++++++--------------------------------
2 files changed, 21 insertions(+), 84 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/b9f5ebd4/lib/common/argscheck.js
----------------------------------------------------------------------
diff --git a/lib/common/argscheck.js b/lib/common/argscheck.js
index edd47a5..524b435 100644
--- a/lib/common/argscheck.js
+++ b/lib/common/argscheck.js
@@ -71,6 +71,11 @@ function checkArgs(spec, functionName, args, opt_callee) {
}
}
+function getValue(value, defaultValue) {
+ return value === undefined ? defaultValue : value;
+}
+
moduleExports.checkArgs = checkArgs;
+moduleExports.getValue = getValue;
moduleExports.enableChecks = true;
http://git-wip-us.apache.org/repos/asf/cordova-js/blob/b9f5ebd4/lib/common/plugin/Camera.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/Camera.js b/lib/common/plugin/Camera.js
index e4a1efa..068d7d7 100644
--- a/lib/common/plugin/Camera.js
+++ b/lib/common/plugin/Camera.js
@@ -19,7 +19,8 @@
*
*/
-var exec = require('cordova/exec'),
+var argscheck = require('cordova/argscheck'),
+ exec = require('cordova/exec'),
Camera = require('cordova/plugin/CameraConstants');
var cameraExport = {};
@@ -40,90 +41,21 @@ for (var key in Camera) {
* @param {Object} options
*/
cameraExport.getPicture = function(successCallback, errorCallback, options) {
+ argscheck.checkArgs('fFO', 'Camera.getPicture', arguments);
options = options || {};
- // successCallback required
- if (typeof successCallback != "function") {
- console.log("Camera Error: successCallback is not a function");
- return;
- }
-
- // errorCallback optional
- if (errorCallback && (typeof errorCallback != "function")) {
- console.log("Camera Error: errorCallback is not a function");
- return;
- }
-
- var quality = 50;
- if (typeof options.quality == "number") {
- quality = options.quality;
- } else if (typeof options.quality == "string") {
- var qlity = parseInt(options.quality, 10);
- if (isNaN(qlity) === false) {
- quality = qlity.valueOf();
- }
- }
-
- var destinationType = Camera.DestinationType.FILE_URI;
- if (typeof options.destinationType == "number") {
- destinationType = options.destinationType;
- }
-
- var sourceType = Camera.PictureSourceType.CAMERA;
- if (typeof options.sourceType == "number") {
- sourceType = options.sourceType;
- }
-
- 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 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 encodingType = Camera.EncodingType.JPEG;
- if (typeof options.encodingType == "number") {
- encodingType = options.encodingType;
- }
-
- var mediaType = Camera.MediaType.PICTURE;
- if (typeof options.mediaType == "number") {
- mediaType = options.mediaType;
- }
- var allowEdit = false;
- if (typeof options.allowEdit == "boolean") {
- allowEdit = options.allowEdit;
- } else if (typeof options.allowEdit == "number") {
- allowEdit = options.allowEdit <= 0 ? false : true;
- }
- var correctOrientation = false;
- if (typeof options.correctOrientation == "boolean") {
- correctOrientation = options.correctOrientation;
- } else if (typeof options.correctOrientation == "number") {
- correctOrientation = options.correctOrientation <=0 ? false : true;
- }
- var saveToPhotoAlbum = false;
- if (typeof options.saveToPhotoAlbum == "boolean") {
- saveToPhotoAlbum = options.saveToPhotoAlbum;
- } else if (typeof options.saveToPhotoAlbum == "number") {
- saveToPhotoAlbum = options.saveToPhotoAlbum <=0 ? false : true;
- }
- var popoverOptions = null;
- if (typeof options.popoverOptions == "object") {
- popoverOptions = options.popoverOptions;
- }
+ var getValue = argscheck.getValue;
+
+ var quality = getValue(options.quality, 50);
+ var destinationType = getValue(options.destinationType, Camera.DestinationType.FILE_URI);
+ var sourceType = getValue(options.sourceType, Camera.PictureSourceType.CAMERA);
+ var targetWidth = getValue(options.targetWidth, -1);
+ var targetHeight = getValue(options.targetHeight, -1);
+ var encodingType = getValue(options.encodingType, Camera.EncodingType.JPEG);
+ var mediaType = getValue(options.mediaType, Camera.MediaType.PICTURE);
+ var allowEdit = getValue(options.allowEdit, 0) > 0;
+ var correctOrientation = getValue(options.correctOrientation, 0) > 0;
+ var saveToPhotoAlbum = getValue(options.saveToPhotoAlbum, 0) > 0;
+ var popoverOptions = getValue(options.popoverOptions, null);
var args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType,
mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions];