Auto merge of #52962 - GuillaumeGomez:few-things, r=QuietMisdreavus
Fix trait item doc setting, add new setting, start hiding elements by default and then showing them up r? @QuietMisdreavus
This commit is contained in:
commit
e7f1880921
2 changed files with 36 additions and 10 deletions
|
@ -1667,6 +1667,7 @@ impl<'a> Settings<'a> {
|
||||||
("item-attributes", "Auto-hide item attributes.", true),
|
("item-attributes", "Auto-hide item attributes.", true),
|
||||||
("trait-implementations", "Auto-hide trait implementations documentation",
|
("trait-implementations", "Auto-hide trait implementations documentation",
|
||||||
true),
|
true),
|
||||||
|
("method-docs", "Auto-hide item methods' documentation", false),
|
||||||
("go-to-only-result", "Directly go to item in search if there is only one result",
|
("go-to-only-result", "Directly go to item in search if there is only one result",
|
||||||
false),
|
false),
|
||||||
],
|
],
|
||||||
|
@ -2074,7 +2075,7 @@ impl<'a> Item<'a> {
|
||||||
fn wrap_into_docblock<F>(w: &mut fmt::Formatter,
|
fn wrap_into_docblock<F>(w: &mut fmt::Formatter,
|
||||||
f: F) -> fmt::Result
|
f: F) -> fmt::Result
|
||||||
where F: Fn(&mut fmt::Formatter) -> fmt::Result {
|
where F: Fn(&mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(w, "<div class=\"docblock type-decl\">")?;
|
write!(w, "<div class=\"docblock type-decl hidden-by-usual-hider\">")?;
|
||||||
f(w)?;
|
f(w)?;
|
||||||
write!(w, "</div>")
|
write!(w, "</div>")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1979,18 +1979,29 @@
|
||||||
if (collapse) {
|
if (collapse) {
|
||||||
toggleAllDocs(pageId, true);
|
toggleAllDocs(pageId, true);
|
||||||
}
|
}
|
||||||
if (getCurrentValue('rustdoc-trait-implementations') !== "false") {
|
var collapser = function(e) {
|
||||||
onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
|
|
||||||
// inherent impl ids are like 'impl' or impl-<number>'.
|
// inherent impl ids are like 'impl' or impl-<number>'.
|
||||||
// they will never be hidden by default.
|
// they will never be hidden by default.
|
||||||
var n = e.parentNode;
|
var n = e.parentElement;
|
||||||
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
|
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
|
||||||
// Automatically minimize all non-inherent impls
|
// Automatically minimize all non-inherent impls
|
||||||
if (collapse || hasClass(n, 'impl')) {
|
if (collapse || hasClass(n, 'impl')) {
|
||||||
collapseDocs(e, "hide", pageId);
|
collapseDocs(e, "hide", pageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
if (getCurrentValue('rustdoc-trait-implementations') !== "false") {
|
||||||
|
onEach(document.getElementById('implementations-list')
|
||||||
|
.getElementsByClassName("collapse-toggle"), collapser);
|
||||||
|
}
|
||||||
|
if (getCurrentValue('rustdoc-method-docs') !== "false") {
|
||||||
|
var implItems = document.getElementsByClassName('impl-items');
|
||||||
|
|
||||||
|
if (implItems && implItems.length > 0) {
|
||||||
|
onEach(implItems, function(elem) {
|
||||||
|
onEach(elem.getElementsByClassName("collapse-toggle"), collapser);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2041,10 +2052,12 @@
|
||||||
onEach(document.getElementsByClassName('associatedconstant'), func);
|
onEach(document.getElementsByClassName('associatedconstant'), func);
|
||||||
onEach(document.getElementsByClassName('impl'), func);
|
onEach(document.getElementsByClassName('impl'), func);
|
||||||
|
|
||||||
function createToggle(otherMessage, fontSize, extraClass) {
|
function createToggle(otherMessage, fontSize, extraClass, show) {
|
||||||
var span = document.createElement('span');
|
var span = document.createElement('span');
|
||||||
span.className = 'toggle-label';
|
span.className = 'toggle-label';
|
||||||
span.style.display = 'none';
|
if (show) {
|
||||||
|
span.style.display = 'none';
|
||||||
|
}
|
||||||
if (!otherMessage) {
|
if (!otherMessage) {
|
||||||
span.innerHTML = ' Expand description';
|
span.innerHTML = ' Expand description';
|
||||||
} else {
|
} else {
|
||||||
|
@ -2060,8 +2073,15 @@
|
||||||
|
|
||||||
var wrapper = document.createElement('div');
|
var wrapper = document.createElement('div');
|
||||||
wrapper.className = 'toggle-wrapper';
|
wrapper.className = 'toggle-wrapper';
|
||||||
|
if (!show) {
|
||||||
|
addClass(wrapper, 'collapsed');
|
||||||
|
var inner = mainToggle.getElementsByClassName('inner');
|
||||||
|
if (inner && inner.length > 0) {
|
||||||
|
inner[0].innerHTML = '+';
|
||||||
|
}
|
||||||
|
}
|
||||||
if (extraClass) {
|
if (extraClass) {
|
||||||
wrapper.className += ' ' + extraClass;
|
addClass(wrapper, extraClass);
|
||||||
}
|
}
|
||||||
wrapper.appendChild(mainToggle);
|
wrapper.appendChild(mainToggle);
|
||||||
return wrapper;
|
return wrapper;
|
||||||
|
@ -2093,10 +2113,15 @@
|
||||||
var otherMessage;
|
var otherMessage;
|
||||||
var fontSize;
|
var fontSize;
|
||||||
var extraClass;
|
var extraClass;
|
||||||
|
var show = true;
|
||||||
|
|
||||||
if (hasClass(e, "type-decl")) {
|
if (hasClass(e, "type-decl")) {
|
||||||
fontSize = "20px";
|
fontSize = "20px";
|
||||||
otherMessage = ' Show declaration';
|
otherMessage = ' Show declaration';
|
||||||
|
show = getCurrentValue('rustdoc-item-declarations') === "false";
|
||||||
|
if (!show) {
|
||||||
|
extraClass = 'collapsed';
|
||||||
|
}
|
||||||
} 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")) {
|
||||||
|
@ -2111,8 +2136,8 @@
|
||||||
extraClass = "marg-left";
|
extraClass = "marg-left";
|
||||||
}
|
}
|
||||||
|
|
||||||
e.parentNode.insertBefore(createToggle(otherMessage, fontSize, extraClass), e);
|
e.parentNode.insertBefore(createToggle(otherMessage, fontSize, extraClass, show), e);
|
||||||
if (otherMessage && getCurrentValue('rustdoc-item-declarations') !== "false") {
|
if (otherMessage && show) {
|
||||||
collapseDocs(e.previousSibling.childNodes[0], "toggle");
|
collapseDocs(e.previousSibling.childNodes[0], "toggle");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue