Auto merge of #84325 - jsha:ephemeral-collapse, r=GuillaumeGomez

rustdoc: make expand/collapse all ephemeral

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.

This also moves the code for toggling display of trait implementations so that it's near the other toggling code.

Fixes #84318
This commit is contained in:
bors 2021-04-25 20:42:11 +00:00
commit 3709ae324c

View file

@ -916,7 +916,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;
@ -931,7 +930,6 @@ function hideThemeButtonState() {
});
}
} else {
updateLocalStorage("rustdoc-collapse", "true");
addClass(innerToggle, "will-expand");
onEachLazy(document.getElementsByTagName("details"), function(e) {
e.open = false;
@ -1086,40 +1084,18 @@ function hideThemeButtonState() {
}
}
function collapser(e, collapse) {
function collapseNonInherent(e) {
// inherent impl ids are like "impl" or impl-<number>'.
// they will never be hidden by default.
var n = e.parentElement;
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
// Automatically minimize all non-inherent impls
if (collapse || hasClass(n, "impl")) {
if (hasClass(n, "impl")) {
collapseDocs(e, "hide");
}
}
}
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);
}
@ -1178,6 +1154,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);
});
}
var blanket_list = document.getElementById("blanket-implementations-list");
if (blanket_list !== null) {
onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
collapseNonInherent(e);
});
}
var func = function(e) {
var next = e.nextElementSibling;
@ -1348,8 +1340,6 @@ function hideThemeButtonState() {
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
autoCollapse(getSettingValue("collapse") === "true");
var pageId = getPageId();
if (pageId !== null) {
expandSection(pageId);