1
0
mirror of https://github.com/flarum/core.git synced 2025-05-10 17:35:25 +02:00

Scroll to the bottom of the last post when jumping to last

This commit is contained in:
Toby Zerner 2015-06-01 11:09:39 +09:30
parent 47560dbc86
commit be249cbcb5

View File

@ -51,7 +51,7 @@ class PostStream extends mixin(Component, evented) {
return promise.then(() => { return promise.then(() => {
anchorScroll(this.$('.item:'+(backwards ? 'last' : 'first')), () => m.redraw(true)); anchorScroll(this.$('.item:'+(backwards ? 'last' : 'first')), () => m.redraw(true));
this.scrollToIndex(index, noAnimation).done(this.unpause.bind(this)); this.scrollToIndex(index, noAnimation, backwards).done(this.unpause.bind(this));
}); });
} }
@ -66,7 +66,7 @@ class PostStream extends mixin(Component, evented) {
Load and scroll down to the last post in the discussion. Load and scroll down to the last post in the discussion.
*/ */
goToLast() { goToLast() {
return this.goToIndex(this.count() - 1); return this.goToIndex(this.count() - 1, true);
} }
/** /**
@ -419,16 +419,16 @@ class PostStream extends mixin(Component, evented) {
/** /**
Scroll down to a certain post by index. Scroll down to a certain post by index.
*/ */
scrollToIndex(index, noAnimation) { scrollToIndex(index, noAnimation, bottom) {
var $item = this.$('.item[data-index='+index+']'); var $item = this.$('.item[data-index='+index+']');
return this.scrollToItem($item, noAnimation, true); return this.scrollToItem($item, noAnimation, true, true);
} }
/** /**
Scroll down to the given post. Scroll down to the given post.
*/ */
scrollToItem($item, noAnimation, force) { scrollToItem($item, noAnimation, force, bottom) {
var $container = $('html, body').stop(true); var $container = $('html, body').stop(true);
if ($item.length) { if ($item.length) {
@ -439,7 +439,7 @@ class PostStream extends mixin(Component, evented) {
// If the item is already in the viewport, we may not need to scroll. // If the item is already in the viewport, we may not need to scroll.
if (force || itemTop < scrollTop || itemBottom > scrollBottom) { if (force || itemTop < scrollTop || itemBottom > scrollBottom) {
var scrollTop = $item.is(':first-child') ? 0 : itemTop; var scrollTop = bottom ? itemBottom : ($item.is(':first-child') ? 0 : itemTop);
if (noAnimation) { if (noAnimation) {
$container.scrollTop(scrollTop); $container.scrollTop(scrollTop);