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.
This commit is contained in:
parent
0cc00c48d2
commit
9f8eeca3bf
4 changed files with 19 additions and 7 deletions
|
@ -934,6 +934,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
|
|
||||||
use crate::clean::Variant;
|
use crate::clean::Variant;
|
||||||
if let clean::VariantItem(Variant::Struct(ref s)) = *variant.kind {
|
if let clean::VariantItem(Variant::Struct(ref s)) = *variant.kind {
|
||||||
|
toggle_open(w, "fields");
|
||||||
let variant_id = cx.derive_id(format!(
|
let variant_id = cx.derive_id(format!(
|
||||||
"{}.{}.fields",
|
"{}.{}.fields",
|
||||||
ItemType::Variant,
|
ItemType::Variant,
|
||||||
|
@ -967,6 +968,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.write_str("</div></div>");
|
w.write_str("</div></div>");
|
||||||
|
toggle_close(w);
|
||||||
}
|
}
|
||||||
render_stability_since(w, variant, it, cx.tcx());
|
render_stability_since(w, variant, it, cx.tcx());
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,6 +428,15 @@ function hideThemeButtonState() {
|
||||||
handleHashes(ev);
|
handleHashes(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function openParentDetails(elem) {
|
||||||
|
while (elem) {
|
||||||
|
if (elem.tagName === "DETAILS") {
|
||||||
|
elem.open = true;
|
||||||
|
}
|
||||||
|
elem = elem.parentNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function expandSection(id) {
|
function expandSection(id) {
|
||||||
var elem = document.getElementById(id);
|
var elem = document.getElementById(id);
|
||||||
if (elem && isHidden(elem)) {
|
if (elem && isHidden(elem)) {
|
||||||
|
@ -442,6 +451,8 @@ function hideThemeButtonState() {
|
||||||
// The element is not visible, we need to make it appear!
|
// The element is not visible, we need to make it appear!
|
||||||
collapseDocs(collapses[0], "show");
|
collapseDocs(collapses[0], "show");
|
||||||
}
|
}
|
||||||
|
// In case this is a sub-variant, toggle the <details> open.
|
||||||
|
openParentDetails(h3.parentNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2418,7 +2429,7 @@ function hideThemeButtonState() {
|
||||||
if (hasClass(relatedDoc, "item-info")) {
|
if (hasClass(relatedDoc, "item-info")) {
|
||||||
relatedDoc = relatedDoc.nextElementSibling;
|
relatedDoc = relatedDoc.nextElementSibling;
|
||||||
}
|
}
|
||||||
if (hasClass(relatedDoc, "docblock") || hasClass(relatedDoc, "sub-variant")) {
|
if (hasClass(relatedDoc, "docblock")) {
|
||||||
if (mode === "toggle") {
|
if (mode === "toggle") {
|
||||||
if (hasClass(relatedDoc, "hidden-by-usual-hider")) {
|
if (hasClass(relatedDoc, "hidden-by-usual-hider")) {
|
||||||
action = "show";
|
action = "show";
|
||||||
|
@ -2727,8 +2738,6 @@ function hideThemeButtonState() {
|
||||||
if (hasClass(e, "type-decl")) {
|
if (hasClass(e, "type-decl")) {
|
||||||
// We do something special for these
|
// We do something special for these
|
||||||
return;
|
return;
|
||||||
} else if (hasClass(e, "sub-variant")) {
|
|
||||||
otherMessage = " Show fields";
|
|
||||||
} else if (hasClass(e, "non-exhaustive")) {
|
} else if (hasClass(e, "non-exhaustive")) {
|
||||||
otherMessage = " This ";
|
otherMessage = " This ";
|
||||||
if (hasClass(e, "non-exhaustive-struct")) {
|
if (hasClass(e, "non-exhaustive-struct")) {
|
||||||
|
@ -2760,7 +2769,6 @@ function hideThemeButtonState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
|
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
|
||||||
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
|
|
||||||
|
|
||||||
autoCollapse(getSettingValue("collapse") === "true");
|
autoCollapse(getSettingValue("collapse") === "true");
|
||||||
|
|
||||||
|
|
|
@ -1031,10 +1031,11 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
|
||||||
}
|
}
|
||||||
|
|
||||||
.sub-variant, .sub-variant > h3 {
|
.sub-variant, .sub-variant > h3 {
|
||||||
margin-top: 1px !important;
|
margin-top: 0px !important;
|
||||||
|
padding-top: 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#main > .sub-variant > h3 {
|
#main > details > .sub-variant > h3 {
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
margin-left: 25px;
|
margin-left: 25px;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
|
|
|
@ -62,7 +62,8 @@ pub struct PrivStruct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @has 'item_hide_threshold/enum.Enum.html'
|
// @has 'item_hide_threshold/enum.Enum.html'
|
||||||
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 0
|
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 1
|
||||||
|
// @has - '//details[@class="rustdoc-toggle type-contents-toggle"]' 'Show fields'
|
||||||
pub enum Enum {
|
pub enum Enum {
|
||||||
A, B, C,
|
A, B, C,
|
||||||
D {
|
D {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue