Skip to content

Commit c4b994f

Browse files
committed
Pick themes on settings page, not every page
This hides the paintbrush icon on most pages by default, in preference for the settings on the settings page. When loading from a local file, and not in mobile view, continue to show the theme picker. That's because some browsers limit access to localStorage from file:/// URLs, so choosing a theme from settings.html doesn't take effect.
1 parent ad46af2 commit c4b994f

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/librustdoc/html/static/css/rustdoc.css

+6-11
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,12 @@ details.rustdoc-toggle[open] > summary.hideme::after {
17551755
padding-top: 0px;
17561756
}
17571757

1758+
/* Space is at a premium on mobile, so remove the theme-picker icon. */
1759+
#theme-picker {
1760+
display: none;
1761+
width: 0;
1762+
}
1763+
17581764
.rustdoc {
17591765
flex-direction: column;
17601766
}
@@ -1873,12 +1879,6 @@ details.rustdoc-toggle[open] > summary.hideme::after {
18731879
height: 100%;
18741880
}
18751881

1876-
nav.sub {
1877-
width: calc(100% - 32px);
1878-
margin-left: 32px;
1879-
margin-bottom: 10px;
1880-
}
1881-
18821882
.source nav:not(.sidebar).sub {
18831883
margin-left: 32px;
18841884
}
@@ -2075,11 +2075,6 @@ details.rustdoc-toggle[open] > summary.hideme::after {
20752075
border: 0;
20762076
}
20772077

2078-
#crate-search + .search-input {
2079-
width: calc(100% + 71px);
2080-
margin-left: -36px;
2081-
}
2082-
20832078
#theme-picker, #settings-menu {
20842079
padding: 5px;
20852080
width: 31px;

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

+5
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,15 @@ function hideThemeButtonState() {
129129

130130
// Set up the theme picker list.
131131
(function () {
132+
if (!document.location.href.startsWith("file:///")) {
133+
return;
134+
}
132135
var themeChoices = getThemesElement();
133136
var themePicker = getThemePickerElement();
134137
var availableThemes = getVar("themes").split(",");
135138

139+
removeClass(themeChoices.parentElement, "hidden");
140+
136141
function switchThemeButtonState() {
137142
if (themeChoices.style.display === "block") {
138143
hideThemeButtonState();

src/librustdoc/templates/page.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
{%- endif -%}
9797
</a> {#- -#}
9898
<nav class="sub"> {#- -#}
99-
<div class="theme-picker"> {#- -#}
99+
<div class="theme-picker hidden"> {#- -#}
100100
<button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"> {#- -#}
101101
<img width="18" height="18" alt="Pick another theme!" {# -#}
102102
src="{{static_root_path|safe}}brush{{page.resource_suffix}}.svg"> {#- -#}

0 commit comments

Comments
 (0)