@@ -9,7 +9,7 @@ const localeData = {
9
9
type : 2 ,
10
10
hint : null ,
11
11
btn : null ,
12
- expandTimeout : null , // New property for expansion timeout
12
+ expandTimeout : null , // Property for expansion timeout
13
13
currentElement : null , // Track current element for expansion
14
14
observer : null , // MutationObserver for DOM changes
15
15
} ;
@@ -66,13 +66,13 @@ async function tooltipCreate() {
66
66
67
67
// Setup event delegation for tooltips instead of individual listeners
68
68
if ( localeData . type === 2 ) {
69
- gradioApp ( ) . addEventListener ( 'mouseover' , tooltipShowDelegated ) ;
70
- gradioApp ( ) . addEventListener ( 'mouseout' , tooltipHideDelegated ) ;
69
+ gradioApp ( ) . addEventListener ( 'mouseover' , tooltipShowDelegated ) ; // eslint-disable-line no-use-before-define
70
+ gradioApp ( ) . addEventListener ( 'mouseout' , tooltipHideDelegated ) ; // eslint-disable-line no-use-before-define
71
71
}
72
72
73
73
// Initialize DOM observer for immediate hint application
74
74
if ( ! localeData . observer ) {
75
- initializeDOMObserver ( ) ;
75
+ initializeDOMObserver ( ) ; // eslint-disable-line no-use-before-define
76
76
}
77
77
}
78
78
@@ -100,13 +100,13 @@ async function expandTooltip(element, longHint) {
100
100
async function tooltipShowDelegated ( e ) {
101
101
// Use event delegation to handle dynamically created elements
102
102
if ( e . target . dataset && e . target . dataset . hint ) {
103
- tooltipShow ( e ) ;
103
+ tooltipShow ( e ) ; // eslint-disable-line no-use-before-define
104
104
}
105
105
}
106
106
107
107
async function tooltipHideDelegated ( e ) {
108
108
if ( e . target . dataset && e . target . dataset . hint ) {
109
- tooltipHide ( e ) ;
109
+ tooltipHide ( e ) ; // eslint-disable-line no-use-before-define
110
110
}
111
111
}
112
112
@@ -319,10 +319,6 @@ async function setHint(el, entry) {
319
319
el . dataset . hint = entry . hint ;
320
320
if ( entry . longHint && entry . longHint . length > 0 ) el . dataset . longHint = entry . longHint ;
321
321
if ( entry . reload && entry . reload . length > 0 ) el . dataset . reload = entry . reload ;
322
- // Don't add individual listeners - we use event delegation now
323
- // This means we don't need to reattach listeners when elements are recreated
324
- // el.addEventListener('mouseover', tooltipShow);
325
- // el.addEventListener('mouseout', tooltipHide);
326
322
} else {
327
323
// tooltips disabled
328
324
}
@@ -393,10 +389,9 @@ async function applyHintToElement(el) {
393
389
if ( ! el . textContent ) return ;
394
390
395
391
// Check if element matches our selector criteria
396
- const isValidElement =
397
- el . tagName === 'BUTTON' ||
398
- el . tagName === 'H2' ||
399
- ( el . tagName === 'SPAN' && ( el . parentElement ?. tagName === 'LABEL' || el . parentElement ?. classList . contains ( 'label-wrap' ) ) ) ;
392
+ const isValidElement = el . tagName === 'BUTTON'
393
+ || el . tagName === 'H2'
394
+ || ( el . tagName === 'SPAN' && ( el . parentElement ?. tagName === 'LABEL' || el . parentElement ?. classList . contains ( 'label-wrap' ) ) ) ;
400
395
401
396
if ( ! isValidElement ) return ;
402
397
@@ -445,16 +440,16 @@ function initializeDOMObserver() {
445
440
446
441
// Include the node itself if it matches
447
442
if ( node . matches && (
448
- node . matches ( 'button' ) ||
449
- node . matches ( 'h2' ) ||
450
- node . matches ( 'label > span' ) ||
451
- node . matches ( '.label-wrap > span' )
443
+ node . matches ( 'button' )
444
+ || node . matches ( 'h2' )
445
+ || node . matches ( 'label > span' )
446
+ || node . matches ( '.label-wrap > span' )
452
447
) ) {
453
448
elements . push ( node ) ;
454
449
}
455
450
456
451
// Apply hints immediately to all found elements
457
- elements . forEach ( el => applyHintToElement ( el ) ) ;
452
+ elements . forEach ( ( el ) => applyHintToElement ( el ) ) ;
458
453
}
459
454
}
460
455
}
@@ -466,7 +461,7 @@ function initializeDOMObserver() {
466
461
if ( targetNode ) {
467
462
localeData . observer . observe ( targetNode , {
468
463
childList : true ,
469
- subtree : true
464
+ subtree : true ,
470
465
} ) ;
471
466
}
472
467
}
0 commit comments