Node.js based forum software built for the modern web
closes #2878
Barış Soner Uşaklı0cc900bdcfc2
diff --git a/public/src/client/category.js b/public/src/client/category.jsindex 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.jsindex 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.jsindex 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.jsindex 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) : '');}