mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: position when scrolling up
if sorting is newest to oldest scrollTop wont be changed if you are at the top of the page
This commit is contained in:
@@ -92,7 +92,7 @@ define('forum/topic/posts', [
|
|||||||
(ajaxify.data.pagination.currentPage === 1 && direction === -1);
|
(ajaxify.data.pagination.currentPage === 1 && direction === -1);
|
||||||
|
|
||||||
if (isPostVisible) {
|
if (isPostVisible) {
|
||||||
createNewPosts(data, components.get('post').not('[data-index=0]'), direction, scrollToPost);
|
createNewPosts(data, components.get('post').not('[data-index=0]'), direction, false, scrollToPost);
|
||||||
} else if (ajaxify.data.scrollToMyPost && parseInt(posts[0].uid, 10) === parseInt(app.user.uid, 10)) {
|
} else if (ajaxify.data.scrollToMyPost && parseInt(posts[0].uid, 10) === parseInt(app.user.uid, 10)) {
|
||||||
// https://github.com/NodeBB/NodeBB/issues/5004#issuecomment-247157441
|
// https://github.com/NodeBB/NodeBB/issues/5004#issuecomment-247157441
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
@@ -112,7 +112,7 @@ define('forum/topic/posts', [
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onNewPostInfiniteScroll(data) {
|
function onNewPostInfiniteScroll(data) {
|
||||||
var direction = config.topicPostSort === 'oldest_to_newest' || config.topicPostSort === 'most_votes' ? 1 : -1;
|
var direction = (config.topicPostSort === 'oldest_to_newest' || config.topicPostSort === 'most_votes') ? 1 : -1;
|
||||||
|
|
||||||
var isPreviousPostAdded = $('[component="post"][data-index="' + (data.posts[0].index - 1) + '"]').length;
|
var isPreviousPostAdded = $('[component="post"][data-index="' + (data.posts[0].index - 1) + '"]').length;
|
||||||
if (!isPreviousPostAdded && (!data.posts[0].selfPost || !ajaxify.data.scrollToMyPost)) {
|
if (!isPreviousPostAdded && (!data.posts[0].selfPost || !ajaxify.data.scrollToMyPost)) {
|
||||||
@@ -123,7 +123,7 @@ define('forum/topic/posts', [
|
|||||||
return ajaxify.go('post/' + data.posts[0].pid);
|
return ajaxify.go('post/' + data.posts[0].pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
createNewPosts(data, components.get('post').not('[data-index=0]'), direction, function (html) {
|
createNewPosts(data, components.get('post').not('[data-index=0]'), direction, false, function (html) {
|
||||||
if (html) {
|
if (html) {
|
||||||
html.addClass('new');
|
html.addClass('new');
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ define('forum/topic/posts', [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createNewPosts(data, repliesSelector, direction, callback) {
|
function createNewPosts(data, repliesSelector, direction, userScrolled, callback) {
|
||||||
callback = callback || function () {};
|
callback = callback || function () {};
|
||||||
if (!data || (data.posts && !data.posts.length)) {
|
if (!data || (data.posts && !data.posts.length)) {
|
||||||
return callback();
|
return callback();
|
||||||
@@ -210,7 +210,7 @@ define('forum/topic/posts', [
|
|||||||
html.insertBefore(before);
|
html.insertBefore(before);
|
||||||
|
|
||||||
// Now restore the relative position the user was on prior to new post insertion
|
// Now restore the relative position the user was on prior to new post insertion
|
||||||
if (scrollTop > 0) {
|
if (userScrolled || scrollTop > 0) {
|
||||||
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
$(window).scrollTop(scrollTop + ($(document).height() - height));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -256,7 +256,7 @@ define('forum/topic/posts', [
|
|||||||
indicatorEl.fadeOut();
|
indicatorEl.fadeOut();
|
||||||
|
|
||||||
if (data && data.posts && data.posts.length) {
|
if (data && data.posts && data.posts.length) {
|
||||||
createNewPosts(data, replies, direction, done);
|
createNewPosts(data, replies, direction, true, done);
|
||||||
} else {
|
} else {
|
||||||
navigator.update();
|
navigator.update();
|
||||||
done();
|
done();
|
||||||
@@ -310,10 +310,8 @@ define('forum/topic/posts', [
|
|||||||
html = html.get(0);
|
html = html.get(0);
|
||||||
|
|
||||||
if (postEl) {
|
if (postEl) {
|
||||||
console.log('insert before', ajaxify.data.posts[beforeIdx].pid);
|
|
||||||
document.querySelector('[component="topic"]').insertBefore(html, postEl);
|
document.querySelector('[component="topic"]').insertBefore(html, postEl);
|
||||||
} else {
|
} else {
|
||||||
console.log('append to bttom?');
|
|
||||||
document.querySelector('[component="topic"]').append(html);
|
document.querySelector('[component="topic"]').append(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user