Skip to content

Commit

Permalink
Auto merge of rust-lang#84325 - jsha:ephemeral-collapse, r=GuillaumeG…
Browse files Browse the repository at this point in the history
…omez

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 rust-lang#84318
  • Loading branch information
bors committed Apr 25, 2021
2 parents e7ed7e8 + 9fcfe5e commit 3709ae3
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -931,7 +930,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 @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1348,8 +1340,6 @@ function hideThemeButtonState() {

onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);

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

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

0 comments on commit 3709ae3

Please sign in to comment.