Carbon/src/js/chat-input.js

39 lines
885 B
JavaScript
Raw Normal View History

2020-10-23 14:15:14 +00:00
const {q} = require("./basic.js")
const {store} = require("./store/store.js")
const lsm = require("./lsm.js")
const {chat} = require("./chat.js")
2020-10-15 13:24:15 +00:00
const input = q("#c-chat-textarea")
2020-10-19 07:23:28 +00:00
store.activeRoom.subscribe("changeSelf", () => {
if (store.activeRoom.exists()) {
input.focus()
}
})
input.addEventListener("keydown", event => {
if (event.key === "Enter" && !event.shiftKey && !event.ctrlKey) {
event.preventDefault()
const body = input.value
send(input.value)
input.value = ""
fixHeight()
}
})
input.addEventListener("input", () => {
fixHeight()
})
2020-10-15 13:24:15 +00:00
function fixHeight() {
input.style.height = "0px"
// console.log(input.clientHeight, input.scrollHeight)
input.style.height = (input.scrollHeight + 1) + "px"
2020-10-15 13:24:15 +00:00
}
function send(body) {
if (!store.activeRoom.exists()) return
2020-10-22 10:02:50 +00:00
if (!body.trim().length) return
return store.activeRoom.value().timeline.send(body)
2020-10-15 13:24:15 +00:00
}