Node.js based forum software built for the modern web
fix: hacking handleBack module to work with world page
Julian Lam971c8603c5c3
diff --git a/public/src/client/world.js b/public/src/client/world.jsindex 420e22e804..074878abc5 100644--- a/public/src/client/world.js+++ b/public/src/client/world.js@@ -3,10 +3,10 @@define('forum/world', ['forum/infinitescroll', 'search', 'sort', 'hooks','alerts', 'api', 'bootbox', 'helpers', 'forum/category/tools',- 'translator', 'quickreply',+ 'translator', 'quickreply', 'handleBack',], function (infinitescroll, search, sort, hooks,alerts, api, bootbox, helpers, categoryTools,- translator, quickreply) {+ translator, quickreply, handleBack) {const World = {};World.init = function () {@@ -47,6 +47,20 @@ define('forum/world', [}}+ handleBack.init((after, handleBackCb) => {+ loadTopicsAfter(after, 1, (payload, callback) => {+ app.parseAndTranslate(ajaxify.data.template.name, 'posts', payload, function (html) {+ const listEl = document.getElementById('world-feed');+ $(listEl).append(html);+ html.find('.timeago').timeago();+ handleImages();+ handleShowMoreButtons();+ callback();+ handleBackCb();+ });+ });+ }, { container: '#world-feed' });+search.enableQuickSearch({searchElements: {inputEl: $('[component="category-search"]'),@@ -65,6 +79,10 @@ define('forum/world', [if (!config.usePagination) {infinitescroll.init((direction) => {const posts = Array.from(document.querySelectorAll('[component="category/topic"]'));+ if (!posts.length) {+ return;+ }+const afterEl = direction > 0 ? posts.pop() : posts.shift();const after = (parseInt(afterEl.getAttribute('data-index'), 10) || 0) + (direction > 0 ? 1 : 0);if (after < config.topicsPerPage) {@@ -74,7 +92,7 @@ define('forum/world', [loadTopicsAfter(after, direction, (payload, callback) => {app.parseAndTranslate(ajaxify.data.template.name, 'posts', payload, function (html) {const listEl = document.getElementById('world-feed');- $(listEl).append(html);+ $(listEl)[direction === -1 ? 'prepend' : 'append'](html);html.find('.timeago').timeago();handleImages();handleShowMoreButtons();diff --git a/public/src/modules/handleBack.js b/public/src/modules/handleBack.jsindex 2df8baceda..97fcc0422f 100644--- a/public/src/modules/handleBack.js+++ b/public/src/modules/handleBack.js@@ -8,9 +8,17 @@ define('handleBack', [], function (components, storage, navigator, pagination) {const handleBack = {};let loadTopicsMethod;+ const elements = new Map();+ const defaults = new Map([+ ['container', '[component="category"]'],+ ]);- handleBack.init = function (_loadTopicsMethod) {+ handleBack.init = function (_loadTopicsMethod, _elements = {}) {loadTopicsMethod = _loadTopicsMethod;+ ['container'].forEach((prop) => {+ elements.set(prop, _elements[prop] || defaults.get(prop));+ });+saveClickedIndex();$(window).off('action:popstate', onBackClicked).on('action:popstate', onBackClicked);};@@ -18,10 +26,10 @@ define('handleBack', [handleBack.onBackClicked = onBackClicked;function saveClickedIndex() {- $('[component="category"]').on('click', '[component="topic/header"]', function () {- const clickedIndex = $(this).parents('[data-index]').attr('data-index');+ $(elements.get('container')).on('click', '[data-index]', function () {+ const clickedIndex = $(this).attr('data-index');const windowScrollTop = $(window).scrollTop();- $('[component="category/topic"]').each(function (index, el) {+ $(elements.get('container')).find('[data-index]').each(function (index, el) {if ($(el).offset().top - windowScrollTop > 0) {storage.setItem('category:bookmark', $(el).attr('data-index'));storage.setItem('category:bookmark:clicked', clickedIndex);@@ -38,6 +46,7 @@ define('handleBack', [ajaxify.data.template.category ||ajaxify.data.template.recent ||ajaxify.data.template.popular ||+ ajaxify.data.template.world ||highlightUnread) {let bookmarkIndex = storage.getItem('category:bookmark');@@ -67,7 +76,7 @@ define('handleBack', [return;}- $('[component="category"]').empty();+ $(elements.get('container')).empty();loadTopicsMethod(Math.max(0, bookmarkIndex - 1) + 1, function () {handleBack.scrollToTopic(bookmarkIndex, clickedIndex);});