From 6af8da210690eafe01202efd78d3cb434347d066 Mon Sep 17 00:00:00 2001 From: Davide Bertola Date: Tue, 12 Jul 2016 17:26:55 +0200 Subject: [PATCH] restore scroll position after loading previous messages --- client/js/lounge.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/client/js/lounge.js b/client/js/lounge.js index 3c767ad4..6c4adee4 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -348,11 +348,19 @@ $(function() { var documentFragment = buildChannelMessages(data.chan, data.messages); var chan = chat .find("#chan-" + data.chan) - .find(".messages") - .prepend(documentFragment) - .end(); + .find(".messages"); + + // 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) { - chan.find(".show-more").removeClass("show"); + scrollable.find(".show-more").removeClass("show"); } });