take into account the system theme
This commit is contained in:
parent
7858dc237d
commit
c076d30ce4
2 changed files with 28 additions and 3 deletions
|
@ -54,6 +54,21 @@
|
|||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* This part handles the "default" theme being used depending on the system one. */
|
||||
html {
|
||||
content: "";
|
||||
}
|
||||
@media (prefers-color-scheme: light) {
|
||||
html {
|
||||
content: "light";
|
||||
}
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
html {
|
||||
content: "dark";
|
||||
}
|
||||
}
|
||||
|
||||
/* General structure and fonts */
|
||||
|
||||
body {
|
||||
|
|
|
@ -86,7 +86,7 @@ function getCurrentValue(name) {
|
|||
return null;
|
||||
}
|
||||
|
||||
function switchTheme(styleElem, mainStyleElem, newTheme) {
|
||||
function switchTheme(styleElem, mainStyleElem, newTheme, skipStorage) {
|
||||
var fullBasicCss = "rustdoc" + resourcesSuffix + ".css";
|
||||
var fullNewTheme = newTheme + resourcesSuffix + ".css";
|
||||
var newHref = mainStyleElem.href.replace(fullBasicCss, fullNewTheme);
|
||||
|
@ -109,8 +109,18 @@ function switchTheme(styleElem, mainStyleElem, newTheme) {
|
|||
});
|
||||
if (found === true) {
|
||||
styleElem.href = newHref;
|
||||
updateLocalStorage("rustdoc-theme", newTheme);
|
||||
// If this new value comes from a system setting or from the previously saved theme, no
|
||||
// need to save it.
|
||||
if (skipStorage !== true) {
|
||||
updateLocalStorage("rustdoc-theme", newTheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switchTheme(currentTheme, mainTheme, getCurrentValue("rustdoc-theme") || "light");
|
||||
function getSystemValue() {
|
||||
return getComputedStyle(document.documentElement).getPropertyValue('content');
|
||||
}
|
||||
|
||||
switchTheme(currentTheme, mainTheme,
|
||||
getCurrentValue("rustdoc-theme") || getSystemValue() || "light",
|
||||
true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue