Fix sending messages

This commit is contained in:
Pavel Djundik 2018-07-08 18:17:20 +03:00 committed by Pavel Djundik
parent 09fa3e5c86
commit ebb63f2742
3 changed files with 35 additions and 35 deletions

View File

@ -2,14 +2,17 @@
<form <form
id="form" id="form"
method="post" method="post"
action=""> action=""
@submit.prevent="onSubmit">
<span id="nick">{{ network.nick }}</span> <span id="nick">{{ network.nick }}</span>
<textarea <textarea
id="input" id="input"
ref="input"
v-model="channel.pendingMessage" v-model="channel.pendingMessage"
:placeholder="getInputPlaceholder(channel)" :placeholder="getInputPlaceholder(channel)"
:aria-label="getInputPlaceholder(channel)" :aria-label="getInputPlaceholder(channel)"
class="mousetrap" class="mousetrap"
@keyup.enter="onSubmit"
/> />
<span <span
id="submit-tooltip" id="submit-tooltip"
@ -24,6 +27,9 @@
</template> </template>
<script> <script>
const $ = require("jquery");
const socket = require("../js/socket");
export default { export default {
name: "ChatInput", name: "ChatInput",
props: { props: {
@ -46,6 +52,32 @@ export default {
return ""; return "";
}, },
onSubmit() {
// Triggering click event opens the virtual keyboard on mobile
// This can only be called from another interactive event (e.g. button click)
$(this.$refs.input).trigger("click").trigger("focus");
const target = this.channel.id;
const text = input.value;
if (text.length === 0) {
return false;
}
input.value = "";
// resetInputHeight(input.get(0));
if (text.charAt(0) === "/") {
const args = text.substr(1).split(" ");
const cmd = args.shift().toLowerCase();
if (typeof utils.inputCommands[cmd] === "function" && utils.inputCommands[cmd](args)) {
return false;
}
}
socket.emit("input", {target, text});
},
}, },
}; };
</script> </script>

View File

@ -4,7 +4,6 @@ const $ = require("jquery");
const Mousetrap = require("mousetrap"); const Mousetrap = require("mousetrap");
const wrapCursor = require("undate").wrapCursor; const wrapCursor = require("undate").wrapCursor;
const utils = require("./utils"); const utils = require("./utils");
const form = $("#form");
const input = $("#input"); const input = $("#input");
const sidebar = $("#sidebar"); const sidebar = $("#sidebar");
const windows = $("#windows"); const windows = $("#windows");
@ -106,8 +105,9 @@ function enableHistory() {
position = 0; position = 0;
}); });
inputTrap.bind("enter", function() { inputTrap.bind("enter", function(e) {
position = 0; position = 0;
const input = $(e.target);
if (input.data("autocompleting")) { if (input.data("autocompleting")) {
return false; return false;
@ -119,9 +119,6 @@ function enableHistory() {
return false; return false;
} }
// Submit the form when pressing enter instead of inserting a new line
form.trigger("submit");
// Store new message in history if last message isn't already equal // Store new message in history if last message isn't already equal
if (history[1] !== text) { if (history[1] !== text) {
history.splice(1, 0, text); history.splice(1, 0, text);

View File

@ -105,35 +105,6 @@ window.vueMounted = () => {
$(document.body).addClass("is-apple"); $(document.body).addClass("is-apple");
} }
$("#form").on("submit", function() {
// Triggering click event opens the virtual keyboard on mobile
// This can only be called from another interactive event (e.g. button click)
input.trigger("click").trigger("focus");
const target = chat.data("id");
const text = input.val();
if (text.length === 0) {
return false;
}
input.val("");
resetInputHeight(input.get(0));
if (text.charAt(0) === "/") {
const args = text.substr(1).split(" ");
const cmd = args.shift().toLowerCase();
if (typeof utils.inputCommands[cmd] === "function" && utils.inputCommands[cmd](args)) {
return false;
}
}
socket.emit("input", {target, text});
return false;
});
chat.on("click", ".inline-channel", function() { chat.on("click", ".inline-channel", function() {
const name = $(this).attr("data-chan"); const name = $(this).attr("data-chan");
const chan = utils.findCurrentNetworkChan(name); const chan = utils.findCurrentNetworkChan(name);