Skip to content

Commit 4217430

Browse files
authored
Rollup merge of rust-lang#85169 - jsha:hoist-classes, r=GuillaumeGomez
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 rust-lang#84829
2 parents a1ac372 + 24480de commit 4217430

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

src/librustdoc/html/render/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,11 @@ fn render_impl(
13521352
}
13531353
let w = if short_documented && trait_.is_some() { interesting } else { boring };
13541354

1355-
if !doc_buffer.is_empty() {
1356-
w.write_str("<details class=\"rustdoc-toggle\" open><summary>");
1355+
let toggled = !doc_buffer.is_empty();
1356+
if toggled {
1357+
let method_toggle_class =
1358+
if item_type == ItemType::Method { " method-toggle" } else { "" };
1359+
write!(w, "<details class=\"rustdoc-toggle{}\" open><summary>", method_toggle_class);
13571360
}
13581361
match *item.kind {
13591362
clean::MethodItem(..) | clean::TyMethodItem(_) => {
@@ -1453,7 +1456,7 @@ fn render_impl(
14531456
}
14541457

14551458
w.push_buffer(info_buffer);
1456-
if !doc_buffer.is_empty() {
1459+
if toggled {
14571460
w.write_str("</summary>");
14581461
w.push_buffer(doc_buffer);
14591462
w.push_str("</details>");

src/librustdoc/html/static/main.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -924,24 +924,16 @@ function hideThemeButtonState() {
924924
});
925925
}
926926

927-
if (hideMethodDocs) {
928-
onEachLazy(document.getElementsByClassName("method"), function(e) {
929-
var toggle = e.parentNode;
930-
if (toggle) {
931-
toggle = toggle.parentNode;
932-
}
933-
if (toggle && toggle.tagName === "DETAILS") {
934-
toggle.open = false;
935-
}
936-
});
937-
}
938-
939927
onEachLazy(document.getElementsByTagName("details"), function (e) {
940928
var showLargeItem = !hideLargeItemContents && hasClass(e, "type-contents-toggle");
941929
var showImplementor = !hideImplementors && hasClass(e, "implementors-toggle");
942930
if (showLargeItem || showImplementor) {
943931
e.open = true;
944932
}
933+
if (hideMethodDocs && hasClass(e, "method-toggle")) {
934+
e.open = false;
935+
}
936+
945937
});
946938

947939
var currentType = document.getElementsByClassName("type-decl")[0];

0 commit comments

Comments
 (0)