-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscroll.js
More file actions
25 lines (22 loc) · 994 Bytes
/
scroll.js
File metadata and controls
25 lines (22 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
eventManager.on('ChatDetected', function override() {
// eslint-disable-next-line consistent-return
globalSet('scroll', function scroll(room, force = false) {
if (!force) return this.super(room);
debug('Forcing scroll');
const container = $(`#${room} .chat-messages`);
container.scrollTop(container.prop('scrollHeight'));
});
function scrollToBottom(room) {
global('scroll')(room, true);
}
// Force scrolling to bottom after loading history -- do last
eventManager.on(':ready', eventManager.on('Chat:getHistory', ({ room }) => scrollToBottom(room)));
// See if we should scroll this message
let force = false;
eventManager.on('preChat:getMessage', function preProcess({ room }) {
if (this.canceled) return;
const container = $(`#${room} .chat-messages`);
force = container.scrollTop() + 100 > container.prop('scrollHeight') - container.height();
});
eventManager.on('Chat:getMessage', ({ room }) => force && scrollToBottom(room));
});