Rollup merge of #84321 - Swatinem:subvariant-details, r=GuillaumeGomez
rustdoc: Convert sub-variant toggle to HTML Instead of creating a JS toggle, this injects details/summary for sub-variants of enums. This also fixes the CSS so that the toggle button does not jump when expanding/collapsing. Takes inspiration from #83337 and should be considered part of #83332. Not quite sure if the `.sub-variant` selectors could be further simplified? AFAICS it is only used in that place, and that does not seem to allow any recursion.
This commit is contained in:
commit
d05e28df15
5 changed files with 26 additions and 8 deletions
|
@ -455,6 +455,15 @@ function hideThemeButtonState() {
|
|||
handleHashes(ev);
|
||||
}
|
||||
|
||||
function openParentDetails(elem) {
|
||||
while (elem) {
|
||||
if (elem.tagName === "DETAILS") {
|
||||
elem.open = true;
|
||||
}
|
||||
elem = elem.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
function expandSection(id) {
|
||||
var elem = document.getElementById(id);
|
||||
if (elem && isHidden(elem)) {
|
||||
|
@ -469,6 +478,8 @@ function hideThemeButtonState() {
|
|||
// The element is not visible, we need to make it appear!
|
||||
collapseDocs(collapses[0], "show");
|
||||
}
|
||||
// Open all ancestor <details> to make this element visible.
|
||||
openParentDetails(h3.parentNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1009,7 +1020,7 @@ function hideThemeButtonState() {
|
|||
if (hasClass(relatedDoc, "item-info")) {
|
||||
relatedDoc = relatedDoc.nextElementSibling;
|
||||
}
|
||||
if (hasClass(relatedDoc, "docblock") || hasClass(relatedDoc, "sub-variant")) {
|
||||
if (hasClass(relatedDoc, "docblock")) {
|
||||
if (mode === "toggle") {
|
||||
if (hasClass(relatedDoc, "hidden-by-usual-hider")) {
|
||||
action = "show";
|
||||
|
@ -1318,8 +1329,6 @@ function hideThemeButtonState() {
|
|||
if (hasClass(e, "type-decl")) {
|
||||
// We do something special for these
|
||||
return;
|
||||
} else if (hasClass(e, "sub-variant")) {
|
||||
otherMessage = " Show fields";
|
||||
} else if (hasClass(e, "non-exhaustive")) {
|
||||
otherMessage = " This ";
|
||||
if (hasClass(e, "non-exhaustive-struct")) {
|
||||
|
@ -1351,7 +1360,6 @@ function hideThemeButtonState() {
|
|||
}
|
||||
|
||||
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
|
||||
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
|
||||
|
||||
autoCollapse(getSettingValue("collapse") === "true");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue