diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2018-08-02 00:19:04 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2018-08-02 00:19:04 +0200 |
| commit | 2462cdb71d7536cd9e1dedab0d2112e9163a3a0a (patch) | |
| tree | 6f17c5150602715c46a9d883f77cc9c4ab2df646 /src/librustdoc/html | |
| parent | 75af9df71b9eea84f281cf7de72c3e3cc2b02222 (diff) | |
| download | rust-2462cdb71d7536cd9e1dedab0d2112e9163a3a0a.tar.gz rust-2462cdb71d7536cd9e1dedab0d2112e9163a3a0a.zip | |
Fix trait item doc setting, add new setting, start hiding elements by default and then showing them up
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/render.rs | 3 | ||||
| -rw-r--r-- | src/librustdoc/html/static/main.js | 41 |
2 files changed, 34 insertions, 10 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index a1ab66ea81c..e8346670453 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -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), ("go-to-only-result", "Directly go to item in search if there is only one result", false), ], @@ -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>") } diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 62ef5626ee5..709865bc932 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1938,18 +1938,27 @@ 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[0].getElementsByClassName("collapse-toggle"), collapser); + } } } @@ -2001,10 +2010,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 = ' Expand description'; } else { @@ -2020,8 +2031,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; @@ -2053,10 +2071,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")) { @@ -2071,8 +2094,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"); } } |
