Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 9f8d3d0

Browse files
committed
settings.js: refactor settingsBlurHandler
changes: * Add type signature * Add null checks * getHelpButton and getSettingsButton are only called once, which should marginally improve performance due to less queries. unfortunatly 2 @ts-expect-error was needed, as typescript is unaware the EventTarget is likely an Element.
1 parent f056836 commit 9f8d3d0

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/librustdoc/html/static/js/settings.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,21 @@
310310
});
311311
}
312312

313+
/**
314+
* @param {MouseEvent} event
315+
*/
313316
function settingsBlurHandler(event) {
314-
if (!getHelpButton().contains(document.activeElement) &&
315-
!getHelpButton().contains(event.relatedTarget) &&
316-
!getSettingsButton().contains(document.activeElement) &&
317-
!getSettingsButton().contains(event.relatedTarget)
318-
) {
317+
const helpBtn = getHelpButton();
318+
const settingsBtn = getSettingsButton();
319+
const helpUnfocused = helpBtn === null ||
320+
(!helpBtn.contains(document.activeElement) &&
321+
// @ts-expect-error
322+
!helpBtn.contains(event.relatedTarget));
323+
const settingsUnfocused = settingsBtn === null ||
324+
(!settingsBtn.contains(document.activeElement) &&
325+
// @ts-expect-error
326+
!settingsBtn.contains(event.relatedTarget));
327+
if (helpUnfocused && settingsUnfocused) {
319328
window.hidePopoverMenus();
320329
}
321330
}

0 commit comments

Comments
 (0)