From 20c841128722b66c8daa17b08641598cf0e98a5e Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 12 Nov 2015 14:14:27 -0500 Subject: [PATCH] closes #3767 closes #3774 --- public/src/client/category.js | 10 ++++------ public/src/modules/navigator.js | 9 ++++++--- 2 files changed, 10 insertions(+), 9 deletions(-) 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) {