settings.js: begin typechecking migration
this also makes `changeSetting` more robust in case it somehow gets called before `main.js` has finished loading.
This commit is contained in:
parent
ae9173d7dd
commit
53ef53aed9
3 changed files with 19 additions and 7 deletions
|
@ -1101,7 +1101,6 @@ function preLoadCss(cssUrl) {
|
|||
});
|
||||
}());
|
||||
|
||||
// @ts-expect-error
|
||||
window.rustdoc_add_line_numbers_to_examples = () => {
|
||||
// @ts-expect-error
|
||||
function generateLine(nb) {
|
||||
|
@ -1123,7 +1122,6 @@ function preLoadCss(cssUrl) {
|
|||
});
|
||||
};
|
||||
|
||||
// @ts-expect-error
|
||||
window.rustdoc_remove_line_numbers_from_examples = () => {
|
||||
onEachLazy(
|
||||
document.querySelectorAll(".rustdoc:not(.src) :not(.scraped-example) > .example-wrap"),
|
||||
|
@ -1132,7 +1130,6 @@ function preLoadCss(cssUrl) {
|
|||
};
|
||||
|
||||
if (getSettingValue("line-numbers") === "true") {
|
||||
// @ts-expect-error
|
||||
window.rustdoc_add_line_numbers_to_examples();
|
||||
}
|
||||
|
||||
|
|
2
src/librustdoc/html/static/js/rustdoc.d.ts
vendored
2
src/librustdoc/html/static/js/rustdoc.d.ts
vendored
|
@ -78,6 +78,8 @@ declare global {
|
|||
pending_implementors?: rustdoc.Implementors,
|
||||
register_type_impls?: function(rustdoc.TypeImpls): void,
|
||||
pending_type_impls?: rustdoc.TypeImpls,
|
||||
rustdoc_add_line_numbers_to_examples?: function(),
|
||||
rustdoc_remove_line_numbers_from_examples?: function(),
|
||||
}
|
||||
interface HTMLElement {
|
||||
/** Used by the popover tooltip code. */
|
||||
|
|
|
@ -4,19 +4,26 @@
|
|||
/* global MAIN_ID, getVar, getSettingsButton, getHelpButton */
|
||||
|
||||
// Eventually fix this.
|
||||
// @ts-nocheck
|
||||
|
||||
"use strict";
|
||||
|
||||
(function() {
|
||||
const isSettingsPage = window.location.pathname.endsWith("/settings.html");
|
||||
|
||||
/**
|
||||
* @overload {"theme"|"preferred-dark-theme"|"preferred-light-theme"}
|
||||
* @param {string} settingName
|
||||
* @param {string} value
|
||||
* @returns
|
||||
* @param {string} settingName
|
||||
* @param {string|boolean} value
|
||||
*/
|
||||
function changeSetting(settingName, value) {
|
||||
if (settingName === "theme") {
|
||||
const useSystem = value === "system preference" ? "true" : "false";
|
||||
updateLocalStorage("use-system-theme", useSystem);
|
||||
}
|
||||
updateLocalStorage(settingName, value);
|
||||
updateLocalStorage(settingName, "" + value);
|
||||
|
||||
switch (settingName) {
|
||||
case "theme":
|
||||
|
@ -27,9 +34,15 @@
|
|||
break;
|
||||
case "line-numbers":
|
||||
if (value === true) {
|
||||
window.rustdoc_add_line_numbers_to_examples();
|
||||
const f = window.rustdoc_add_line_numbers_to_examples;
|
||||
if (f !== undefined) {
|
||||
f();
|
||||
}
|
||||
} else {
|
||||
window.rustdoc_remove_line_numbers_from_examples();
|
||||
const f = window.rustdoc_remove_line_numbers_from_examples;
|
||||
if (f !== undefined) {
|
||||
f();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "hide-sidebar":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue