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) {