Skip to content

Instantly share code, notes, and snippets.

@ds0nt
Last active August 29, 2015 13:57
Show Gist options
  • Save ds0nt/9681362 to your computer and use it in GitHub Desktop.
Save ds0nt/9681362 to your computer and use it in GitHub Desktop.
var camOpen = function(source) {
var camoptions = {
limit: 1,
destinationType: Camera.DestinationType.FILE_URI,
targetWidth: 512,
targetHeight: 512,
sourceType: (source == 1) ? Camera.PictureSourceType.CAMERA : Camera.PictureSourceType.PHOTOLIBRARY
};
navigator.camera.getPicture(function onSuccess(file) {
api.upload_head_pic(file, function onSuccess(result) {
var data = JSON.parse(result.response);
if (!data.success) {
app.alertError('Could not upload your photo.');
return;
}
p.profile_view.imageholder.change(data.portrait_url);
sidemenu.updatePhoto(data.portrait_url);
app.data.user.portrait_url = data.portrait_url;
navigator.camera.cleanup();
},
function onError(error) {
app.alertError('Could not upload your photo.');
console.log(error);
navigator.camera.cleanup();
});
},
function onError(error) {
app.alertError('Could not access that file.');
console.error(error);
}, camoptions);
};
this.container.onTap('#edit-profile', function() {
app.openChild(p.profile_edit);
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment