Skip to content

Node.js based forum software built for the modern web

closes #3767 closes #3774

barisusakli20c841128722
diff --git a/public/src/client/category.js b/public/src/client/category.js
index d213663aa8..34ecb73fec 100644
--- a/public/src/client/category.js
+++ b/public/src/client/category.js
@@ -104,7 +104,9 @@ define('forum/category', [
var bookmarkIndex = localStorage.getItem('category:' + cid + ':bookmark');
var clickedIndex = localStorage.getItem('category:' + cid + ':bookmark:clicked');
- if (!bookmarkIndex) {
+ bookmarkIndex = Math.max(0, parseInt(bookmarkIndex, 10) || 0);
+ clickedIndex = Math.max(0, parseInt(clickedIndex, 10) || 0);
+ if (!parseInt(bookmarkIndex, 10)) {
return;
}
@@ -123,13 +125,9 @@ define('forum/category', [
return;
}
- if (bookmarkIndex < 0) {
- bookmarkIndex = 0;
- }
-
$('[component="category"]').empty();
- loadTopicsAfter(bookmarkIndex - 1, 1, function() {
+ loadTopicsAfter(Math.max(0, bookmarkIndex - 1), 1, function() {
Category.scrollToTopic(bookmarkIndex, clickedIndex, 0);
});
}
diff --git a/public/src/modules/navigator.js b/public/src/modules/navigator.js
index d635eae181..33d3599228 100644
--- a/public/src/modules/navigator.js
+++ b/public/src/modules/navigator.js
@@ -95,11 +95,14 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
navigator.update = function() {
toggle(!!count);
- var middleOfViewport = $(window).scrollTop() + $(window).height() / 2;
+ var els = $(navigator.selector);
+ if (els.length) {
+ index = parseInt(els.first().attr('data-index'), 10) + 1;
+ }
- index = parseInt($(navigator.selector).first().attr('data-index'), 10) + 1;
+ var middleOfViewport = $(window).scrollTop() + $(window).height() / 2;
var previousDistance = Number.MAX_VALUE;
- $(navigator.selector).each(function() {
+ els.each(function() {
var distanceToMiddle = Math.abs(middleOfViewport - $(this).offset().top);
if (distanceToMiddle > previousDistance) {