Skip to content

Commit 9f54910

Browse files
committed
settings.js: add elemContainsTarget utility function
this allows us to eliminate the last 3 @ts-expect-error in this file.
1 parent 8a34129 commit 9f54910

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

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

+15-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
(function() {
99
const isSettingsPage = window.location.pathname.endsWith("/settings.html");
1010

11+
/**
12+
* @param {Element} elem
13+
* @param {EventTarget|null} target
14+
*/
15+
function elemContainsTarget(elem, target) {
16+
if (target instanceof Node) {
17+
return elem.contains(target);
18+
} else {
19+
return false;
20+
}
21+
}
22+
1123
/**
1224
* @overload {"theme"|"preferred-dark-theme"|"preferred-light-theme"}
1325
* @param {string} settingName
@@ -322,12 +334,10 @@
322334
const settingsBtn = getSettingsButton();
323335
const helpUnfocused = helpBtn === null ||
324336
(!helpBtn.contains(document.activeElement) &&
325-
// @ts-expect-error
326-
!helpBtn.contains(event.relatedTarget));
337+
!elemContainsTarget(helpBtn, event.relatedTarget));
327338
const settingsUnfocused = settingsBtn === null ||
328339
(!settingsBtn.contains(document.activeElement) &&
329-
// @ts-expect-error
330-
!settingsBtn.contains(event.relatedTarget));
340+
!elemContainsTarget(settingsBtn, event.relatedTarget));
331341
if (helpUnfocused && settingsUnfocused) {
332342
window.hidePopoverMenus();
333343
}
@@ -340,8 +350,7 @@
340350
const settingsButton = nonnull(getSettingsButton());
341351
const settingsMenu = nonnull(document.getElementById("settings"));
342352
settingsButton.onclick = event => {
343-
// @ts-expect-error
344-
if (settingsMenu.contains(event.target)) {
353+
if (elemContainsTarget(settingsMenu, event.target)) {
345354
return;
346355
}
347356
event.preventDefault();

0 commit comments

Comments
 (0)