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

Commit a805f52

Browse files
committed
settings.js: make top-level code typecheck
With this, almost the entire file is fully typechecked, the only exception being the Element.contains(EventTarget) pattern that is used several times, those are annotated with @ts-expect-error
1 parent d2ff26b commit a805f52

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/librustdoc/html/static/js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Local js definitions:
22
/* global addClass, getSettingValue, hasClass, updateLocalStorage */
3-
/* global onEachLazy, removeClass, getVar */
3+
/* global onEachLazy, removeClass, getVar, nonnull */
44

55
"use strict";
66

src/librustdoc/html/static/js/rustdoc.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ declare global {
3030
currentCrate: string|null;
3131
/**
3232
* Hide popovers, tooltips, or the mobile sidebar.
33+
*
34+
* Pass `true` to reset focus for tooltip popovers.
3335
*/
3436
hideAllModals: function(boolean),
3537
/**

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Local js definitions:
22
/* global getSettingValue, updateLocalStorage, updateTheme */
33
/* global addClass, removeClass, onEach, onEachLazy */
4-
/* global MAIN_ID, getVar, getSettingsButton, getHelpButton */
5-
6-
// Eventually fix this.
4+
/* global MAIN_ID, getVar, getSettingsButton, getHelpButton, nonnull */
75

86
"use strict";
97

@@ -317,7 +315,7 @@
317315
}
318316

319317
/**
320-
* @param {MouseEvent} event
318+
* @param {FocusEvent} event
321319
*/
322320
function settingsBlurHandler(event) {
323321
const helpBtn = getHelpButton();
@@ -337,22 +335,26 @@
337335

338336
if (!isSettingsPage) {
339337
// We replace the existing "onclick" callback.
340-
const settingsButton = getSettingsButton();
341-
const settingsMenu = document.getElementById("settings");
338+
// These elements must exist, as (outside of the settings page)
339+
// `settings.js` is only loaded after the settings button is clicked.
340+
const settingsButton = nonnull(getSettingsButton());
341+
const settingsMenu = nonnull(document.getElementById("settings"));
342342
settingsButton.onclick = event => {
343+
// @ts-expect-error
343344
if (settingsMenu.contains(event.target)) {
344345
return;
345346
}
346347
event.preventDefault();
347348
const shouldDisplaySettings = settingsMenu.style.display === "none";
348349

349-
window.hideAllModals();
350+
window.hideAllModals(false);
350351
if (shouldDisplaySettings) {
351352
displaySettings();
352353
}
353354
};
354355
settingsButton.onblur = settingsBlurHandler;
355-
settingsButton.querySelector("a").onblur = settingsBlurHandler;
356+
// the settings button should always have a link in it
357+
nonnull(settingsButton.querySelector("a")).onblur = settingsBlurHandler;
356358
onEachLazy(settingsMenu.querySelectorAll("input"), el => {
357359
el.onblur = settingsBlurHandler;
358360
});

0 commit comments

Comments
 (0)