mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: closes #11731, set postIndex on pagination
This commit is contained in:
@@ -303,11 +303,11 @@ ajaxify.widgets = { render: render };
|
|||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
// if on topic page, scroll to the correct post,
|
// if on topic page, scroll to the correct post,
|
||||||
// this is here to avoid a flash of the wrong posts at the top of the page
|
// this is here to avoid a flash of the wrong posts at the top of the page
|
||||||
if (ajaxify.data.template.topic && ajaxify.data.postIndex > 1) {
|
require(['navigator'], function (navigator) {
|
||||||
require(['navigator'], function (navigator) {
|
if (navigator.shouldScrollToPost(ajaxify.data.postIndex)) {
|
||||||
navigator.scrollToPostIndex(ajaxify.data.postIndex - 1, true, 0);
|
navigator.scrollToPostIndex(ajaxify.data.postIndex - 1, true, 0);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
ajaxify.loadScript(tpl_url, function done() {
|
ajaxify.loadScript(tpl_url, function done() {
|
||||||
hooks.fire('action:ajaxify.end', { url: url, tpl_url: tpl_url, title: ajaxify.data.title });
|
hooks.fire('action:ajaxify.end', { url: url, tpl_url: tpl_url, title: ajaxify.data.title });
|
||||||
|
|||||||
@@ -151,10 +151,8 @@ define('forum/topic', [
|
|||||||
const bookmark = ajaxify.data.bookmark || storage.getItem('topic:' + tid + ':bookmark');
|
const bookmark = ajaxify.data.bookmark || storage.getItem('topic:' + tid + ':bookmark');
|
||||||
const postIndex = ajaxify.data.postIndex;
|
const postIndex = ajaxify.data.postIndex;
|
||||||
updateUserBookmark(postIndex);
|
updateUserBookmark(postIndex);
|
||||||
if (postIndex > 1) {
|
if (navigator.shouldScrollToPost(postIndex)) {
|
||||||
if (components.get('post/anchor', postIndex - 1).length) {
|
return navigator.scrollToPostIndex(postIndex - 1, true, 0);
|
||||||
return navigator.scrollToPostIndex(postIndex - 1, true, 0);
|
|
||||||
}
|
|
||||||
} else if (bookmark && (
|
} else if (bookmark && (
|
||||||
!config.usePagination ||
|
!config.usePagination ||
|
||||||
(config.usePagination && ajaxify.data.pagination.currentPage === 1)
|
(config.usePagination && ajaxify.data.pagination.currentPage === 1)
|
||||||
|
|||||||
@@ -642,6 +642,14 @@ define('navigator', [
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
navigator.shouldScrollToPost = function (postIndex) {
|
||||||
|
if (!ajaxify.data.template.topic || postIndex <= 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const firstPostEl = $('[component="topic"] [component="post"]').first();
|
||||||
|
return parseInt(firstPostEl.attr('data-index'), 10) !== postIndex - 1;
|
||||||
|
};
|
||||||
|
|
||||||
navigator.scrollToPostIndex = function (postIndex, highlight, duration) {
|
navigator.scrollToPostIndex = function (postIndex, highlight, duration) {
|
||||||
const scrollTo = components.get('post', 'index', postIndex);
|
const scrollTo = components.get('post', 'index', postIndex);
|
||||||
navigator.scrollToElement(scrollTo, highlight, duration, postIndex);
|
navigator.scrollToElement(scrollTo, highlight, duration, postIndex);
|
||||||
|
|||||||
@@ -72,8 +72,12 @@ topicsController.get = async function getTopic(req, res, next) {
|
|||||||
const sort = req.query.sort || settings.topicPostSort;
|
const sort = req.query.sort || settings.topicPostSort;
|
||||||
const set = sort === 'most_votes' ? `tid:${tid}:posts:votes` : `tid:${tid}:posts`;
|
const set = sort === 'most_votes' ? `tid:${tid}:posts:votes` : `tid:${tid}:posts`;
|
||||||
const reverse = sort === 'newest_to_oldest' || sort === 'most_votes';
|
const reverse = sort === 'newest_to_oldest' || sort === 'most_votes';
|
||||||
if (settings.usePagination && !req.query.page) {
|
if (settings.usePagination) {
|
||||||
currentPage = calculatePageFromIndex(postIndex, settings);
|
if (!req.query.page) {
|
||||||
|
currentPage = calculatePageFromIndex(postIndex, settings);
|
||||||
|
} else {
|
||||||
|
postIndex = ((currentPage - 1) * settings.postsPerPage) + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const { start, stop } = calculateStartStop(currentPage, postIndex, settings);
|
const { start, stop } = calculateStartStop(currentPage, postIndex, settings);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user