ChatServer/pages/js/message.js

31 lines
978 B
JavaScript
Raw Normal View History

var respfunc = function respfunc(result) {
if (result != "Success") { //on success result is string
2016-07-28 13:04:24 +00:00
var errormsg = document.getElementById("errormsg");
errormsg.innerHTML = result.responseText;
errormsg.style = "display: block";
}
else
location.reload(true);
};
2016-07-28 13:04:24 +00:00
var sendmsgonenter = function sendmsgonenter(e) { //TODO: Detect Enter
2016-07-28 13:04:24 +00:00
var code = e.keyCode || e.which;
2016-08-01 10:16:54 +00:00
if (code != 13 || e.shiftKey) { //Enter keycode
2016-07-28 13:04:24 +00:00
return;
}
2016-08-01 10:16:54 +00:00
e.preventDefault();
2016-07-28 13:04:24 +00:00
var textarea = event.target;
2016-08-01 10:16:54 +00:00
if (textarea.value.trim().length == 0)
return;
textarea.disabled = true;
window.convid = 1;
2016-07-28 13:04:24 +00:00
var json = JSON.stringify({"message": textarea.value, "conversation": window.convid});
$.ajax({
url: "/message", data: json, method: "POST", success: respfunc, error: respfunc
});
};
$(document).ready(function () {
2016-08-01 10:16:54 +00:00
$('#msginput').on("keydown", sendmsgonenter);
2016-07-28 13:04:24 +00:00
});