Carbon/build/static/chat-input.js

38 lines
941 B
JavaScript
Raw Normal View History

import {q} from "../static/basic.js?static=4212436742"
import {store} from "../static/store/store.js?static=ce3066287b"
import * as lsm from "../static/lsm.js?static=aed2c7ca35"
import {chat} from "../static/chat.js?static=b01b3716ff"
2020-10-15 13:24:15 +00:00
2020-10-19 07:23:28 +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()
2020-10-19 07:23:28 +00:00
const body = input.value
send(input.value)
input.value = ""
2020-10-15 13:24:15 +00:00
fixHeight()
}
})
2020-10-19 07:23:28 +00:00
input.addEventListener("input", () => {
2020-10-15 13:24:15 +00:00
fixHeight()
})
function fixHeight() {
2020-10-19 07:23:28 +00:00
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
return store.activeRoom.value().timeline.send(body)
2020-10-15 13:24:15 +00:00
}