Skip to content

Commit 3a1c8c3

Browse files
committed
rustdoc-search: put throbber at bottom of search results instead
1 parent 69a081a commit 3a1c8c3

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ summary.hideme,
339339
.scraped-example-list,
340340
.rustdoc-breadcrumbs,
341341
.search-switcher,
342+
.search-throbber,
342343
/* This selector is for the items listed in the "all items" page. */
343344
ul.all-items {
344345
font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
@@ -2006,6 +2007,57 @@ a.tooltip:hover::after {
20062007
color: transparent;
20072008
}
20082009

2010+
.search-throbber {
2011+
position: relative;
2012+
height: 34px;
2013+
}
2014+
2015+
.search-throbber::before,
2016+
.search-form.loading::before
2017+
{
2018+
width: 16px;
2019+
height: 16px;
2020+
border-radius: 16px;
2021+
background: radial-gradient(
2022+
var(--button-background-color) 0 50%,
2023+
transparent 50% 100%
2024+
), conic-gradient(
2025+
var(--code-highlight-kw-color) 0deg 30deg,
2026+
var(--code-highlight-prelude-color) 30deg 60deg,
2027+
var(--code-highlight-number-color) 90deg 120deg,
2028+
var(--code-highlight-lifetime-color ) 120deg 150deg,
2029+
var(--code-highlight-comment-color) 150deg 180deg,
2030+
var(--code-highlight-self-color) 180deg 210deg,
2031+
var(--code-highlight-attribute-color) 210deg 240deg,
2032+
var(--code-highlight-literal-color) 210deg 240deg,
2033+
var(--code-highlight-macro-color) 240deg 270deg,
2034+
var(--code-highlight-question-mark-color) 270deg 300deg,
2035+
var(--code-highlight-prelude-val-color) 300deg 330deg,
2036+
var(--code-highlight-doc-comment-color) 330deg 360deg
2037+
);
2038+
content: "";
2039+
position: absolute;
2040+
right: 9px;
2041+
top: 8px;
2042+
animation: rotating 1.25s linear infinite;
2043+
}
2044+
.search-throbber::after,
2045+
.search-form.loading::after
2046+
{
2047+
width: 18px;
2048+
height: 18px;
2049+
border-radius: 18px;
2050+
background: conic-gradient(
2051+
var(--button-background-color) 0deg 180deg,
2052+
transparent 270deg 360deg
2053+
);
2054+
content: "";
2055+
position: absolute;
2056+
right: 8px;
2057+
top: 8px;
2058+
animation: rotating 0.66s linear infinite;
2059+
}
2060+
20092061
#search .error code {
20102062
border-radius: 3px;
20112063
background-color: var(--search-error-code-background-color);

src/librustdoc/html/static/js/search.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4701,6 +4701,11 @@ async function addTab(results, query, display, finishedCallback, isTypeSearch) {
47014701
let output = document.createElement("ul");
47024702
output.className = "search-results " + extraClass;
47034703

4704+
const throbber = document.createElement("div");
4705+
throbber.className = "search-throbber";
4706+
throbber.innerHTML = "Loading...";
4707+
output.appendChild(throbber);
4708+
47044709
let count = 0;
47054710

47064711
/** @type {Promise<string|null>[]} */
@@ -4807,7 +4812,7 @@ ${obj.displayPath}<span class="${type}">${name}</span>\
48074812
}
48084813

48094814
link.appendChild(description);
4810-
output.appendChild(link);
4815+
output.insertBefore(link, throbber);
48114816

48124817
results.next().then(async nextResult => {
48134818
if (nextResult.value) {
@@ -4816,7 +4821,10 @@ ${obj.displayPath}<span class="${type}">${name}</span>\
48164821
await Promise.all(descList);
48174822
// need to make sure the element is shown before
48184823
// running this callback
4819-
yieldToBrowser().then(() => finishedCallback(count, output));
4824+
yieldToBrowser().then(() => {
4825+
finishedCallback(count, output);
4826+
throbber.remove();
4827+
});
48204828
}
48214829
});
48224830
};
@@ -5012,9 +5020,14 @@ async function showResults(docSearch, results, goToFirst, filterCrates) {
50125020
resultsElem.id = "results";
50135021

50145022
search.innerHTML = "";
5015-
for (const [tab, output] of tabs) {
5023+
for (const [tabNb, [tab, output]] of tabs.entries()) {
50165024
tabsElem.appendChild(tab);
5025+
const isCurrentTab = window.searchState.currentTab === tabNb;
50175026
const placeholder = document.createElement("div");
5027+
placeholder.className = isCurrentTab ?
5028+
"search-throbber search-results active" :
5029+
"search-throbber search-results";
5030+
placeholder.innerHTML = "Loading...";
50185031
output.then(output => {
50195032
if (placeholder.parentElement) {
50205033
placeholder.parentElement.replaceChild(output, placeholder);

0 commit comments

Comments
 (0)