@@ -8,6 +8,9 @@ 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
+
11
14
function setupGlobalTooltip ( ) {
12
15
$ ( document ) . on ( "mouseenter" , "a" , mouseEnterHandler ) ;
13
16
@@ -23,7 +26,11 @@ function setupGlobalTooltip() {
23
26
}
24
27
25
28
function dismissAllTooltips ( ) {
26
- $ ( ".note-tooltip" ) . remove ( ) ;
29
+ openTooltipElements . forEach ( $el => {
30
+ $el . tooltip ( "dispose" ) ;
31
+ $el . removeAttr ( "aria-describedby" ) ;
32
+ } ) ;
33
+ openTooltipElements = [ ] ;
27
34
}
28
35
29
36
function setupElementTooltip ( $el : JQuery < HTMLElement > ) {
@@ -86,8 +93,8 @@ async function mouseEnterHandler(this: HTMLElement) {
86
93
// we need to check if we're still hovering over the element
87
94
// since the operation to get tooltip content was async, it is possible that
88
95
// 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 ( {
96
+ if ( $link . filter ( ":hover" ) . length > 0 ) {
97
+ $link . tooltip ( {
91
98
container : "body" ,
92
99
// https://github.com/zadam/trilium/issues/2794 https://github.com/zadam/trilium/issues/2988
93
100
// with bottom this flickering happens a bit less
@@ -103,7 +110,9 @@ async function mouseEnterHandler(this: HTMLElement) {
103
110
} ) ;
104
111
105
112
dismissAllTooltips ( ) ;
106
- $ ( this ) . tooltip ( "show" ) ;
113
+ $link . tooltip ( "show" ) ;
114
+
115
+ openTooltipElements . push ( $link ) ;
107
116
108
117
// Dismiss the tooltip immediately if a link was clicked inside the tooltip.
109
118
$ ( `.${ tooltipClass } a` ) . on ( "click" , ( e ) => {
@@ -115,7 +124,8 @@ async function mouseEnterHandler(this: HTMLElement) {
115
124
// click on links within tooltip etc. without tooltip disappearing
116
125
// - once the user moves the cursor away from both link and the tooltip, hide the tooltip
117
126
const checkTooltip = ( ) => {
118
- if ( ! $ ( this ) . filter ( ":hover" ) . length && ! $ ( `.${ linkId } :hover` ) . length ) {
127
+
128
+ if ( ! $link . filter ( ":hover" ) . length && ! $ ( `.${ linkId } :hover` ) . length ) {
119
129
// cursor is neither over the link nor over the tooltip, user likely is not interested
120
130
dismissAllTooltips ( ) ;
121
131
} else {
0 commit comments