2018-07-08 13:42:54 +00:00
|
|
|
<template>
|
|
|
|
<form
|
|
|
|
id="form"
|
|
|
|
method="post"
|
2018-07-08 15:17:20 +00:00
|
|
|
action=""
|
|
|
|
@submit.prevent="onSubmit">
|
2018-07-08 13:42:54 +00:00
|
|
|
<span id="nick">{{ network.nick }}</span>
|
|
|
|
<textarea
|
|
|
|
id="input"
|
2018-07-08 15:17:20 +00:00
|
|
|
ref="input"
|
2018-07-08 13:42:54 +00:00
|
|
|
v-model="channel.pendingMessage"
|
|
|
|
:placeholder="getInputPlaceholder(channel)"
|
|
|
|
:aria-label="getInputPlaceholder(channel)"
|
|
|
|
class="mousetrap"
|
2018-07-08 15:17:20 +00:00
|
|
|
@keyup.enter="onSubmit"
|
2018-07-08 13:42:54 +00:00
|
|
|
/>
|
|
|
|
<span
|
|
|
|
id="submit-tooltip"
|
|
|
|
class="tooltipped tooltipped-w tooltipped-no-touch"
|
|
|
|
aria-label="Send message">
|
|
|
|
<button
|
|
|
|
id="submit"
|
|
|
|
type="submit"
|
|
|
|
aria-label="Send message"/>
|
|
|
|
</span>
|
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2018-07-08 15:17:20 +00:00
|
|
|
const $ = require("jquery");
|
|
|
|
const socket = require("../js/socket");
|
|
|
|
|
2018-07-08 13:42:54 +00:00
|
|
|
export default {
|
|
|
|
name: "ChatInput",
|
|
|
|
props: {
|
|
|
|
network: Object,
|
|
|
|
channel: Object,
|
|
|
|
},
|
2018-07-08 14:57:02 +00:00
|
|
|
mounted() {
|
|
|
|
if (this.$root.settings.autocomplete) {
|
|
|
|
require("../js/autocompletion").enable();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
destroyed() {
|
|
|
|
require("../js/autocompletion").disable();
|
|
|
|
},
|
2018-07-08 13:42:54 +00:00
|
|
|
methods: {
|
|
|
|
getInputPlaceholder(channel) {
|
|
|
|
if (channel.type === "channel" || channel.type === "query") {
|
|
|
|
return `Write to ${channel.name}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
},
|
2018-07-08 15:17:20 +00:00
|
|
|
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});
|
|
|
|
},
|
2018-07-08 13:42:54 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|