Skip to content

Commit

Permalink
issue-293 - scroll to top when navigating more posts (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaret authored Mar 22, 2024
1 parent 06c9364 commit 582539d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 1 addition & 4 deletions cigaradvisor/blocks/return-to-top/return-to-top.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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';
Expand Down
5 changes: 5 additions & 0 deletions cigaradvisor/scripts/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ 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');
const link = document.createElement('a');
const currentPagePath = window.location.pathname;
const currentPageQuery = window.location.search;
link.href = `${currentPagePath}${currentPageQuery}#page=${pageNumber}`;
link.onclick = scrollTop;
link.textContent = text;

if (className) {
Expand Down

0 comments on commit 582539d

Please sign in to comment.