mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
feat(client): render tooltips for bookmarks
This commit is contained in:
parent
6e67832416
commit
941d0d45f8
@ -73,8 +73,8 @@ async function mouseEnterHandler(this: HTMLElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let renderPromise;
|
let renderPromise;
|
||||||
if (url?.startsWith("#fn")) {
|
if (url && url.startsWith("#") && !url.startsWith("#root/")) {
|
||||||
renderPromise = renderFootnote($link, url);
|
renderPromise = renderFootnoteOrAnchor($link, url);
|
||||||
} else {
|
} else {
|
||||||
renderPromise = renderTooltip(await froca.getNote(noteId));
|
renderPromise = renderTooltip(await froca.getNote(noteId));
|
||||||
}
|
}
|
||||||
@ -178,33 +178,47 @@ async function renderTooltip(note: FNote | null) {
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderFootnote($link: JQuery<HTMLElement>, url: string) {
|
function renderFootnoteOrAnchor($link: JQuery<HTMLElement>, url: string) {
|
||||||
// A footnote text reference
|
// A footnote text reference
|
||||||
const footnoteRef = url.substring(3);
|
const footnoteRef = url.substring(3);
|
||||||
const $footnoteContent = $link
|
let $targetContent: JQuery<HTMLElement>;
|
||||||
.closest(".ck-content") // find the parent CK content
|
|
||||||
.find("> .footnote-section") // find the footnote section
|
if (url.startsWith("#fn")) {
|
||||||
.find(`a[href="#fnref${footnoteRef}"]`) // find the footnote link
|
$targetContent = $link
|
||||||
.closest(".footnote-item") // find the parent container of the footnote
|
.closest(".ck-content") // find the parent CK content
|
||||||
.find(".footnote-content"); // find the actual text content of the footnote
|
.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
|
||||||
|
} else {
|
||||||
|
$targetContent = $link
|
||||||
|
.closest(".ck-content")
|
||||||
|
.find(url)
|
||||||
|
.closest("p");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$targetContent.length) {
|
||||||
|
// If the target content is not found, return an empty string
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
const isEditable = $link.closest(".ck-content").hasClass("note-detail-editable-text-editor");
|
const isEditable = $link.closest(".ck-content").hasClass("note-detail-editable-text-editor");
|
||||||
if (isEditable) {
|
if (isEditable) {
|
||||||
/* Remove widget buttons for tables, formulas, and images in editable notes. */
|
/* Remove widget buttons for tables, formulas, and images in editable notes. */
|
||||||
$footnoteContent.find('.ck-widget__selection-handle').remove();
|
$targetContent.find('.ck-widget__selection-handle').remove();
|
||||||
$footnoteContent.find('.ck-widget__type-around').remove();
|
$targetContent.find('.ck-widget__type-around').remove();
|
||||||
$footnoteContent.find('.ck-widget__resizer').remove();
|
$targetContent.find('.ck-widget__resizer').remove();
|
||||||
|
|
||||||
/* Handling in-line math formulas */
|
/* Handling in-line math formulas */
|
||||||
$footnoteContent.find('.ck-math-tex.ck-math-tex-inline.ck-widget').each(function () {
|
$targetContent.find('.ck-math-tex.ck-math-tex-inline.ck-widget').each(function () {
|
||||||
const $katex = $(this).find('.katex').first();
|
const $katex = $(this).find('.katex').first();
|
||||||
if ($katex.length) {
|
if ($katex.length) {
|
||||||
$(this).replaceWith($('<span class="math-tex"></span>').append($('<span></span>').append($katex.clone())));
|
$(this).replaceWith($('<span class="math-tex"></span>').append($('<span></span>').append($katex.clone())));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let footnoteContent = $footnoteContent.html();
|
let footnoteContent = $targetContent.html();
|
||||||
footnoteContent = `<div class="ck-content">${footnoteContent}</div>`
|
footnoteContent = `<div class="ck-content">${footnoteContent}</div>`
|
||||||
return footnoteContent || "";
|
return footnoteContent || "";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user