1
Fork 0

Rollup merge of #84320 - jsha:details-implementors, r=Manishearth,Nemo157,GuillaumeGomez

Use details tag for trait implementors.

Part of #83332 and following on from #83337 and #83355.

This removes one category of JS-generated toggles (implementors), and replaces them with a `<details>` tag. This simplifies the JS, and fixes some bugs where things that were supposed to be hidden by the toggle were not hidden. Compare https://hoffman-andrews.com/rust/details-implementors/std/io/trait.Read.html#impl-Read vs https://doc.rust-lang.org/nightly/std/io/trait.Read.html#implementors.

This introduces a `left: -23px` to put the toggle in the correct place, matching the current style for `.collapse-toggle`.

It's worth noting this introduces a slight behavior change: since the entire line is now a `<summary>`, any part of the line is clickable. So for instance, in `impl Read for File`, clicking `impl` or `for` will collapse / expand the docs. Clicking `Read` or `File` still links to the appropriate documentation as before.
This commit is contained in:
Yuki Okushi 2021-04-24 12:17:03 +09:00 committed by GitHub
commit b4544698d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 68 additions and 66 deletions

View file

@ -1207,31 +1207,18 @@ function hideThemeButtonState() {
if (!next) {
return;
}
if (hasClass(e, "impl") &&
(next.getElementsByClassName("method").length > 0 ||
next.getElementsByClassName("associatedconstant").length > 0)) {
var newToggle = toggle.cloneNode(true);
insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
// In case the option "auto-collapse implementors" is not set to false, we collapse
// all implementors.
if (hideImplementors === true && e.parentNode.id === "implementors-list") {
collapseDocs(newToggle, "hide");
}
}
};
onEachLazy(document.getElementsByClassName("method"), func);
onEachLazy(document.getElementsByClassName("associatedconstant"), func);
onEachLazy(document.getElementsByClassName("impl"), funcImpl);
var impl_call = function() {};
// Large items are hidden by default in the HTML. If the setting overrides that, show 'em.
if (!hideLargeItemContents) {
onEachLazy(document.getElementsByTagName("details"), function (e) {
if (hasClass(e, "type-contents-toggle")) {
e.open = true;
}
});
}
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 === true) {
impl_call = function(e, newToggle) {
if (e.id.match(/^impl(?:-\d+)?$/) === null) {