Skip to content

Commit e54f514

Browse files
Cleanup and final lint
1 parent 8eabbe3 commit e54f514

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

javascript/setHints.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const localeData = {
99
type: 2,
1010
hint: null,
1111
btn: null,
12-
expandTimeout: null, // New property for expansion timeout
12+
expandTimeout: null, // Property for expansion timeout
1313
currentElement: null, // Track current element for expansion
1414
observer: null, // MutationObserver for DOM changes
1515
};
@@ -66,13 +66,13 @@ async function tooltipCreate() {
6666

6767
// Setup event delegation for tooltips instead of individual listeners
6868
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
7171
}
7272

7373
// Initialize DOM observer for immediate hint application
7474
if (!localeData.observer) {
75-
initializeDOMObserver();
75+
initializeDOMObserver(); // eslint-disable-line no-use-before-define
7676
}
7777
}
7878

@@ -100,13 +100,13 @@ async function expandTooltip(element, longHint) {
100100
async function tooltipShowDelegated(e) {
101101
// Use event delegation to handle dynamically created elements
102102
if (e.target.dataset && e.target.dataset.hint) {
103-
tooltipShow(e);
103+
tooltipShow(e); // eslint-disable-line no-use-before-define
104104
}
105105
}
106106

107107
async function tooltipHideDelegated(e) {
108108
if (e.target.dataset && e.target.dataset.hint) {
109-
tooltipHide(e);
109+
tooltipHide(e); // eslint-disable-line no-use-before-define
110110
}
111111
}
112112

@@ -319,10 +319,6 @@ async function setHint(el, entry) {
319319
el.dataset.hint = entry.hint;
320320
if (entry.longHint && entry.longHint.length > 0) el.dataset.longHint = entry.longHint;
321321
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);
326322
} else {
327323
// tooltips disabled
328324
}
@@ -393,10 +389,9 @@ async function applyHintToElement(el) {
393389
if (!el.textContent) return;
394390

395391
// 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')));
400395

401396
if (!isValidElement) return;
402397

@@ -445,16 +440,16 @@ function initializeDOMObserver() {
445440

446441
// Include the node itself if it matches
447442
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')
452447
)) {
453448
elements.push(node);
454449
}
455450

456451
// Apply hints immediately to all found elements
457-
elements.forEach(el => applyHintToElement(el));
452+
elements.forEach((el) => applyHintToElement(el));
458453
}
459454
}
460455
}
@@ -466,7 +461,7 @@ function initializeDOMObserver() {
466461
if (targetNode) {
467462
localeData.observer.observe(targetNode, {
468463
childList: true,
469-
subtree: true
464+
subtree: true,
470465
});
471466
}
472467
}

0 commit comments

Comments
 (0)