new chat messages don't force chat window to bottom if it was scrolled up

This commit is contained in:
iou1name 2018-07-22 02:58:54 -04:00
parent f7627d5090
commit c59f2dde99
3 changed files with 9 additions and 3 deletions

View File

@ -18,7 +18,9 @@ var tid = setInterval( function () {
let mbox = document.getElementById('chatWindow'); let mbox = document.getElementById('chatWindow');
mbox.innerHTML = mbox.innerHTML + msg_str; mbox.innerHTML = mbox.innerHTML + msg_str;
if ((mbox.scrollTop + mbox.offsetHeight) >= (mbox.scrollHeight - mbox.clientHeight / 2)) {
mbox.scrollTop = mbox.scrollHeight; mbox.scrollTop = mbox.scrollHeight;
}
}); });
socket.on('new_post', function(data) { socket.on('new_post', function(data) {
deactivate_post(); deactivate_post();
@ -143,6 +145,7 @@ var tid = setInterval( function () {
let text = mtarea.value.trim(); let text = mtarea.value.trim();
mtarea.value = ''; mtarea.value = '';
if (text == '') { return; } if (text == '') { return; }
document.getElementById('chatWindow').scrollTop = document.getElementById('chatWindow').scrollHeight;
socket.emit('message', {message: text, name: 'Anonymous', room: room_id}); socket.emit('message', {message: text, name: 'Anonymous', room: room_id});
} }
}); });

View File

@ -18,7 +18,9 @@ var tid = setInterval( function () {
let mbox = document.getElementById('chatWindow'); let mbox = document.getElementById('chatWindow');
mbox.innerHTML = mbox.innerHTML + msg_str; mbox.innerHTML = mbox.innerHTML + msg_str;
if ((mbox.scrollTop + mbox.offsetHeight) >= (mbox.scrollHeight - mbox.clientHeight / 2)) {
mbox.scrollTop = mbox.scrollHeight; mbox.scrollTop = mbox.scrollHeight;
}
}); });
socket.on('new_post', function(data) { socket.on('new_post', function(data) {
deactivate_post(); deactivate_post();
@ -129,6 +131,7 @@ var tid = setInterval( function () {
let text = mtarea.value.trim(); let text = mtarea.value.trim();
mtarea.value = ''; mtarea.value = '';
if (text == '') { return; } if (text == '') { return; }
document.getElementById('chatWindow').scrollTop = document.getElementById('chatWindow').scrollHeight;
socket.emit('message', {message: text, name: 'Anonymous', room: room_id}); socket.emit('message', {message: text, name: 'Anonymous', room: room_id});
} }
}); });

2
todo
View File

@ -12,13 +12,13 @@ Enable namefagging
Account managament/logout Account managament/logout
Display profile link in header bar Display profile link in header bar
Tagging system Tagging system
Quote backlinks
Improvements: Improvements:
Revamp post editing Revamp post editing
More options for text posts (lists and so on) More options for text posts (lists and so on)
More rigorous input checking in events.py More rigorous input checking in events.py
New post displays chat message New post displays chat message
New chat message doesn't take chat window to the bottom if it was scrolled up
Record email on signup Record email on signup
Change urls Change urls
Poll vote highlights entire option Poll vote highlights entire option