From 5a342748d5c17386741aa9f774a514ec7ce60fdc Mon Sep 17 00:00:00 2001 From: tmaret Date: Fri, 22 Mar 2024 10:43:01 +0100 Subject: [PATCH] issue-293 - scroll to top when navigating more posts --- cigaradvisor/blocks/return-to-top/return-to-top.js | 5 +---- cigaradvisor/scripts/util.js | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cigaradvisor/blocks/return-to-top/return-to-top.js b/cigaradvisor/blocks/return-to-top/return-to-top.js index de1e159..d69a015 100644 --- a/cigaradvisor/blocks/return-to-top/return-to-top.js +++ b/cigaradvisor/blocks/return-to-top/return-to-top.js @@ -1,6 +1,7 @@ import { buildBlock, createOptimizedPicture, decorateBlock, decorateIcons, loadBlock, } from '../../scripts/aem.js'; +import { scrollTop } from '../../scripts/util.js'; function onScroll() { const link = document.getElementById('return-to-top'); @@ -11,10 +12,6 @@ function onScroll() { } } -function scrollTop() { - window.scrollTo({ top: 0, behavior: 'smooth' }); -} - export default function decorate(block) { const link = document.createElement('a'); link.id = 'return-to-top'; diff --git a/cigaradvisor/scripts/util.js b/cigaradvisor/scripts/util.js index cab06a5..99d900e 100644 --- a/cigaradvisor/scripts/util.js +++ b/cigaradvisor/scripts/util.js @@ -23,6 +23,10 @@ function createEllipsis() { return listItem; } +export function scrollTop() { + window.scrollTo({ top: 0, behavior: 'smooth' }); +} + // Function to create a page link function createPageLink(pageNumber, text, className) { const listItem = document.createElement('li'); @@ -30,6 +34,7 @@ function createPageLink(pageNumber, text, className) { const currentPagePath = window.location.pathname; const currentPageQuery = window.location.search; link.href = `${currentPagePath}${currentPageQuery}#page=${pageNumber}`; + link.onclick = scrollTop; link.textContent = text; if (className) {