REFACTOR Fixing duplicate handleSmoothScrollToTitle function

This commit is contained in:
Nonimart 2025-06-24 12:55:43 +02:00
parent 4e66d244ee
commit 6d12445569
2 changed files with 4 additions and 20 deletions

View File

@ -69,12 +69,6 @@ function observeSommaireLinks(): void {
} }
} }
function handleSmoothScrollToTitle(targetId: string): void {
const targetElement = document.querySelector(`#${targetId}`);
if (!targetElement) return;
targetElement.scrollIntoView({ behavior: 'smooth' });
}
function toggleActiveChapterLinkInIndexPanel(targetId: string): void { function toggleActiveChapterLinkInIndexPanel(targetId: string): void {
const sommaireLinks: NodeListOf<Element> = document.querySelectorAll('.sommaire-index li a'); const sommaireLinks: NodeListOf<Element> = document.querySelectorAll('.sommaire-index li a');

View File

@ -1,16 +1,6 @@
export function handleSmoothScrollToTitle(): void { export function handleSmoothScrollToTitle(targetId: string): void {
const sommaireTitles: NodeListOf<Element> = document.querySelectorAll('.sommaire-index li a'); const targetElement = document.querySelector(`#${targetId}`);
for (const title of sommaireTitles) { if (!targetElement) return;
title.addEventListener('click', (e) => {
e.preventDefault();
const target = title.getAttribute('href'); targetElement.scrollIntoView({ behavior: 'smooth' });
if (!target) return;
const targetElement = document.querySelector(target);
if (!targetElement) return;
targetElement.scrollIntoView({ behavior: 'smooth' });
});
}
} }