diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 867b2a32905..d4e22dd91d7 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1667,6 +1667,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), ("go-to-only-result", "Directly go to item in search if there is only one result", false), ], @@ -2074,7 +2075,7 @@ impl<'a> Item<'a> { fn wrap_into_docblock(w: &mut fmt::Formatter, f: F) -> fmt::Result where F: Fn(&mut fmt::Formatter) -> fmt::Result { - write!(w, "
")?; + write!(w, "
")?; f(w)?; write!(w, "
") } diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index a6027a54657..3dbefabace1 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1979,18 +1979,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-'. // 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); + }); + } } } @@ -2041,10 +2052,12 @@ onEach(document.getElementsByClassName('associatedconstant'), func); onEach(document.getElementsByClassName('impl'), 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 = ' Expand description'; } else { @@ -2060,8 +2073,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; @@ -2093,10 +2113,15 @@ var otherMessage; var fontSize; var extraClass; + var show = true; if (hasClass(e, "type-decl")) { fontSize = "20px"; otherMessage = ' Show declaration'; + show = getCurrentValue('rustdoc-item-declarations') === "false"; + if (!show) { + extraClass = 'collapsed'; + } } else if (hasClass(e, "non-exhaustive")) { otherMessage = ' This '; if (hasClass(e, "non-exhaustive-struct")) { @@ -2111,8 +2136,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"); } }