Browse Source

photo submit fukkup

master
jngrt 10 years ago
parent
commit
ce1b342a5e
  1. 64
      web/main.js

64
web/main.js

@ -22,6 +22,8 @@ document.addEventListener('DOMContentLoaded', function(){
// necessary in case connection is lost and messages are not yet sent // necessary in case connection is lost and messages are not yet sent
checkOutbox(); checkOutbox();
} }
document.getElementById('message-form').onsubmit = onSubmitMessage;
//update everything to initialize //update everything to initialize
updateInboxView(); updateInboxView();
@ -69,13 +71,20 @@ function showOverview(){
/* /*
* OUTBOX STUFF * OUTBOX STUFF
*/ */
document.getElementById('message-form').onsubmit = function(){ function onSubmitMessage(){
var outStr = localStorage.getItem( 'outbox' ) || ''; var msg = document.getElementById('message').value.replace(/\r?\n/g, "<br />");
var namm = document.getElementById('name').value || "anonymous"; var namm = document.getElementById('name').value || "anonymous";
var mess = document.getElementById('message').value.replace(/\r?\n/g, "<br />"); addOutboxItem( namm, msg );
};
function addOutboxItem( name, message ){
var outStr = localStorage.getItem( 'outbox' ) || '';
var newMsgs = {}; var newMsgs = {};
var ddata = new Date().getTime(); var ddata = new Date().getTime();
var alias = ownAlias;//to do: build a check to see if ownAlias == ownId, if so, alias should become 'local' var alias = ownAlias;
if ( alias === ownId ) {
alias = "local";
}
var contento = { var contento = {
"time" : ddata, "time" : ddata,
"message" : mess, "message" : mess,
@ -91,7 +100,7 @@ document.getElementById('message-form').onsubmit = function(){
showOverview(); showOverview();
return false; return false;
}; }
function checkOutbox() { function checkOutbox() {
var outStr = localStorage.getItem( 'outbox' ); var outStr = localStorage.getItem( 'outbox' );
@ -268,7 +277,7 @@ function downloadMessage(filename) {
if (xhr.readyState == 4 && xhr.status == 200){ if (xhr.readyState == 4 && xhr.status == 200){
onMessageDownload( xhr.responseText, filename ); onMessageDownload( xhr.responseText, filename );
} }
} };
xhr.open( "GET", 'msg/'+filename, true); xhr.open( "GET", 'msg/'+filename, true);
xhr.send(); xhr.send();
@ -279,7 +288,7 @@ function checkInbox() {
if (xhr.readyState == 4 && xhr.status == 200){ if (xhr.readyState == 4 && xhr.status == 200){
onIndex( xhr.responseText ); onIndex( xhr.responseText );
} }
} };
xhr.open( "GET", 'index', true); xhr.open( "GET", 'index', true);
xhr.send(); xhr.send();
} }
@ -290,7 +299,7 @@ function getOwnId() {
ownId = xhr.responseText; ownId = xhr.responseText;
ownColor = getNodeColor( ownId ); ownColor = getNodeColor( ownId );
} }
} };
xhr.open( "GET", 'id', true); xhr.open( "GET", 'id', true);
xhr.send(); xhr.send();
} }
@ -309,6 +318,7 @@ function getOwnAlias() {
/* /*
* PHOTO STUFF * PHOTO STUFF
*/ */
var imgDim = 200;
var canvas1; var canvas1;
var context1; var context1;
var canvas2; var canvas2;
@ -351,29 +361,31 @@ function submitImage(){
var canvas = document.getElementById('canvas3'); // choose canvas element to convert var canvas = document.getElementById('canvas3'); // choose canvas element to convert
var dataURL = canvas.toDataURL(); // convert cabvas to data url we can handle var dataURL = canvas.toDataURL(); // convert cabvas to data url we can handle
image.src = dataURL;
var outputImg = document.createElement("img"); // create img tag //var outputImg = document.createElement("img"); // create img tag
outputImg.src = dataURL; // assign dataurl to image tag 'src' option //outputImg.src = dataURL; // assign dataurl to image tag 'src' option
//document.body.appendChild(outputImg); // append img to body (to be assigned to place holder div) //document.body.appendChild(outputImg); // append img to body (to be assigned to place holder div)
// append data to text area...not working yet.. // append data to text area...not working yet..
var photo = document.getElementById('message'); // add data url to message field... not working yet //var photo = document.getElementById('message'); // add data url to message field... not working yet
//outputImg.src = "<img src='"+ outputImg.src; +"'/>" // construct image tag + img data... //outputImg.src = "<img src='"+ outputImg.src; +"'/>" // construct image tag + img data...
//photo += outputImg.src; //photo += outputImg.src;
photo.innerHTML += outputImg.src; //photo.innerHTML += outputImg.src;
sendMessage( new Date().getTime(), "test"); //<< breaks vereything ;) and is an bad idea: TODO: append data stringto message field, or url whatever and preview it locally (append to body) before submitting, but textarea is refreshing or something ugh...aka find clean solution, add url parameter instead of dirty innerhtml hacking //sendMessage( new Date().getTime(), dataURL );
//TEST INNNETHTML ADD TO TEXATAREA QUICKYYYYY //sendMessage( new Date().getTime(), "random "+Math.random()*1000 );
var namm = document.getElementById('photo-name').value || "anonymous";
console.log(photo.innerHTML); addOutboxItem( namm, image.outerHTML );
showOverview();
return false;
} }
function initCanvas(context){ function initCanvas(context){
// Debug filling // Debug filling
context.fillStyle ="#dbbd7a"; context.fillStyle ="#dbbd7a";
context.fill() context.fill();
context.beginPath(); context.beginPath();
context.rect(0,0, 400, 400); context.rect(0,0, imgDim, imgDim);
context.fillStyle = 'yellow'; context.fillStyle = 'yellow';
context.fill(); context.fill();
context.lineWidth = 7; context.lineWidth = 7;
@ -412,13 +424,13 @@ function onImageLoad() {
var xOffset = 0; var xOffset = 0;
var yOffset = 0; var yOffset = 0;
if ( imgObj.width > imgObj.height ) { if ( imgObj.width > imgObj.height ) {
h = 400; h = imgDim;
w = 400 * imgObj.width / imgObj.height; w = imgDim * imgObj.width / imgObj.height;
xOffset = (400 - w) / 2; xOffset = (imgDim - w) / 2;
} else { } else {
w = 400; w = imgDim;
h = 400 * imgObj.height / imgObj.width; h = imgDim * imgObj.height / imgObj.width;
yOffset = (400 - h) / 2; yOffset = (imgDim - h) / 2;
} }
context1.drawImage(imgObj, xOffset, yOffset, w, h); context1.drawImage(imgObj, xOffset, yOffset, w, h);
var imageData = context1.getImageData( 0, 0, canvas1.width, canvas1.height); var imageData = context1.getImageData( 0, 0, canvas1.width, canvas1.height);

Loading…
Cancel
Save