Maintain bottom-most scroll position when resizing conversation area, once again.

Related with #278. Redone to include keeping scroll at the bottom when resizing the window, as suggested in #305, and to better fit the current code structure.
This commit is contained in:
adambar 2015-07-14 23:11:11 +02:00 committed by lilia
parent 56b6375f97
commit 1498d90b58
2 changed files with 22 additions and 11 deletions

View file

@ -17,6 +17,10 @@
'use strict';
window.Whisper = window.Whisper || {};
var scrollPosition,
scrollHeight,
shouldStickToBottom;
Whisper.MessageListView = Whisper.ListView.extend({
tagName: 'ul',
className: 'message-list',
@ -25,9 +29,20 @@
'add': 'scrollToBottom',
'update *': 'scrollToBottom'
},
measureScrollPosition: function() {
scrollPosition = this.$el.scrollTop() + this.$el.outerHeight();
scrollHeight = this.el.scrollHeight;
shouldStickToBottom = scrollPosition === scrollHeight;
},
scrollToBottomIfNeeded: function() {
if (shouldStickToBottom) {
this.$el.scrollTop(scrollHeight);
}
},
scrollToBottom: function() {
// TODO: Avoid scrolling if user has manually scrolled up?
this.$el.scrollTop(this.el.scrollHeight);
this.measureScrollPosition();
},
addAll: function() {
Whisper.ListView.prototype.addAll.apply(this, arguments); // super()