update livechan to allow attachments
This commit is contained in:
parent
13e0010419
commit
4a8861761d
@ -905,12 +905,17 @@ Chat.prototype.onNotifyShow = function () {
|
|||||||
Chat.prototype.readImage = function (elem, callback) {
|
Chat.prototype.readImage = function (elem, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var reader = new FileReader();
|
|
||||||
if (elem.files.length > 0 ) {
|
if (elem.files.length > 0 ) {
|
||||||
|
var reader = new FileReader();
|
||||||
var file = elem.files[0];
|
var file = elem.files[0];
|
||||||
callback(file, file.name);
|
reader.onloadend = function(ev) {
|
||||||
|
if (ev.target.readyState == FileReader.DONE) {
|
||||||
|
callback(window.btoa(ev.target.result), file.name, file.type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.readAsBinaryString(file);
|
||||||
} else {
|
} else {
|
||||||
callback(null, null);
|
callback(null, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -956,17 +961,21 @@ Chat.prototype.sendInput = function(event) {
|
|||||||
var message = inputElem.message.value;
|
var message = inputElem.message.value;
|
||||||
var name = inputElem.name.value;
|
var name = inputElem.name.value;
|
||||||
var convo = inputElem.convo.value;
|
var convo = inputElem.convo.value;
|
||||||
|
self.readImage(inputElem.file, function(fdata, fname, ftype) {
|
||||||
|
if (fdata) {
|
||||||
connection.send({Type: "post", Post: {
|
connection.send({Type: "post", Post: {
|
||||||
Message: message,
|
message: message,
|
||||||
Name: name,
|
name: name,
|
||||||
|
files: [{name: fname, data: fdata, type: ftype}],
|
||||||
}});
|
}});
|
||||||
for (var idx = 0 ; idx < inputElem.file.files.length; idx ++ ) {
|
} else {
|
||||||
console.log("send file "+ idx);
|
connection.send({Type: "post", Post: {
|
||||||
connection.send(inputElem.file.files[idx]);
|
message: message,
|
||||||
|
name: name, }});
|
||||||
}
|
}
|
||||||
inputElem.file.value = "";
|
inputElem.file.value = "";
|
||||||
//TODO: don't clear this when doing captcha
|
|
||||||
inputElem.message.value = '';
|
inputElem.message.value = '';
|
||||||
|
});
|
||||||
inputElem.submit.disabled = true;
|
inputElem.submit.disabled = true;
|
||||||
var i = parseInt(self.options.cooldown);
|
var i = parseInt(self.options.cooldown);
|
||||||
// fallback
|
// fallback
|
||||||
|
Reference in New Issue
Block a user