diff options
author | WlodekM <[email protected]> | 2024-11-30 19:31:29 +0200 |
---|---|---|
committer | WlodekM <[email protected]> | 2024-11-30 19:31:29 +0200 |
commit | b12f275f16b98c6255bff7f1eaf0887b76444027 (patch) | |
tree | c3dc3fde7610a78e9b397c4349f657b1ae159100 /pages | |
parent | 216069f702de324eaf1c96c9f625032d4c69f3a3 (diff) |
add unload handler
Diffstat (limited to 'pages')
-rw-r--r-- | pages/main/page.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/pages/main/page.js b/pages/main/page.js index 96726a9..81f498c 100644 --- a/pages/main/page.js +++ b/pages/main/page.js @@ -10,6 +10,13 @@ function scrollToBottomOfElement(element) { element.scrollTo(0, element.scrollHeight); } +function handleNewPost() { + console.debug('posting of the poster', post) + let scrolledToBottom = msgArea.parentElement.scrollTopMax == msgArea.parentElement.scrollTop; + createMessage(post.data) + if(scrolledToBottom) scrollToBottomOfElement(msgArea.parentElement); +} + export function onload() { const msgArea = document.getElementById("messages"); @@ -83,12 +90,7 @@ export function onload() { } scrollToBottomOfElement(msgArea.parentElement); - stores.sdlib.wsEvents.on("new_post", post => { - console.debug('posting of the poster', post) - let scrolledToBottom = msgArea.parentElement.scrollTopMax == msgArea.parentElement.scrollTop; - createMessage(post.data) - if(scrolledToBottom) scrollToBottomOfElement(msgArea.parentElement); - }) + stores.sdlib.wsEvents.on("new_post", handleNewPost) const submitBtn = document.getElementById("send") @@ -113,4 +115,8 @@ export function onload() { if (!submitBtn.disabled) submitBtn.click(); } }) +} + +export function onunload() { + stores.sdlib.wsEvents.off('new_post', handleNewPost) } \ No newline at end of file |