@@ -8,6 +8,10 @@ import appContext from "../components/app_context.js";
8
8
import type FNote from "../entities/fnote.js" ;
9
9
import { t } from "./i18n.js" ;
10
10
11
+ // Track all elements that open tooltips
12
+ let openTooltipElements : JQuery < HTMLElement > [ ] = [ ] ;
13
+ let dismissTimer : ReturnType < typeof setTimeout > ;
14
+
11
15
function setupGlobalTooltip ( ) {
12
16
$ ( document ) . on ( "mouseenter" , "a" , mouseEnterHandler ) ;
13
17
@@ -23,7 +27,12 @@ function setupGlobalTooltip() {
23
27
}
24
28
25
29
function dismissAllTooltips ( ) {
26
- $ ( ".note-tooltip" ) . remove ( ) ;
30
+ clearTimeout ( dismissTimer ) ;
31
+ openTooltipElements . forEach ( $el => {
32
+ $el . tooltip ( "dispose" ) ;
33
+ $el . removeAttr ( "aria-describedby" ) ;
34
+ } ) ;
35
+ openTooltipElements = [ ] ;
27
36
}
28
37
29
38
function setupElementTooltip ( $el : JQuery < HTMLElement > ) {
@@ -86,8 +95,8 @@ async function mouseEnterHandler(this: HTMLElement) {
86
95
// we need to check if we're still hovering over the element
87
96
// since the operation to get tooltip content was async, it is possible that
88
97
// we now create tooltip which won't close because it won't receive mouseleave event
89
- if ( $ ( this ) . filter ( ":hover" ) . length > 0 ) {
90
- $ ( this ) . tooltip ( {
98
+ if ( $link . filter ( ":hover" ) . length > 0 ) {
99
+ $link . tooltip ( {
91
100
container : "body" ,
92
101
// https://github.com/zadam/trilium/issues/2794 https://github.com/zadam/trilium/issues/2988
93
102
// with bottom this flickering happens a bit less
@@ -103,7 +112,9 @@ async function mouseEnterHandler(this: HTMLElement) {
103
112
} ) ;
104
113
105
114
dismissAllTooltips ( ) ;
106
- $ ( this ) . tooltip ( "show" ) ;
115
+ $link . tooltip ( "show" ) ;
116
+
117
+ openTooltipElements . push ( $link ) ;
107
118
108
119
// Dismiss the tooltip immediately if a link was clicked inside the tooltip.
109
120
$ ( `.${ tooltipClass } a` ) . on ( "click" , ( e ) => {
@@ -115,15 +126,16 @@ async function mouseEnterHandler(this: HTMLElement) {
115
126
// click on links within tooltip etc. without tooltip disappearing
116
127
// - once the user moves the cursor away from both link and the tooltip, hide the tooltip
117
128
const checkTooltip = ( ) => {
118
- if ( ! $ ( this ) . filter ( ":hover" ) . length && ! $ ( `.${ linkId } :hover` ) . length ) {
129
+
130
+ if ( ! $link . filter ( ":hover" ) . length && ! $ ( `.${ linkId } :hover` ) . length ) {
119
131
// cursor is neither over the link nor over the tooltip, user likely is not interested
120
132
dismissAllTooltips ( ) ;
121
133
} else {
122
- setTimeout ( checkTooltip , 1000 ) ;
134
+ dismissTimer = setTimeout ( checkTooltip , 1000 ) ;
123
135
}
124
136
} ;
125
137
126
- setTimeout ( checkTooltip , 1000 ) ;
138
+ dismissTimer = setTimeout ( checkTooltip , 1000 ) ;
127
139
}
128
140
}
129
141
@@ -176,7 +188,25 @@ function renderFootnote($link: JQuery<HTMLElement>, url: string) {
176
188
. closest ( ".footnote-item" ) // find the parent container of the footnote
177
189
. find ( ".footnote-content" ) ; // find the actual text content of the footnote
178
190
179
- return $footnoteContent . html ( ) || "" ;
191
+ const isEditable = $link . closest ( ".ck-content" ) . hasClass ( "note-detail-editable-text-editor" ) ;
192
+ if ( isEditable ) {
193
+ /* Remove widget buttons for tables, formulas, and images in editable notes. */
194
+ $footnoteContent . find ( '.ck-widget__selection-handle' ) . remove ( ) ;
195
+ $footnoteContent . find ( '.ck-widget__type-around' ) . remove ( ) ;
196
+ $footnoteContent . find ( '.ck-widget__resizer' ) . remove ( ) ;
197
+
198
+ /* Handling in-line math formulas */
199
+ $footnoteContent . find ( '.ck-math-tex.ck-math-tex-inline.ck-widget' ) . each ( function ( ) {
200
+ const $katex = $ ( this ) . find ( '.katex' ) . first ( ) ;
201
+ if ( $katex . length ) {
202
+ $ ( this ) . replaceWith ( $ ( '<span class="math-tex"></span>' ) . append ( $ ( '<span></span>' ) . append ( $katex . clone ( ) ) ) ) ;
203
+ }
204
+ } ) ;
205
+ }
206
+
207
+ let footnoteContent = $footnoteContent . html ( ) ;
208
+ footnoteContent = `<div class="ck-content">${ footnoteContent } </div>`
209
+ return footnoteContent || "" ;
180
210
}
181
211
182
212
export default {
0 commit comments