|
|
@ -161,14 +161,56 @@ function clearmessage() { |
|
|
|
|
|
|
|
|
|
|
|
function attachments(files, id) { |
|
|
|
function attachments(files, id) { |
|
|
|
if (files) files.forEach(function(file) { |
|
|
|
if (files) files.forEach(function(file) { |
|
|
|
if (file.content.length<1000000) { |
|
|
|
if (file.content.length<100000) { |
|
|
|
var img = document.createElement('img'); |
|
|
|
var img = document.createElement('img'); |
|
|
|
img.src = 'data:'+file.type+';base64,' + file.content; |
|
|
|
img.src = file.content; |
|
|
|
$(id).append(img); |
|
|
|
$(id).append(img); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function fileupload(evt) { |
|
|
|
|
|
|
|
if (!window.FileReader) return error("your browser dows not support file upload", true); |
|
|
|
|
|
|
|
for (var i=0, f; f=evt.target.files[i]; ++i) { |
|
|
|
|
|
|
|
var file = f; |
|
|
|
|
|
|
|
var reader = new FileReader(); |
|
|
|
|
|
|
|
reader.onload = function(evt) { |
|
|
|
|
|
|
|
if (evt.target.error) return error("error reading file", true); |
|
|
|
|
|
|
|
if (evt.target.readyState==0) return notice("waiting for data ..."); |
|
|
|
|
|
|
|
if (evt.target.readyState==1) return notice("loading data ..."); |
|
|
|
|
|
|
|
if (!file.type.match('^image/')) return error(file.name+": not an image", true); |
|
|
|
|
|
|
|
var img = document.createElement("img"); |
|
|
|
|
|
|
|
img.onload = function() { |
|
|
|
|
|
|
|
var MAX = 400; |
|
|
|
|
|
|
|
var width = img.width; |
|
|
|
|
|
|
|
var height = img.height; |
|
|
|
|
|
|
|
if (width > MAX) { |
|
|
|
|
|
|
|
height *= MAX / width; |
|
|
|
|
|
|
|
width = MAX; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (height > MAX) { |
|
|
|
|
|
|
|
width *= MAX / height; |
|
|
|
|
|
|
|
height = MAX; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var canvas = document.createElement("canvas"); |
|
|
|
|
|
|
|
canvas.width = width; |
|
|
|
|
|
|
|
canvas.height = height; |
|
|
|
|
|
|
|
var ctx = canvas.getContext("2d"); |
|
|
|
|
|
|
|
ctx.drawImage(img, 0, 0, width, height); |
|
|
|
|
|
|
|
img.onload = function() { |
|
|
|
|
|
|
|
filecontent.push({type: file.type, content: img.src}); |
|
|
|
|
|
|
|
$("#preview").append(img); |
|
|
|
|
|
|
|
success('image of type '+file.type+' is ready to be sent'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
img.src = canvas.toDataURL(file.type); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
img.src=evt.target.result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
reader.readAsDataURL(file); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
function fileupload(evt) { |
|
|
|
function fileupload(evt) { |
|
|
|
if (!window.FileReader) |
|
|
|
if (!window.FileReader) |
|
|
|
return error("your browser dows not support file upload", true); |
|
|
|
return error("your browser dows not support file upload", true); |
|
|
@ -193,6 +235,7 @@ function fileupload(evt) { |
|
|
|
reader.readAsBinaryString(file); |
|
|
|
reader.readAsBinaryString(file); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
function setreceiver(name) { |
|
|
|
function setreceiver(name) { |
|
|
|
$("#recv").val(name); |
|
|
|
$("#recv").val(name); |
|
|
|