From 48a8ec4ab20a47eeb7580410d2b389503cf3ce4b Mon Sep 17 00:00:00 2001 From: psychobunny Date: Wed, 23 Sep 2020 07:57:45 -0400 Subject: [PATCH] feat: return to previous page and/or category after marking topic unread ... also return to category if pagination is active and previous page was another page in the thread --- public/src/client/topic/threadTools.js | 10 +++++++++- public/src/modules/handleBack.js | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/public/src/client/topic/threadTools.js b/public/src/client/topic/threadTools.js index 32a910f442..646438df41 100644 --- a/public/src/client/topic/threadTools.js +++ b/public/src/client/topic/threadTools.js @@ -4,7 +4,8 @@ define('forum/topic/threadTools', [ 'components', 'translator', -], function (components, translator) { + 'handleBack', +], function (components, translator, handleBack) { var ThreadTools = {}; ThreadTools.init = function (tid, topicContainer) { @@ -50,6 +51,13 @@ define('forum/topic/threadTools', [ if (err) { return app.alertError(err); } + + if (app.previousUrl && !app.previousUrl.match('^/topic')) { + ajaxify.go(app.previousUrl, handleBack.onBackClicked); + } else if (ajaxify.data.category) { + ajaxify.go('category/' + ajaxify.data.category.slug, handleBack.onBackClicked); + } + app.alertSuccess('[[topic:mark_unread.success]]'); }); return false; diff --git a/public/src/modules/handleBack.js b/public/src/modules/handleBack.js index b6c2c16540..3de96cb414 100644 --- a/public/src/modules/handleBack.js +++ b/public/src/modules/handleBack.js @@ -15,6 +15,8 @@ define('handleBack', [ $(window).off('action:popstate', onBackClicked).on('action:popstate', onBackClicked); }; + handleBack.onBackClicked = onBackClicked; + function saveClickedIndex() { $('[component="category"]').on('click', '[component="topic/header"]', function () { var clickedIndex = $(this).parents('[data-index]').attr('data-index');