From 12c58990990448126fac8d8d647ef92300208992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 6 Feb 2019 13:34:50 -0500 Subject: [PATCH] fix: #7339 --- public/src/modules/handleBack.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/public/src/modules/handleBack.js b/public/src/modules/handleBack.js index f5c9f61848..b6c2c16540 100644 --- a/public/src/modules/handleBack.js +++ b/public/src/modules/handleBack.js @@ -18,10 +18,12 @@ define('handleBack', [ function saveClickedIndex() { $('[component="category"]').on('click', '[component="topic/header"]', function () { var clickedIndex = $(this).parents('[data-index]').attr('data-index'); + var windowScrollTop = $(window).scrollTop(); $('[component="category/topic"]').each(function (index, el) { - if ($(el).offset().top - $(window).scrollTop() > 0) { + if ($(el).offset().top - windowScrollTop > 0) { storage.setItem('category:bookmark', $(el).attr('data-index')); storage.setItem('category:bookmark:clicked', clickedIndex); + storage.setItem('category:bookmark:offset', $(el).offset().top - windowScrollTop); return false; } }); @@ -42,10 +44,6 @@ define('handleBack', [ bookmarkIndex = Math.max(0, parseInt(bookmarkIndex, 10) || 0); clickedIndex = Math.max(0, parseInt(clickedIndex, 10) || 0); - if (!bookmarkIndex && !clickedIndex) { - return; - } - if (config.usePagination) { var page = Math.ceil((parseInt(bookmarkIndex, 10) + 1) / config.topicsPerPage); if (parseInt(page, 10) !== ajaxify.data.pagination.currentPage) { @@ -57,7 +55,7 @@ define('handleBack', [ } } else { if (bookmarkIndex === 0) { - handleBack.highlightTopic(clickedIndex); + handleBack.scrollToTopic(bookmarkIndex, clickedIndex); return; } @@ -88,7 +86,9 @@ define('handleBack', [ var scrollTo = components.get('category/topic', 'index', bookmarkIndex); if (scrollTo.length) { - $(window).scrollTop(scrollTo.offset().top); + var offset = storage.getItem('category:bookmark:offset'); + storage.removeItem('category:bookmark:offset'); + $(window).scrollTop(scrollTo.offset().top - offset); handleBack.highlightTopic(clickedIndex); navigator.update(); }