diff options
author | Struan Donald <struan@exo.org.uk> | 2013-09-24 17:24:43 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2013-09-24 17:24:43 +0100 |
commit | e90734afa8b6759841f8cc59c6bc987302ae06ce (patch) | |
tree | f4a908bc299d398f2c06e3ab6cc87a8ba2ce9187 | |
parent | 1cdb9a77ce4d7d8fe517cf305fa4928dd6dc6f60 (diff) |
split out photo option setting to a method
To remove duplication of option setting
-rw-r--r-- | src/js/views/photo.js | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/js/views/photo.js b/src/js/views/photo.js index a6bbb47..be4c1e2 100644 --- a/src/js/views/photo.js +++ b/src/js/views/photo.js @@ -27,12 +27,35 @@ } }, + getOptions: function(isFromAlbum) { + var options = { + destinationType: Camera.DestinationType.FILE_URI, + sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY + }; + + if ( ! isFromAlbum ) { + options.saveToPhotoAlbum = true; + options.sourceType = navigator.camera.PictureSourceType.CAMERA; + } + + // this helps with out of memory errors on iPhones but not on Android it seems + if ( ! FMS.isAndroid ) { + options.quality = 49; + options.correctOrientation = true; + } + + return options; + }, + takePhoto: function(e) { e.preventDefault(); $.mobile.loading('show'); $('#photo').hide(); var that = this; - navigator.camera.getPicture( function(imgURI) { that.addPhotoSuccess(imgURI); }, function(error) { that.addPhotoFail(error); }, { targetWidth: 2048, targetHeight: 2048, saveToPhotoAlbum: true, quality: 49, destinationType: Camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.CAMERA, correctOrientation: true }); + + var options = this.getOptions(); + + navigator.camera.getPicture( function(imgURI) { that.addPhotoSuccess(imgURI); }, function(error) { that.addPhotoFail(error); }, options); }, addPhoto: function(e) { @@ -40,7 +63,8 @@ $.mobile.loading('show'); $('#photo').hide(); var that = this; - navigator.camera.getPicture( function(imgURI) { that.addPhotoSuccess(imgURI); }, function(error) { that.addPhotoFail(error); }, { targetWidth: 2048, targetHeight: 2048, saveToPhotoAlbum: false, quality: 49, destinationType: Camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY, correctOrientation: true }); + var options = this.getOptions(true); + navigator.camera.getPicture( function(imgURI) { that.addPhotoSuccess(imgURI); }, function(error) { that.addPhotoFail(error); }, options); }, addPhotoSuccess: function(imgURI) { |