Hello,
My code works on the older version of Framework7 but for the life of me, I can’t seem to properly migrate it to V2. Can someone help me out please? Here’s the code in the old F7:
HTML:
<a href="#" class="button button-fill" onclick="capturePhotoWithFile();">Take A Picture</a> <br>
<a href="#" class="button button-fill" onclick="getPhoto(navigator.camera.PictureSourceType.SAVEDPHOTOALBUM);">Select from Gallery</a><br>
<div id="uplimgcontainer">
<img style="display:none; max-width:100%" id="largeImage" src="" />
</div>
<div id='photocap'></div>
<a href="#" class="button button-fill" style="display:none;" id="uploadpicbtn" onclick="uploadpic()">Upload Picture</a><br>
</form>
JS:
// Wait for device API libraries to load
//
document.addEventListener(“deviceready”,onDeviceReady,false);
// device APIs are available
//
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
//alert("device is ready for camera");
}
…
function onPhotoFileSuccess(imageData) {
alert("onPhotoFileSuccess was called. imageData: "+imageData);
// Get image handle
console.log(JSON.stringify(imageData));
// Get image handle
//
var largeImage = document.getElementById('largeImage');
// Unhide image elements
//
largeImage.style.display = 'block';
document.getElementById('uploadpicbtn').style.display="block";
// Show the captured photo
// The inline CSS rules are used to resize the image
//
largeImage.src = imageData;
uploadimgdata=imageData;
}
// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
alert("onPhotoURISuccess was called. imageuri: "+imageURI);
// Uncomment to view the image file URI
// console.log(imageURI);
// Get image handle
//
var largeImage = document.getElementById('largeImage');
// Unhide image elements
//
largeImage.style.display = 'block';
document.getElementById('uploadpicbtn').style.display="block";
// Show the captured photo
// The inline CSS rules are used to resize the image
//
//custom code to fix image uri
if (imageURI.substring(0,21)=="content://com.android") {
photo_split=imageURI.split("%3A");
imageURI="content://media/external/images/media/"+photo_split[1];
}
largeImage.src = imageURI;
document.getElementById('uploadpicbtn').style.display="block";
uploadimgdata=imageURI;
}
function capturePhotoWithFile() {
navigator.camera.getPicture(onPhotoFileSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI });
}
// A button will call this function
//
function getPhoto(source) {
alert("getphoto was called. source= "+source);
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}
Thanks in advance!