diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index bea0e75832c33..4b0903019312e 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -51,19 +51,20 @@ impl Print for &'_ str { crate struct Buffer { for_html: bool, buffer: String, + crate label_id_count: usize, } impl Buffer { crate fn empty_from(v: &Buffer) -> Buffer { - Buffer { for_html: v.for_html, buffer: String::new() } + Buffer { for_html: v.for_html, buffer: String::new(), label_id_count: 0 } } crate fn html() -> Buffer { - Buffer { for_html: true, buffer: String::new() } + Buffer { for_html: true, buffer: String::new(), label_id_count: 0 } } crate fn new() -> Buffer { - Buffer { for_html: false, buffer: String::new() } + Buffer { for_html: false, buffer: String::new(), label_id_count: 0 } } crate fn is_empty(&self) -> bool { diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 66c47f14655ba..70f7896ccb749 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -626,9 +626,14 @@ fn render_markdown( is_hidden: bool, ) { let mut ids = cx.id_map.borrow_mut(); + let label_id_count = w.label_id_count; + w.label_id_count += 1; write!( w, - "
");
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl, cx);
w.write_str("
");
@@ -1538,10 +1543,11 @@ fn render_impl(
write_srclink(cx, item, w);
w.write_str("", id, item_type, extra_class);
+ write!(w, "", id, item_type, extra_class);
assoc_type(
w,
item,
@@ -1552,10 +1558,11 @@ fn render_impl(
cx.cache(),
);
w.write_str("
");
+ true
}
clean::AssocConstItem(ref ty, ref default) => {
let id = cx.derive_id(format!("{}.{}", item_type, name));
- write!(w, "", id, item_type, extra_class);
+ write!(w, "", id, item_type, extra_class);
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id), "", cx);
w.write_str("
");
render_stability_since_raw(
@@ -1567,16 +1574,18 @@ fn render_impl(
);
write_srclink(cx, item, w);
w.write_str("
");
+ true
}
clean::AssocTypeItem(ref bounds, ref default) => {
let id = cx.derive_id(format!("{}.{}", item_type, name));
- write!(w, "", id, item_type, extra_class);
+ write!(w, "", id, item_type, extra_class);
assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id), "", cx.cache());
w.write_str("
");
+ true
}
clean::StrippedItem(..) => return,
_ => panic!("can't make docs for trait item with name {:?}", item.name),
- }
+ };
if render_method_item {
if !is_default_item {
@@ -1614,6 +1623,9 @@ fn render_impl(
document_short(w, item, cx, link, "", is_hidden, Some(parent), show_def_docs);
}
}
+ if need_close {
+ w.write_str("");
+ }
}
w.write_str("");
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index e7b522093c74d..4491f8317a0fa 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -2249,9 +2249,14 @@ function defocusSearchBar() {
});
innerToggle.title = "collapse all docs";
if (fromAutoCollapse !== true) {
+ // Old toggle handling.
onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
collapseDocs(e, "show");
});
+ // New toggle handling.
+ onEachLazy(document.getElementsByClassName("toggle"), function(e) {
+ e.checked = true;
+ });
}
} else {
updateLocalStorage("rustdoc-collapse", "true");
@@ -2270,6 +2275,7 @@ function defocusSearchBar() {
});
innerToggle.title = "expand all docs";
if (fromAutoCollapse !== true) {
+ // Old toggle handling.
onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
var parent = e.parentNode;
var superParent = null;
@@ -2282,6 +2288,19 @@ function defocusSearchBar() {
collapseDocs(e, "hide");
}
});
+ // New toggle handling.
+ onEachLazy(document.getElementsByClassName("toggle"), function(e) {
+ var parent = e.parentNode;
+ var superParent = null;
+
+ if (parent) {
+ superParent = parent.parentNode;
+ }
+ if (!parent || !superParent || superParent.id !== "main" ||
+ hasClass(parent, "impl") === false) {
+ e.checked = false;
+ }
+ });
}
}
}
@@ -2460,7 +2479,7 @@ function defocusSearchBar() {
span.style.display = "none";
}
if (!otherMessage) {
- span.innerHTML = " Expand description";
+ return null;
} else {
span.innerHTML = otherMessage;
}
@@ -2506,11 +2525,9 @@ function defocusSearchBar() {
if (!next) {
return;
}
- if (hasClass(next, "docblock")) {
- var newToggle = toggle.cloneNode(true);
- insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
+ if (hasClass(next, "toggle")) {
if (hideMethodDocs === true && hasClass(e, "method") === true) {
- collapseDocs(newToggle, "hide");
+ next.checked = true;
}
}
};
@@ -2672,14 +2689,15 @@ function defocusSearchBar() {
extraClass = "marg-left";
}
- e.parentNode.insertBefore(
- createToggle(
+ var t = createToggle(
toggle,
otherMessage,
fontSize,
extraClass,
- hasClass(e, "type-decl") === false || showItemDeclarations === true),
- e);
+ hasClass(e, "type-decl") === false || showItemDeclarations === true);
+ if (t) {
+ e.parentNode.insertBefore(t, e);
+ }
if (hasClass(e, "type-decl") === true && showItemDeclarations === true) {
collapseDocs(e.previousSibling.childNodes[0], "toggle");
}
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css
index 4f287cde73b1b..a75d35678984d 100644
--- a/src/librustdoc/html/static/rustdoc.css
+++ b/src/librustdoc/html/static/rustdoc.css
@@ -80,6 +80,10 @@ html {
}
}
+div {
+ position: relative;
+}
+
/* General structure and fonts */
body {
@@ -1768,3 +1772,42 @@ div.name.expand::before {
.type-decl > pre > .docblock.attributes {
margin-left: 4em;
}
+
+input.toggle {
+ display: none;
+}
+input.toggle + label {
+ position: absolute;
+ top: 0;
+ font-family: "Fira Sans", Arial, sans-serif;
+ font-weight: 300;
+ cursor: pointer;
+}
+input.toggle + label:before {
+ content: "[+]";
+}
+input.toggle:checked + label:before {
+ content: "[-]";
+}
+input.toggle:not(:checked) + label + .docblock {
+ display: none;
+}
+h4 + input.toggle + label {
+ font-size: 0.8em;
+ top: 5px;
+}
+.type-decl + input.toggle + label {
+ top: initial;
+}
+.type-decl + input.toggle:not(:checked) + label {
+ margin-bottom: .6em;
+ height: 25px;
+ position: initial;
+}
+.type-decl + input.toggle:not(:checked) + label:before {
+ content: "[+]";
+}
+.type-decl + input.toggle:not(:checked) + label:after {
+ content: "Expand description";
+ margin-left: 6px;
+}
\ No newline at end of file
diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css
index 88ac3252bb4b2..f545993051676 100644
--- a/src/librustdoc/html/static/themes/dark.css
+++ b/src/librustdoc/html/static/themes/dark.css
@@ -186,7 +186,7 @@ a.test-arrow {
color: #dedede;
}
-.collapse-toggle {
+.collapse-toggle, input.toggle + label {
color: #999;
}