|
2093 | 2093 | return wrapper; |
2094 | 2094 | } |
2095 | 2095 |
|
| 2096 | + var hideItemDeclarations = getCurrentValue('rustdoc-item-declarations') === "false"; |
2096 | 2097 | onEach(document.getElementsByClassName('docblock'), function(e) { |
2097 | 2098 | if (hasClass(e, 'autohide')) { |
2098 | 2099 | var wrap = e.previousElementSibling; |
|
2116 | 2117 | } |
2117 | 2118 | } |
2118 | 2119 | if (e.parentNode.id === "main") { |
2119 | | - var otherMessage; |
| 2120 | + var otherMessage = ''; |
2120 | 2121 | var fontSize; |
2121 | 2122 | var extraClass; |
2122 | | - var show = true; |
2123 | 2123 |
|
2124 | 2124 | if (hasClass(e, "type-decl")) { |
2125 | 2125 | fontSize = "20px"; |
2126 | 2126 | otherMessage = ' Show declaration'; |
2127 | | - show = getCurrentValue('rustdoc-item-declarations') === "false"; |
2128 | | - if (!show) { |
| 2127 | + if (hideItemDeclarations === false) { |
2129 | 2128 | extraClass = 'collapsed'; |
2130 | 2129 | } |
2131 | 2130 | } else if (hasClass(e, "non-exhaustive")) { |
|
2142 | 2141 | extraClass = "marg-left"; |
2143 | 2142 | } |
2144 | 2143 |
|
2145 | | - e.parentNode.insertBefore(createToggle(otherMessage, fontSize, extraClass, show), e); |
2146 | | - if (otherMessage && show) { |
| 2144 | + e.parentNode.insertBefore(createToggle(otherMessage, |
| 2145 | + fontSize, |
| 2146 | + extraClass, |
| 2147 | + hideItemDeclarations), |
| 2148 | + e); |
| 2149 | + if (otherMessage.length > 0 && hideItemDeclarations === true) { |
2147 | 2150 | collapseDocs(e.previousSibling.childNodes[0], "toggle"); |
2148 | 2151 | } |
2149 | 2152 | } |
|
2186 | 2189 | }); |
2187 | 2190 | } |
2188 | 2191 |
|
| 2192 | + // To avoid checking on "rustdoc-item-attributes" value on every loop... |
| 2193 | + var itemAttributesFunc = function() {}; |
| 2194 | + if (getCurrentValue("rustdoc-item-attributes") !== "false") { |
| 2195 | + itemAttributesFunc = function(x) { |
| 2196 | + collapseDocs(x.previousSibling.childNodes[0], "toggle"); |
| 2197 | + }; |
| 2198 | + } |
2189 | 2199 | onEach(document.getElementById('main').getElementsByClassName('attributes'), function(i_e) { |
2190 | 2200 | i_e.parentNode.insertBefore(createToggleWrapper(toggle.cloneNode(true)), i_e); |
2191 | | - if (getCurrentValue("rustdoc-item-attributes") !== "false") { |
2192 | | - collapseDocs(i_e.previousSibling.childNodes[0], "toggle"); |
2193 | | - } |
| 2201 | + itemAttributesFunc(i_e); |
2194 | 2202 | }); |
2195 | 2203 |
|
| 2204 | + // To avoid checking on "rustdoc-line-numbers" value on every loop... |
| 2205 | + var lineNumbersFunc = function() {}; |
| 2206 | + if (getCurrentValue("rustdoc-line-numbers") === "true") { |
| 2207 | + lineNumbersFunc = function(x) { |
| 2208 | + var count = x.textContent.split('\n').length; |
| 2209 | + var elems = []; |
| 2210 | + for (var i = 0; i < count; ++i) { |
| 2211 | + elems.push(i + 1); |
| 2212 | + } |
| 2213 | + var node = document.createElement('pre'); |
| 2214 | + addClass(node, 'line-number'); |
| 2215 | + node.innerHTML = elems.join('\n'); |
| 2216 | + x.parentNode.insertBefore(node, x); |
| 2217 | + }; |
| 2218 | + } |
2196 | 2219 | onEach(document.getElementsByClassName('rust-example-rendered'), function(e) { |
2197 | 2220 | if (hasClass(e, 'compile_fail')) { |
2198 | 2221 | e.addEventListener("mouseover", function(event) { |
|
2209 | 2232 | e.previousElementSibling.childNodes[0].style.color = ''; |
2210 | 2233 | }); |
2211 | 2234 | } |
| 2235 | + lineNumbersFunc(e); |
2212 | 2236 | }); |
2213 | 2237 |
|
2214 | 2238 | function showModal(content) { |
|
0 commit comments