Webserver: -mod: prepare for phonegap -> use the camera object

This commit is contained in:
lukeIam committed 2013-12-13 18:03:03 +01:00
1 parent a91def2ff8
commit a8c5022bb0
1 file changed
+51 -9
+51 -9
View File
@@ -10,13 +10,14 @@ var serverBaseAddress = "";
$(document).ready(function () { $(document).ready(function () {
replaceTransitionHandler(); replaceTransitionHandler();
initTranslation();
initPageLoadHandler(); initPageLoadHandler();
initKeyboardPageHandler(); initKeyboardPageHandler();
initMainPageHandler(); initMainPageHandler();
initDiscoverPageHandler();
initLoginPageHandler(); initLoginPageHandler();
initHeartbeat(); initHeartbeat();
initVideoPopup(); initVideoPopup();
initTranslation();
}); });
function replaceTransitionHandler() { function replaceTransitionHandler() {
@@ -157,6 +158,23 @@ function initPageLoadHandler() {
$('#captureContainer').remove(); $('#captureContainer').remove();
} }
if (document.location.protocol == "file:"
&& typeof(navigator) != 'undefined'
&& typeof(navigator.camera) != 'undefined'
&& typeof(navigator.camera.getPicture) != 'undefined') {
navigator.camera.getPicture(function (imageData) {
$('#playerAvatar').prop("src", "data:image/jpeg;base64," + imageData);
$('#playerAvatar').data("changed", true);
}, function() {
//Fail - do nothing
}, {
destinationType: Camera.DestinationType.DATA_URL,
allowEdit: true,
correctOrientation: true,
saveToPhotoAlbum: true
});
} else {
$(document.body).append('<div id="captureContainer" style="height: 0px;width:0px; overflow:hidden;"> <input type="file" accept="image/*" id="capture" capture> </div>'); $(document.body).append('<div id="captureContainer" style="height: 0px;width:0px; overflow:hidden;"> <input type="file" accept="image/*" id="capture" capture> </div>');
$('#capture').change(function(eventData) { $('#capture').change(function(eventData) {
@@ -173,6 +191,7 @@ function initPageLoadHandler() {
}); });
$('#capture').click(); $('#capture').click();
}
}); });
} }
else { else {
@@ -758,11 +777,36 @@ function initMainPageHandler() {
}); });
}); });
function uploadImg(imgData) {
request({
url: "sendPhoto",
contentType: "application/json;charset=utf-8",
type: "POST",
data: JSON.stringify({ Photo: { base64Data: imgData } })
}, 'Uploading photo...');
}
$('#mainPageTakePhotoLink').click(function () { $('#mainPageTakePhotoLink').click(function () {
if ($('#captureContainer').length > 0) { if ($('#captureContainer').length > 0) {
$('#captureContainer').remove(); $('#captureContainer').remove();
} }
if (document.location.protocol == "file:"
&& typeof (navigator) != 'undefined'
&& typeof (navigator.camera) != 'undefined'
&& typeof (navigator.camera.getPicture) != 'undefined') {
navigator.camera.getPicture(function (imageData) {
uploadImg("data:image/jpeg;base64," + imageData);
}, function () {
//Fail - do nothing
}, {
destinationType: Camera.DestinationType.DATA_URL,
allowEdit: true,
correctOrientation: true,
saveToPhotoAlbum: true
});
} else {
$(document.body).append('<div id="captureContainer" style="height: 0px;width:0px; overflow:hidden;"> <input type="file" accept="image/*" id="capture" capture="camera"> </div>'); $(document.body).append('<div id="captureContainer" style="height: 0px;width:0px; overflow:hidden;"> <input type="file" accept="image/*" id="capture" capture="camera"> </div>');
$('#capture').change(function (eventData) { $('#capture').change(function (eventData) {
@@ -771,13 +815,8 @@ function initMainPageHandler() {
var reader = new FileReader(); var reader = new FileReader();
reader.onloadend = function (e) { reader.onloadend = function (e) {
request({ uploadImg(e.target.result);
url: "sendPhoto", $('#capture').remove();
contentType: "application/json;charset=utf-8",
type: "POST",
headers: { "session": sessionId },
data: JSON.stringify({ Photo: { base64Data: e.target.result } })
}, 'Uploading photo...');
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
@@ -785,6 +824,7 @@ function initMainPageHandler() {
}); });
$('#capture').click(); $('#capture').click();
}
}); });
$('#mainPageLogoutLink').click(function () { $('#mainPageLogoutLink').click(function () {
@@ -850,7 +890,7 @@ function initKeyboardPageHandler() {
}); });
} }
function initLoginPageHandler() { function initDiscoverPageHandler() {
var keyPressed = function (e) { var keyPressed = function (e) {
if (e.which == 13) { if (e.which == 13) {
$('#discoverConnect').click(); $('#discoverConnect').click();
@@ -877,8 +917,10 @@ function initLoginPageHandler() {
}); });
//Fire pageLoadHandler for discover (first page shown after start) //Fire pageLoadHandler for discover (first page shown after start)
setTimeout(function() {
pagebeforeshowDiscover(); pagebeforeshowDiscover();
$(this).removeData('promise'); $(this).removeData('promise');
},1);
} }
var cachedImages = {}; var cachedImages = {};