mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 02:42:27 +08:00
chore(client/ts): port services/note_tooltip
This commit is contained in:
parent
e889955e8b
commit
6f32f21ac4
@ -5,6 +5,7 @@ import utils from "./utils.js";
|
|||||||
import attributeRenderer from "./attribute_renderer.js";
|
import attributeRenderer from "./attribute_renderer.js";
|
||||||
import contentRenderer from "./content_renderer.js";
|
import contentRenderer from "./content_renderer.js";
|
||||||
import appContext from "../components/app_context.js";
|
import appContext from "../components/app_context.js";
|
||||||
|
import FNote from "../entities/fnote.js";
|
||||||
|
|
||||||
function setupGlobalTooltip() {
|
function setupGlobalTooltip() {
|
||||||
$(document).on("mouseenter", "a", mouseEnterHandler);
|
$(document).on("mouseenter", "a", mouseEnterHandler);
|
||||||
@ -24,11 +25,11 @@ function cleanUpTooltips() {
|
|||||||
$('.note-tooltip').remove();
|
$('.note-tooltip').remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupElementTooltip($el) {
|
function setupElementTooltip($el: JQuery<HTMLElement>) {
|
||||||
$el.on('mouseenter', mouseEnterHandler);
|
$el.on('mouseenter', mouseEnterHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function mouseEnterHandler() {
|
async function mouseEnterHandler(this: HTMLElement) {
|
||||||
const $link = $(this);
|
const $link = $(this);
|
||||||
|
|
||||||
if ($link.hasClass("no-tooltip-preview") || $link.hasClass("disabled")) {
|
if ($link.hasClass("no-tooltip-preview") || $link.hasClass("disabled")) {
|
||||||
@ -44,7 +45,7 @@ async function mouseEnterHandler() {
|
|||||||
const url = $link.attr("href") || $link.attr("data-href");
|
const url = $link.attr("href") || $link.attr("data-href");
|
||||||
const { notePath, noteId, viewScope } = linkService.parseNavigationStateFromUrl(url);
|
const { notePath, noteId, viewScope } = linkService.parseNavigationStateFromUrl(url);
|
||||||
|
|
||||||
if (!notePath || viewScope.viewMode !== 'default') {
|
if (!notePath || !noteId || viewScope?.viewMode !== 'default') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ async function mouseEnterHandler() {
|
|||||||
new Promise(res => setTimeout(res, 500))
|
new Promise(res => setTimeout(res, 500))
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (utils.isHtmlEmpty(content)) {
|
if (!content || utils.isHtmlEmpty(content)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +82,8 @@ async function mouseEnterHandler() {
|
|||||||
// with bottom this flickering happens a bit less
|
// with bottom this flickering happens a bit less
|
||||||
placement: 'bottom',
|
placement: 'bottom',
|
||||||
trigger: 'manual',
|
trigger: 'manual',
|
||||||
boundary: 'window',
|
//TODO: boundary No longer applicable?
|
||||||
|
//boundary: 'window',
|
||||||
title: html,
|
title: html,
|
||||||
html: true,
|
html: true,
|
||||||
template: `<div class="tooltip note-tooltip ${tooltipClass}" role="tooltip"><div class="arrow"></div><div class="tooltip-inner"></div></div>`,
|
template: `<div class="tooltip note-tooltip ${tooltipClass}" role="tooltip"><div class="arrow"></div><div class="tooltip-inner"></div></div>`,
|
||||||
@ -114,7 +116,7 @@ async function mouseEnterHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function renderTooltip(note) {
|
async function renderTooltip(note: FNote | null) {
|
||||||
if (!note) {
|
if (!note) {
|
||||||
return '<div>Note has been deleted.</div>';
|
return '<div>Note has been deleted.</div>';
|
||||||
}
|
}
|
||||||
@ -126,7 +128,11 @@ async function renderTooltip(note) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = `<h5 class="note-tooltip-title">${(await treeService.getNoteTitleWithPathAsSuffix(bestNotePath)).prop('outerHTML')}</h5>`;
|
const noteTitleWithPathAsSuffix = await treeService.getNoteTitleWithPathAsSuffix(bestNotePath);
|
||||||
|
let content = "";
|
||||||
|
if (noteTitleWithPathAsSuffix) {
|
||||||
|
content = `<h5 class="note-tooltip-title">${noteTitleWithPathAsSuffix.prop('outerHTML')}</h5>`;
|
||||||
|
}
|
||||||
|
|
||||||
const {$renderedAttributes} = await attributeRenderer.renderNormalAttributes(note);
|
const {$renderedAttributes} = await attributeRenderer.renderNormalAttributes(note);
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user