Skip to content

Commit

Permalink
Pick themes on settings page, not every page
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jsha committed Jan 15, 2022
1 parent ad46af2 commit c4b994f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
17 changes: 6 additions & 11 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,12 @@ details.rustdoc-toggle[open] > summary.hideme::after {
padding-top: 0px;
}

/* Space is at a premium on mobile, so remove the theme-picker icon. */
#theme-picker {
display: none;
width: 0;
}

.rustdoc {
flex-direction: column;
}
Expand Down Expand Up @@ -1873,12 +1879,6 @@ details.rustdoc-toggle[open] > summary.hideme::after {
height: 100%;
}

nav.sub {
width: calc(100% - 32px);
margin-left: 32px;
margin-bottom: 10px;
}

.source nav:not(.sidebar).sub {
margin-left: 32px;
}
Expand Down Expand Up @@ -2075,11 +2075,6 @@ details.rustdoc-toggle[open] > summary.hideme::after {
border: 0;
}

#crate-search + .search-input {
width: calc(100% + 71px);
margin-left: -36px;
}

#theme-picker, #settings-menu {
padding: 5px;
width: 31px;
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,15 @@ function hideThemeButtonState() {

// Set up the theme picker list.
(function () {
if (!document.location.href.startsWith("file:///")) {
return;
}
var themeChoices = getThemesElement();
var themePicker = getThemePickerElement();
var availableThemes = getVar("themes").split(",");

removeClass(themeChoices.parentElement, "hidden");

function switchThemeButtonState() {
if (themeChoices.style.display === "block") {
hideThemeButtonState();
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
{%- endif -%}
</a> {#- -#}
<nav class="sub"> {#- -#}
<div class="theme-picker"> {#- -#}
<div class="theme-picker hidden"> {#- -#}
<button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"> {#- -#}
<img width="18" height="18" alt="Pick another theme!" {# -#}
src="{{static_root_path|safe}}brush{{page.resource_suffix}}.svg"> {#- -#}
Expand Down

0 comments on commit c4b994f

Please sign in to comment.