REFACTOR code to best handle index panel and different single. javascript features

This commit is contained in:
Nonimart 2025-06-24 12:52:35 +02:00
parent b045a76e5c
commit 086d318c9c

View File

@ -1,4 +1,5 @@
import handleIndexPanels from './index-panel';
import handleIndexPanel from './index-panel';
import handleFootnoteFormat from './footnote-format';
export default function singles(): void {
const isSingleRevue: HTMLElement | null = document.querySelector('.page--single-revue');
@ -7,9 +8,9 @@ export default function singles(): void {
injectIdToNativeTitles();
handleIndexPanels();
handleIndexPanel();
handleFootnoteFormat();
handleCiteButton();
handleSmoothScrollToTitle();
}
function handleCiteButton(): void {
@ -75,20 +76,3 @@ function injectIdToNativeTitles(): void {
title.setAttribute('id', slug);
});
}
function handleSmoothScrollToTitle(): void {
const sommaireTitles: NodeListOf<Element> = document.querySelectorAll('.sommaire-index li a');
for (const title of sommaireTitles) {
title.addEventListener('click', (e) => {
e.preventDefault();
const target = title.getAttribute('href');
if (!target) return;
const targetElement = document.querySelector(target);
if (!targetElement) return;
targetElement.scrollIntoView({ behavior: 'smooth' });
});
}
}