Skip to content

Commit

Permalink
feat: return to previous page and/or category after marking topic unread
Browse files Browse the repository at this point in the history
... also return to category if pagination is active and previous page was another page in the thread
  • Loading branch information
psychobunny committed Sep 23, 2020
1 parent 6ebd2c8 commit 48a8ec4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion public/src/client/topic/threadTools.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions public/src/modules/handleBack.js
Expand Up @@ -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');
Expand Down

0 comments on commit 48a8ec4

Please sign in to comment.