Skip to content

Fix trait item doc setting, add new setting, start hiding elements by default and then showing them up #52962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ impl<'a> Settings<'a> {
("item-attributes", "Auto-hide item attributes.", true),
("trait-implementations", "Auto-hide trait implementations documentation",
true),
("method-docs", "Auto-hide item methods' documentation", false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this setting requested by anyone? It doesn't seem all that necessary to me. "Collapse all" is already saved into local storage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were doing it before through "trait-implementations". Now that I've fixed it, I assume some people might want all their docs collapsed by default so why not providing it?

("go-to-only-result", "Directly go to item in search if there is only one result",
false),
],
Expand Down Expand Up @@ -2073,7 +2074,7 @@ impl<'a> Item<'a> {
fn wrap_into_docblock<F>(w: &mut fmt::Formatter,
f: F) -> 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)?;
write!(w, "</div>")
}
Expand Down
43 changes: 34 additions & 9 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1938,18 +1938,29 @@
if (collapse) {
toggleAllDocs(pageId, true);
}
if (getCurrentValue('rustdoc-trait-implementations') !== "false") {
onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
var collapser = function(e) {
// inherent impl ids are like 'impl' or impl-<number>'.
// they will never be hidden by default.
var n = e.parentNode;
var n = e.parentElement;
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
// Automatically minimize all non-inherent impls
if (collapse || hasClass(n, 'impl')) {
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);
});
}
}
}

Expand Down Expand Up @@ -2001,10 +2012,12 @@
onEach(e.getElementsByClassName('associatedconstant'), func);
});

function createToggle(otherMessage, fontSize, extraClass) {
function createToggle(otherMessage, fontSize, extraClass, show) {
var span = document.createElement('span');
span.className = 'toggle-label';
span.style.display = 'none';
if (show) {
span.style.display = 'none';
}
if (!otherMessage) {
span.innerHTML = '&nbsp;Expand&nbsp;description';
} else {
Expand All @@ -2020,8 +2033,15 @@

var wrapper = document.createElement('div');
wrapper.className = 'toggle-wrapper';
if (!show) {
addClass(wrapper, 'collapsed');
var inner = mainToggle.getElementsByClassName('inner');
if (inner && inner.length > 0) {
inner[0].innerHTML = '+';
}
}
if (extraClass) {
wrapper.className += ' ' + extraClass;
addClass(wrapper, extraClass);
}
wrapper.appendChild(mainToggle);
return wrapper;
Expand Down Expand Up @@ -2053,10 +2073,15 @@
var otherMessage;
var fontSize;
var extraClass;
var show = true;

if (hasClass(e, "type-decl")) {
fontSize = "20px";
otherMessage = '&nbsp;Show&nbsp;declaration';
show = getCurrentValue('rustdoc-item-declarations') === "false";
if (!show) {
extraClass = 'collapsed';
}
} else if (hasClass(e, "non-exhaustive")) {
otherMessage = '&nbsp;This&nbsp;';
if (hasClass(e, "non-exhaustive-struct")) {
Expand All @@ -2071,8 +2096,8 @@
extraClass = "marg-left";
}

e.parentNode.insertBefore(createToggle(otherMessage, fontSize, extraClass), e);
if (otherMessage && getCurrentValue('rustdoc-item-declarations') !== "false") {
e.parentNode.insertBefore(createToggle(otherMessage, fontSize, extraClass, show), e);
if (otherMessage && show) {
collapseDocs(e.previousSibling.childNodes[0], "toggle");
}
}
Expand Down