rustdoc: avoid calling document.write after the page loads

This commit is contained in:
Michael Howell 2023-09-14 12:56:15 -07:00
parent 7e86fd61e8
commit ab41e2b6dc

View File

@ -131,8 +131,18 @@ function switchTheme(newThemeName, saveTheme) {
const newHref = getVar("root-path") + newThemeName + const newHref = getVar("root-path") + newThemeName +
getVar("resource-suffix") + ".css"; getVar("resource-suffix") + ".css";
if (!window.currentTheme) { if (!window.currentTheme) {
document.write(`<link rel="stylesheet" id="themeStyle" href="${newHref}">`); // If we're in the middle of loading, document.write blocks
window.currentTheme = document.getElementById("themeStyle"); // rendering, but if we are done, it would blank the page.
if (document.readyState === "loading") {
document.write(`<link rel="stylesheet" id="themeStyle" href="${newHref}">`);
window.currentTheme = document.getElementById("themeStyle");
} else {
window.currentTheme = document.createElement("link");
window.currentTheme.rel = "stylesheet";
window.currentTheme.id = "themeStyle";
window.currentTheme.href = newHref;
document.documentElement.appendChild(window.currentTheme);
}
} else if (newHref !== window.currentTheme.href) { } else if (newHref !== window.currentTheme.href) {
window.currentTheme.href = newHref; window.currentTheme.href = newHref;
} }