Skip to content

Commit

Permalink
Rustdoc style cleanups
Browse files Browse the repository at this point in the history
 - Make "since" version numbers grey again (regressed in rust-lang#92602).
 - Remove unneeded selectors for when crate filter dropdown is a
   sibling of search-input.
 - Crate filter dropdown doesn't need to be 100% width on mobile.
 - Only build crate filter dropdown when there is more than one crate.
 - Remove unused addCrateDropdown.
  • Loading branch information
jsha committed Jan 17, 2022
1 parent ee5d8d3 commit 43b9268
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 46 deletions.
11 changes: 0 additions & 11 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -934,11 +934,6 @@ h2.small-section-header > .anchor {
width: 100%;
}

#crate-search + .search-input {
border-radius: 0 1px 1px 0;
width: calc(100% - 32px);
}

.search-input:focus {
border-radius: 2px;
border: 0;
Expand Down Expand Up @@ -2070,16 +2065,10 @@ details.rustdoc-toggle[open] > summary.hideme::after {
}

#crate-search {
width: 100%;
border-radius: 4px;
border: 0;
}

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

#theme-picker, #settings-menu {
padding: 5px;
width: 31px;
Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/static/css/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ details.undocumented > summary::before {
border-color: #5c6773;
}

.since {
.rightside,
.out-of-band {
color: grey;
}

Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/static/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ details.undocumented > summary::before {
background: rgba(0,0,0,0);
}

.since {
.rightside,
.out-of-band {
color: grey;
}

Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/html/static/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ details.undocumented > summary::before {
border-color: #bfbfbf;
}

.rightside,
.out-of-band {
color: grey;
}

.result-name .primitive > i, .result-name .keyword > i {
color: black;
}
Expand Down
27 changes: 0 additions & 27 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,6 @@ function hideThemeButtonState() {
loadSearch();
}

// `crates{version}.js` should always be loaded before this script, so we can use it
// safely.
searchState.addCrateDropdown(window.ALL_CRATES);
var params = searchState.getQueryStringParams();
if (params.search !== undefined) {
var search = searchState.outputElement();
Expand All @@ -295,30 +292,6 @@ function hideThemeButtonState() {
loadSearch();
}
},
addCrateDropdown: function(crates) {
var elem = document.getElementById("crate-search");

if (!elem) {
return;
}
var savedCrate = getSettingValue("saved-filter-crate");
for (var i = 0, len = crates.length; i < len; ++i) {
var option = document.createElement("option");
option.value = crates[i];
option.innerText = crates[i];
elem.appendChild(option);
// Set the crate filter from saved storage, if the current page has the saved crate
// filter.
//
// If not, ignore the crate filter -- we want to support filtering for crates on
// sites like doc.rust-lang.org where the crates may differ from page to page while
// on the
// same domain.
if (crates[i] === savedCrate) {
elem.value = savedCrate;
}
}
},
};

function getPageId() {
Expand Down
18 changes: 12 additions & 6 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -1126,15 +1126,18 @@ window.initSearch = function(rawSearchIndex) {
}
}

let crates = `<select id="crate-search"><option value="All crates">All crates</option>`;
for (let c of window.ALL_CRATES) {
crates += `<option value="${c}" ${c == filterCrates && "selected"}>${c}</option>`;
let crates = "";
if (window.ALL_CRATES.length > 1) {
crates = ` in <select id="crate-search"><option value="All crates">All crates</option>`;
for (let c of window.ALL_CRATES) {
crates += `<option value="${c}" ${c == filterCrates && "selected"}>${c}</option>`;
}
crates += `</select>`;
}
crates += `</select>`;
var output = `<div id="search-settings">
<h1 class="search-results-title">Results for ${escape(query.query)} ` +
(query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
` in ${crates} ` +
crates +
`</div><div id="titles">` +
makeTabHeader(0, "In Names", ret_others[1]) +
makeTabHeader(1, "In Parameters", ret_in_args[1]) +
Expand All @@ -1148,7 +1151,10 @@ window.initSearch = function(rawSearchIndex) {
resultsElem.appendChild(ret_returned[0]);

search.innerHTML = output;
document.getElementById("crate-search").addEventListener("input", updateCrate);
let crateSearch = document.getElementById("crate-search");
if (crateSearch) {
crateSearch.addEventListener("input", updateCrate);
}
search.appendChild(resultsElem);
// Reset focused elements.
searchState.focusedByTab = [null, null, null];
Expand Down

0 comments on commit 43b9268

Please sign in to comment.