From 9ea4fa9ea7c640cb767a6d3fd66f299d7d880409 Mon Sep 17 00:00:00 2001 From: Nonimart Date: Tue, 24 Jun 2025 12:52:54 +0200 Subject: [PATCH] FEATURE Introducing dedicated external component --- resources/js/singles/footnote-format.ts | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 resources/js/singles/footnote-format.ts diff --git a/resources/js/singles/footnote-format.ts b/resources/js/singles/footnote-format.ts new file mode 100644 index 0000000..12dab1c --- /dev/null +++ b/resources/js/singles/footnote-format.ts @@ -0,0 +1,27 @@ +import { + scrollToFootnoteInIndexPanel, + toggleActiveTabPanel, + toggleActiveFootnoteLinkInIndexPanel, +} from './index-panel'; + +export default function handleFootnoteFormat(): void { + const footnotes = document.querySelectorAll('.content-area .footnote-reference'); + + footnotes.forEach((footnote) => { + const footnoteId = footnote.getAttribute('id'); + if (!footnoteId) return; + + footnote.addEventListener('click', () => { + toggleActiveTabPanel('footnotes'); + scrollToFootnoteInIndexPanel(footnoteId); + toggleActiveFootnoteLinkInIndexPanel(footnoteId); + }); + }); +} + +export function scrollToFootnote(footnoteId: string): void { + const footnote = document.querySelector(`a.footnote-reference#${footnoteId}`); + if (!footnote) return; + + footnote.scrollIntoView({ behavior: 'smooth' }); +}