Created
August 20, 2012 12:38
-
-
Save boydlee/3403722 to your computer and use it in GitHub Desktop.
CommonJS module to access photo gallery and camera and return resulting image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
PhotoSelector.js | |
Gets a photo from camera or gallery | |
Usage: | |
var ps = require('PhotoSelector'); | |
var select = new ps.PhotoSelector(); | |
//get a photo from the camera | |
select.fromCamera(false, true, function(success){}, function(failed){}, function(cancelled){}); | |
//or get a photo from the gallery | |
select.fromGallery(function(success){}, function(failed){}, function(cancelled){}); | |
*/ | |
function PhotoSelector(){ | |
}; | |
/* | |
* | |
*/ | |
PhotoSelector.prototype.fromCamera = function(saveToGallery, allowEditing, success, failure, cancel) { | |
Titanium.Media.showCamera({ | |
success:function(event) | |
{ | |
Ti.API.debug('Our type was: '+ event.mediaType); | |
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) | |
{ | |
success(event.media); | |
} | |
}, | |
cancel: cancel, | |
error:function(err) | |
{ | |
failure(err); | |
}, | |
saveToPhotoGallery: saveToGallery, | |
allowEditing: allowEditing, | |
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO] | |
}); | |
}; | |
/* | |
* | |
*/ | |
PhotoSelector.prototype.fromGallery = function(success, failure, cancel) { | |
Titanium.Media.openPhotoGallery({ | |
success:function(event) | |
{ | |
Ti.API.debug('Our type was: '+event.mediaType); | |
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) | |
{ | |
success(event.media); | |
} | |
}, | |
cancel: cancel, | |
error:function(err) | |
{ | |
failure(err); | |
}, | |
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO] | |
}); | |
}; | |
//finally, | |
exports.PhotoSelector = PhotoSelector; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment