From 0cc900bdcfc20db4de8ba29718ba8bfea5135b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 19 Mar 2015 12:32:05 -0400 Subject: [PATCH] closes #2878 --- public/src/client/category.js | 4 ++-- public/src/client/topic.js | 14 +++++++------- public/src/modules/navigator.js | 18 +++++++++++++----- public/src/modules/share.js | 2 +- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/public/src/client/category.js b/public/src/client/category.js index 2a6a580323..bf91059a25 100644 --- a/public/src/client/category.js +++ b/public/src/client/category.js @@ -89,8 +89,8 @@ define('forum/category', [ }); }; - Category.navigatorCallback = function(element, elementCount) { - return parseInt(element.attr('data-index'), 10) + 1; + Category.navigatorCallback = function(topIndex, bottomIndex, elementCount) { + return bottomIndex; }; $(window).on('action:popstate', function(ev, data) { diff --git a/public/src/client/topic.js b/public/src/client/topic.js index 4a597b4853..cbf4074d4f 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -148,18 +148,18 @@ define('forum/topic', [ return index; }; - Topic.navigatorCallback = function(element, elementCount) { + Topic.navigatorCallback = function(topPostIndex, bottomPostIndex, elementCount) { var path = ajaxify.removeRelativePath(window.location.pathname.slice(1)); if (!path.startsWith('topic')) { return 1; } - var postIndex = parseInt(element.attr('data-index'), 10); - var index = postIndex + 1; + var postIndex = topPostIndex; + var index = bottomPostIndex; if (config.topicPostSort !== 'oldest_to_newest') { - if (postIndex === 0) { + if (bottomPostIndex === 0) { index = 1; } else { - index = Math.max(elementCount - postIndex + 1, 1); + index = Math.max(elementCount - bottomPostIndex + 2, 1); } } @@ -175,8 +175,8 @@ define('forum/topic', [ var topicId = parts[1], slug = parts[2]; var newUrl = 'topic/' + topicId + '/' + (slug ? slug : ''); - if (postIndex > 0) { - newUrl += '/' + (postIndex + 1); + if (postIndex > 1) { + newUrl += '/' + postIndex; } if (newUrl !== currentUrl) { diff --git a/public/src/modules/navigator.js b/public/src/modules/navigator.js index 49b7a8f7ca..697046bd28 100644 --- a/public/src/modules/navigator.js +++ b/public/src/modules/navigator.js @@ -90,18 +90,26 @@ define('navigator', ['forum/pagination'], function(pagination) { navigator.update = function() { toggle(!!count); - $($(navigator.selector).get().reverse()).each(function() { + var topIndex = 0; + var bottomIndex = 0; + $(navigator.selector).each(function() { var el = $(this); if (elementInView(el)) { - if (typeof navigator.callback === 'function') { - index = navigator.callback(el, count); - navigator.updateTextAndProgressBar(); + if (!topIndex) { + topIndex = parseInt(el.attr('data-index'), 10) + 1; + } else { + bottomIndex = parseInt(el.attr('data-index'), 10) + 1; } - + } else if (topIndex && bottomIndex) { return false; } }); + + if (typeof navigator.callback === 'function' && topIndex && bottomIndex) { + index = navigator.callback(topIndex, bottomIndex, count); + navigator.updateTextAndProgressBar(); + } }; navigator.updateTextAndProgressBar = function() { diff --git a/public/src/modules/share.js b/public/src/modules/share.js index 83c2dce041..6665a30b8c 100644 --- a/public/src/modules/share.js +++ b/public/src/modules/share.js @@ -50,7 +50,7 @@ define('share', function() { function getPostUrl(clickedElement) { var parts = window.location.pathname.split('/'); - var postIndex = parseInt(clickedElement.parents('data-index').attr('data-index'), 10); + var postIndex = parseInt(clickedElement.parents('[data-index]').attr('data-index'), 10); return '/' + parts[1] + '/' + parts[2] + (parts[3] ? '/' + parts[3] : '') + (postIndex ? '/' + (postIndex + 1) : ''); }