From 39b299f8a46fd3c2467a61ce7a5b9829ce03fc7d Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sun, 18 Apr 2021 14:33:33 -0700 Subject: [PATCH 1/2] 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. --- src/librustdoc/html/static/main.js | 44 ++++++++++++------------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index f017fd846b1..76d95dc9d9f 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -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; @@ -920,7 +919,6 @@ function hideThemeButtonState() { }); } } else { - updateLocalStorage("rustdoc-collapse", "true"); addClass(innerToggle, "will-expand"); onEachLazy(document.getElementsByTagName("details"), function(e) { e.open = false; @@ -1075,7 +1073,7 @@ function hideThemeButtonState() { } } - function collapser(e, collapse) { + function collapseNonInherent(e, collapse) { // inherent impl ids are like "impl" or impl-'. // they will never be hidden by default. var n = e.parentElement; @@ -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); } @@ -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; @@ -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); From 9fcfe5e0c7aaf8e6f0bdcdd36157e08dd67c8b42 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Mon, 19 Apr 2021 12:07:55 -0700 Subject: [PATCH 2/2] Remove collapse param from collapseNonInherent. --- src/librustdoc/html/static/main.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 76d95dc9d9f..7f6d64e4746 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1073,13 +1073,13 @@ function hideThemeButtonState() { } } - function collapseNonInherent(e, collapse) { + function collapseNonInherent(e) { // inherent impl ids are like "impl" or impl-'. // 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"); } } @@ -1149,14 +1149,14 @@ function hideThemeButtonState() { var impl_list = document.getElementById("trait-implementations-list"); if (impl_list !== null) { onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) { - collapseNonInherent(e, collapse); + collapseNonInherent(e); }); } var blanket_list = document.getElementById("blanket-implementations-list"); if (blanket_list !== null) { onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) { - collapseNonInherent(e, collapse); + collapseNonInherent(e); }); }