diff options
| author | binarycat <binarycat@envs.net> | 2025-04-02 13:09:49 -0500 |
|---|---|---|
| committer | binarycat <binarycat@envs.net> | 2025-04-02 13:18:48 -0500 |
| commit | 9f8d3d0bc9057ecc9de715a5cf65d97dc67da766 (patch) | |
| tree | 95502079a8540b2ed61380c173c84c7d3baa00f5 | |
| parent | f05683639d64dc26e51f63d97a0ba3cd812dc374 (diff) | |
| download | rust-9f8d3d0bc9057ecc9de715a5cf65d97dc67da766.tar.gz rust-9f8d3d0bc9057ecc9de715a5cf65d97dc67da766.zip | |
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.
| -rw-r--r-- | src/librustdoc/html/static/js/settings.js | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js index 5e706e28492..f61673c9088 100644 --- a/src/librustdoc/html/static/js/settings.js +++ b/src/librustdoc/html/static/js/settings.js @@ -310,12 +310,21 @@ }); } + /** + * @param {MouseEvent} event + */ function settingsBlurHandler(event) { - if (!getHelpButton().contains(document.activeElement) && - !getHelpButton().contains(event.relatedTarget) && - !getSettingsButton().contains(document.activeElement) && - !getSettingsButton().contains(event.relatedTarget) - ) { + const helpBtn = getHelpButton(); + const settingsBtn = getSettingsButton(); + const helpUnfocused = helpBtn === null || + (!helpBtn.contains(document.activeElement) && + // @ts-expect-error + !helpBtn.contains(event.relatedTarget)); + const settingsUnfocused = settingsBtn === null || + (!settingsBtn.contains(document.activeElement) && + // @ts-expect-error + !settingsBtn.contains(event.relatedTarget)); + if (helpUnfocused && settingsUnfocused) { window.hidePopoverMenus(); } } |
