Skip to content

Commit

Permalink
Rollup merge of #85169 - jsha:hoist-classes, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Add method-toggle to <details> for methods

The makes the code for handling "auto-hide" settings more consistent.

Demo at https://hoffman-andrews.com/rust/hoist-classes/std/string/struct.String.html

Fixes #84829
  • Loading branch information
RalfJung committed May 19, 2021
2 parents a1ac372 + 24480de commit 4217430
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
9 changes: 6 additions & 3 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<details class=\"rustdoc-toggle\" open><summary>");
let toggled = !doc_buffer.is_empty();
if toggled {
let method_toggle_class =
if item_type == ItemType::Method { " method-toggle" } else { "" };
write!(w, "<details class=\"rustdoc-toggle{}\" open><summary>", method_toggle_class);
}
match *item.kind {
clean::MethodItem(..) | clean::TyMethodItem(_) => {
Expand Down Expand Up @@ -1453,7 +1456,7 @@ fn render_impl(
}

w.push_buffer(info_buffer);
if !doc_buffer.is_empty() {
if toggled {
w.write_str("</summary>");
w.push_buffer(doc_buffer);
w.push_str("</details>");
Expand Down
16 changes: 4 additions & 12 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 4217430

Please sign in to comment.