feat(note_tooltip): display tooltip of footnote reference

This commit is contained in:
Elian Doran 2025-01-07 13:27:19 +02:00
parent ab9769c93b
commit 3f65fb83cb
No known key found for this signature in database

View File

@ -58,10 +58,15 @@ async function mouseEnterHandler(this: HTMLElement) {
return; return;
} }
const note = await froca.getNote(noteId); let renderPromise;
if (url?.startsWith("#fn")) {
renderPromise = renderFootnote($link, url);
} else {
renderPromise = renderTooltip(await froca.getNote(noteId))
}
const [content] = await Promise.all([ const [content] = await Promise.all([
renderTooltip(note), renderPromise,
// to reduce flicker due to accidental mouseover, cursor must stay for a bit over the link for tooltip to appear // to reduce flicker due to accidental mouseover, cursor must stay for a bit over the link for tooltip to appear
new Promise(res => setTimeout(res, 500)) new Promise(res => setTimeout(res, 500))
]); ]);
@ -147,6 +152,19 @@ async function renderTooltip(note: FNote | null) {
return content; return content;
} }
function renderFootnote($link: JQuery<HTMLElement>, url: string) {
// A footnote text reference
const footnoteRef = url.substring(3);
const $footnoteContent = $link
.closest(".ck-content") // find the parent CK content
.find("> .footnote-section") // find the footnote section
.find(`a[href="#fnref${footnoteRef}"]`) // find the footnote link
.closest(".footnote-item") // find the parent container of the footnote
.find(".footnote-content"); // find the actual text content of the footnote
return $footnoteContent.html() || "";
}
export default { export default {
setupGlobalTooltip, setupGlobalTooltip,
setupElementTooltip setupElementTooltip