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
id="form"
method="post"
action="">
action=""
@submit.prevent="onSubmit">
<span id="nick">{{ network.nick }}</span>
<textarea
id="input"
ref="input"
v-model="channel.pendingMessage"
:placeholder="getInputPlaceholder(channel)"
:aria-label="getInputPlaceholder(channel)"
class="mousetrap"
@keyup.enter="onSubmit"
/>
<span
id="submit-tooltip"
@ -24,6 +27,9 @@
</template>
<script>
const $ = require("jquery");
const socket = require("../js/socket");
export default {
name: "ChatInput",
props: {
@ -46,6 +52,32 @@ export default {
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>

View file

@ -4,7 +4,6 @@ const $ = require("jquery");
const Mousetrap = require("mousetrap");
const wrapCursor = require("undate").wrapCursor;
const utils = require("./utils");
const form = $("#form");
const input = $("#input");
const sidebar = $("#sidebar");
const windows = $("#windows");
@ -106,8 +105,9 @@ function enableHistory() {
position = 0;
});
inputTrap.bind("enter", function() {
inputTrap.bind("enter", function(e) {
position = 0;
const input = $(e.target);
if (input.data("autocompleting")) {
return false;
@ -119,9 +119,6 @@ function enableHistory() {
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
if (history[1] !== text) {
history.splice(1, 0, text);

View file

@ -105,35 +105,6 @@ window.vueMounted = () => {
$(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() {
const name = $(this).attr("data-chan");
const chan = utils.findCurrentNetworkChan(name);