From ba0b48d6dc6a025e461cf45ef03f3bfd3010680c Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 7 Jan 2025 13:40:55 +0200 Subject: [PATCH] feat(footnotes): clicking a reference navigates to footnote --- src/public/app/services/link.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/public/app/services/link.ts b/src/public/app/services/link.ts index 2874ffea9..3cd5b1a70 100644 --- a/src/public/app/services/link.ts +++ b/src/public/app/services/link.ts @@ -242,7 +242,7 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent, hrefLink: string | und evt.preventDefault(); evt.stopPropagation(); - if (hrefLink?.startsWith("#fnref")) { + if (hrefLink?.startsWith("#fn")) { return handleFootnote(hrefLink, $link); } @@ -305,6 +305,13 @@ function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent, hrefLink: string | und return true; } +/** + * Scrolls to either the footnote (if clicking on a reference such as `[1]`), or to the reference of a footnote (if clicking on the footnote `^` arrow). + * + * @param hrefLink the URL of the link that was clicked (it should be in the form of `#fn` or `#fnref`). + * @param $link the element of the link that was clicked. + * @returns whether the event should be consumed or not. + */ function handleFootnote(hrefLink: string, $link: JQuery) { const el = $link.closest(".ck-content") .find(hrefLink)[0];