|
1775 | 1775 | } |
1776 | 1776 | } |
1777 | 1777 |
|
1778 | | - function toggleAllDocs(pageId) { |
| 1778 | + function toggleAllDocs(pageId, fromAutoCollapse) { |
1779 | 1779 | var toggle = document.getElementById("toggle-all-docs"); |
1780 | 1780 | if (!toggle) { |
1781 | 1781 | return; |
|
1787 | 1787 | e.innerHTML = labelForToggleButton(false); |
1788 | 1788 | }); |
1789 | 1789 | toggle.title = "collapse all docs"; |
1790 | | - onEach(document.getElementsByClassName("collapse-toggle"), function(e) { |
1791 | | - collapseDocs(e, "show"); |
1792 | | - }); |
| 1790 | + if (fromAutoCollapse !== true) { |
| 1791 | + onEach(document.getElementsByClassName("collapse-toggle"), function(e) { |
| 1792 | + collapseDocs(e, "show"); |
| 1793 | + }); |
| 1794 | + } |
1793 | 1795 | } else { |
1794 | 1796 | updateLocalStorage("rustdoc-collapse", "true"); |
1795 | 1797 | addClass(toggle, "will-expand"); |
1796 | 1798 | onEveryMatchingChild(toggle, "inner", function(e) { |
1797 | 1799 | e.innerHTML = labelForToggleButton(true); |
1798 | 1800 | }); |
1799 | 1801 | toggle.title = "expand all docs"; |
1800 | | - |
1801 | | - onEach(document.getElementsByClassName("collapse-toggle"), function(e) { |
1802 | | - collapseDocs(e, "hide", pageId); |
1803 | | - }); |
| 1802 | + if (fromAutoCollapse !== true) { |
| 1803 | + onEach(document.getElementsByClassName("collapse-toggle"), function(e) { |
| 1804 | + collapseDocs(e, "hide", pageId); |
| 1805 | + }); |
| 1806 | + } |
1804 | 1807 | } |
1805 | 1808 | } |
1806 | 1809 |
|
|
1921 | 1924 | } |
1922 | 1925 | } |
1923 | 1926 |
|
1924 | | - function autoCollapseAllImpls(pageId) { |
1925 | | - // Automatically minimize all non-inherent impls |
1926 | | - onEach(document.getElementsByClassName('impl'), function(n) { |
1927 | | - // inherent impl ids are like 'impl' or impl-<number>' |
1928 | | - var inherent = (n.id.match(/^impl(?:-\d+)?$/) !== null); |
1929 | | - if (!inherent) { |
1930 | | - onEach(n.childNodes, function(m) { |
1931 | | - if (hasClass(m, "collapse-toggle")) { |
1932 | | - collapseDocs(m, "hide", pageId); |
1933 | | - } |
1934 | | - }); |
| 1927 | + function autoCollapse(pageId, collapse) { |
| 1928 | + if (collapse) { |
| 1929 | + toggleAllDocs(pageId, true); |
| 1930 | + } |
| 1931 | + onEach(document.getElementsByClassName("collapse-toggle"), function(e) { |
| 1932 | + // inherent impl ids are like 'impl' or impl-<number>'. |
| 1933 | + // they will never be hidden by default. |
| 1934 | + var n = e.parentNode; |
| 1935 | + if (n.id.match(/^impl(?:-\d+)?$/) === null) { |
| 1936 | + // Automatically minimize all non-inherent impls |
| 1937 | + if (collapse || hasClass(n, 'impl')) { |
| 1938 | + collapseDocs(e, "hide", pageId); |
| 1939 | + } |
1935 | 1940 | } |
1936 | 1941 | }); |
1937 | 1942 | } |
|
2044 | 2049 | } |
2045 | 2050 | }); |
2046 | 2051 |
|
2047 | | - autoCollapseAllImpls(getPageId()); |
2048 | | - |
2049 | 2052 | function createToggleWrapper(tog) { |
2050 | 2053 | var span = document.createElement('span'); |
2051 | 2054 | span.className = 'toggle-label'; |
|
2175 | 2178 | hideSidebar(); |
2176 | 2179 | }; |
2177 | 2180 |
|
2178 | | - if (getCurrentValue("rustdoc-collapse") === "true") { |
2179 | | - toggleAllDocs(getPageId()); |
2180 | | - } |
| 2181 | + autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true"); |
2181 | 2182 | }()); |
2182 | 2183 |
|
2183 | 2184 | // Sets the focus on the search bar at the top of the page |
|
0 commit comments