From 24480ded58c9867439cfabba4198e1877c1fd166 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Mon, 10 May 2021 16:41:41 -0700 Subject: [PATCH] Add method-toggle to
for methods. The makes the code for handling "auto-hide" settings more consistent. --- src/librustdoc/html/render/mod.rs | 9 ++++++--- src/librustdoc/html/static/main.js | 16 ++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index a288b43722ad4..318e1b44f8683 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1352,8 +1352,11 @@ fn render_impl( } let w = if short_documented && trait_.is_some() { interesting } else { boring }; - if !doc_buffer.is_empty() { - w.write_str("
"); + let toggled = !doc_buffer.is_empty(); + if toggled { + let method_toggle_class = + if item_type == ItemType::Method { " method-toggle" } else { "" }; + write!(w, "
", method_toggle_class); } match *item.kind { clean::MethodItem(..) | clean::TyMethodItem(_) => { @@ -1453,7 +1456,7 @@ fn render_impl( } w.push_buffer(info_buffer); - if !doc_buffer.is_empty() { + if toggled { w.write_str(""); w.push_buffer(doc_buffer); w.push_str("
"); diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 307ce9ac3752c..83e6a529b0aa4 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -924,24 +924,16 @@ function hideThemeButtonState() { }); } - if (hideMethodDocs) { - onEachLazy(document.getElementsByClassName("method"), function(e) { - var toggle = e.parentNode; - if (toggle) { - toggle = toggle.parentNode; - } - if (toggle && toggle.tagName === "DETAILS") { - toggle.open = false; - } - }); - } - onEachLazy(document.getElementsByTagName("details"), function (e) { var showLargeItem = !hideLargeItemContents && hasClass(e, "type-contents-toggle"); var showImplementor = !hideImplementors && hasClass(e, "implementors-toggle"); if (showLargeItem || showImplementor) { e.open = true; } + if (hideMethodDocs && hasClass(e, "method-toggle")) { + e.open = false; + } + }); var currentType = document.getElementsByClassName("type-decl")[0];