Carbon/src/js/chat-input.js
Jonathan de Jong 51905ab3f2
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
add browserify
2020-10-23 16:15:14 +02:00

38 lines
885 B
JavaScript

const {q} = require("./basic.js")
const {store} = require("./store/store.js")
const lsm = require("./lsm.js")
const {chat} = require("./chat.js")
const input = q("#c-chat-textarea")
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()
})
function fixHeight() {
input.style.height = "0px"
// console.log(input.clientHeight, input.scrollHeight)
input.style.height = (input.scrollHeight + 1) + "px"
}
function send(body) {
if (!store.activeRoom.exists()) return
if (!body.trim().length) return
return store.activeRoom.value().timeline.send(body)
}