mirror of
https://github.com/thelounge/thelounge
synced 2024-11-10 22:54:15 +00:00
Merge pull request #496 from davibe/restore-scroll
restore scroll position after loading previous messages
This commit is contained in:
commit
a7fe19deca
1 changed files with 12 additions and 4 deletions
|
@ -353,11 +353,19 @@ $(function() {
|
||||||
var documentFragment = buildChannelMessages(data.chan, data.messages);
|
var documentFragment = buildChannelMessages(data.chan, data.messages);
|
||||||
var chan = chat
|
var chan = chat
|
||||||
.find("#chan-" + data.chan)
|
.find("#chan-" + data.chan)
|
||||||
.find(".messages")
|
.find(".messages");
|
||||||
.prepend(documentFragment)
|
|
||||||
.end();
|
// get the scrollable wrapper around messages
|
||||||
|
var scrollable = chan.closest(".chat");
|
||||||
|
var heightOld = chan.height();
|
||||||
|
chan.prepend(documentFragment).end();
|
||||||
|
|
||||||
|
// restore scroll position
|
||||||
|
var position = chan.height() - heightOld;
|
||||||
|
scrollable.scrollTop(position);
|
||||||
|
|
||||||
if (data.messages.length !== 100) {
|
if (data.messages.length !== 100) {
|
||||||
chan.find(".show-more").removeClass("show");
|
scrollable.find(".show-more").removeClass("show");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue