mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 00:15:46 +01:00
prevent infinite loop on topic scroll to bottom
This commit is contained in:
@@ -121,7 +121,9 @@ define('forum/topic', [
|
|||||||
var postIndex = getPostIndex();
|
var postIndex = getPostIndex();
|
||||||
|
|
||||||
if (postIndex && window.location.search.indexOf('page=') === -1) {
|
if (postIndex && window.location.search.indexOf('page=') === -1) {
|
||||||
navigator.scrollToPost(postIndex - 1, true);
|
if (components.get('post/anchor', postIndex).length) {
|
||||||
|
return navigator.scrollToPostIndex(postIndex - 1, true);
|
||||||
|
}
|
||||||
} else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1)) && ajaxify.data.postcount > 1) {
|
} else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1)) && ajaxify.data.postcount > 1) {
|
||||||
app.alert({
|
app.alert({
|
||||||
alert_id: 'bookmark',
|
alert_id: 'bookmark',
|
||||||
@@ -140,12 +142,20 @@ define('forum/topic', [
|
|||||||
|
|
||||||
function getPostIndex() {
|
function getPostIndex() {
|
||||||
var parts = window.location.pathname.split('/');
|
var parts = window.location.pathname.split('/');
|
||||||
if (parts[parts.length - 1] && utils.isNumber(parts[parts.length - 1])) {
|
var lastPart = parts[parts.length - 1];
|
||||||
return parseInt(parts[parts.length - 1], 10);
|
if (lastPart && utils.isNumber(lastPart)) {
|
||||||
}
|
lastPart = parseInt(lastPart, 10);
|
||||||
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (lastPart > 0 && !components.get('post/anchor', lastPart).length) {
|
||||||
|
lastPart --;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastPart;
|
||||||
|
}
|
||||||
|
|
||||||
function addBlockQuoteHandler() {
|
function addBlockQuoteHandler() {
|
||||||
components.get('topic').on('click', 'blockquote .toggle', function() {
|
components.get('topic').on('click', 'blockquote .toggle', function() {
|
||||||
var blockQuote = $(this).parent('blockquote');
|
var blockQuote = $(this).parent('blockquote');
|
||||||
|
|||||||
@@ -175,18 +175,18 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
|
|||||||
navigator.scrollActive = true;
|
navigator.scrollActive = true;
|
||||||
|
|
||||||
if (components.get('post/anchor', postIndex).length) {
|
if (components.get('post/anchor', postIndex).length) {
|
||||||
return scrollToPid(postIndex, highlight, duration, offset);
|
return navigator.scrollToPostIndex(postIndex, highlight, duration, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.usePagination) {
|
if (config.usePagination) {
|
||||||
var page = Math.max(1, Math.ceil(postIndex / config.postsPerPage));
|
var page = Math.max(1, Math.ceil(postIndex / config.postsPerPage));
|
||||||
|
|
||||||
if(parseInt(page, 10) !== pagination.currentPage) {
|
if (parseInt(page, 10) !== pagination.currentPage) {
|
||||||
pagination.loadPage(page, function() {
|
pagination.loadPage(page, function() {
|
||||||
scrollToPid(postIndex, highlight, duration, offset);
|
navigator.scrollToPostIndex(postIndex, highlight, duration, offset);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
scrollToPid(postIndex, highlight, duration, offset);
|
navigator.scrollToPostIndex(postIndex, highlight, duration, offset);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
navigator.scrollActive = false;
|
navigator.scrollActive = false;
|
||||||
@@ -195,14 +195,16 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function scrollToPid(postIndex, highlight, duration, offset) {
|
navigator.scrollToPostIndex = function(postIndex, highlight, duration, offset) {
|
||||||
var scrollTo = components.get('post/anchor', postIndex);
|
var scrollTo = components.get('post/anchor', postIndex);
|
||||||
|
|
||||||
if (!scrollTo.length) {
|
if (!scrollTo.length) {
|
||||||
navigator.scrollActive = false;
|
navigator.scrollActive = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
offset = offset || 0;
|
||||||
|
duration = duration !== undefined ? duration : 400;
|
||||||
|
navigator.scrollActive = true;
|
||||||
var done = false;
|
var done = false;
|
||||||
function animateScroll() {
|
function animateScroll() {
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
@@ -232,8 +234,10 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
|
|||||||
|
|
||||||
if (components.get('topic').length) {
|
if (components.get('topic').length) {
|
||||||
animateScroll();
|
animateScroll();
|
||||||
|
} else {
|
||||||
|
navigator.scrollActive = false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
return navigator;
|
return navigator;
|
||||||
|
|||||||
Reference in New Issue
Block a user