Skip to content

Commit

Permalink
rustdoc: make expand/collapse all ephemeral
Browse files Browse the repository at this point in the history
The `[+]` in the upper right of a rustdoc page expands or collapses all
toggles on the page. That state is stored across page loads, but is used
inconsistently. This change explicitly stops storing or using the state.
  • Loading branch information
jsha committed Apr 19, 2021
1 parent 392ba2b commit 39b299f
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,6 @@ function hideThemeButtonState() {
return;
}
if (hasClass(innerToggle, "will-expand")) {
updateLocalStorage("rustdoc-collapse", "false");
removeClass(innerToggle, "will-expand");
onEachLazy(document.getElementsByTagName("details"), function(e) {
e.open = true;
Expand All @@ -920,7 +919,6 @@ function hideThemeButtonState() {
});
}
} else {
updateLocalStorage("rustdoc-collapse", "true");
addClass(innerToggle, "will-expand");
onEachLazy(document.getElementsByTagName("details"), function(e) {
e.open = false;
Expand Down Expand Up @@ -1075,7 +1073,7 @@ function hideThemeButtonState() {
}
}

function collapser(e, collapse) {
function collapseNonInherent(e, collapse) {
// inherent impl ids are like "impl" or impl-<number>'.
// they will never be hidden by default.
var n = e.parentElement;
Expand All @@ -1087,28 +1085,6 @@ function hideThemeButtonState() {
}
}

function autoCollapse(collapse) {
if (collapse) {
toggleAllDocs(true);
} else if (getSettingValue("auto-hide-trait-implementations") !== "false") {
var impl_list = document.getElementById("trait-implementations-list");

if (impl_list !== null) {
onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
collapser(e, collapse);
});
}

var blanket_list = document.getElementById("blanket-implementations-list");

if (blanket_list !== null) {
onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
collapser(e, collapse);
});
}
}
}

function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
Expand Down Expand Up @@ -1167,6 +1143,22 @@ function hideThemeButtonState() {
var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true";
var hideImplementors = getSettingValue("auto-collapse-implementors") !== "false";
var hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false";
var hideTraitImplementations =
getSettingValue("auto-hide-trait-implementations") !== "false";

var impl_list = document.getElementById("trait-implementations-list");
if (impl_list !== null) {
onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
collapseNonInherent(e, collapse);
});
}

var blanket_list = document.getElementById("blanket-implementations-list");
if (blanket_list !== null) {
onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
collapseNonInherent(e, collapse);
});
}

var func = function(e) {
var next = e.nextElementSibling;
Expand Down Expand Up @@ -1353,8 +1345,6 @@ function hideThemeButtonState() {
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);

autoCollapse(getSettingValue("collapse") === "true");

var pageId = getPageId();
if (pageId !== null) {
expandSection(pageId);
Expand Down

0 comments on commit 39b299f

Please sign in to comment.