about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-06-11 04:38:04 +0800
committerkennytm <kennytm@gmail.com>2018-06-13 18:00:18 +0800
commitca65a5e485761ed06e88756d9066156109b0755f (patch)
tree07088a06b0145fe96d3f1f1a0ff808031a53b070
parent8398ab82e5d6623f49f054af848f1553f429d307 (diff)
downloadrust-ca65a5e485761ed06e88756d9066156109b0755f.tar.gz
rust-ca65a5e485761ed06e88756d9066156109b0755f.zip
Don't auto-hide inherent impls even if `rustdoc-collapse == true`.
-rw-r--r--src/librustdoc/html/static/main.js49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 983da51779c..ed6745cd7f5 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -1775,7 +1775,7 @@
         }
     }
 
-    function toggleAllDocs(pageId) {
+    function toggleAllDocs(pageId, fromAutoCollapse) {
         var toggle = document.getElementById("toggle-all-docs");
         if (!toggle) {
             return;
@@ -1787,9 +1787,11 @@
                 e.innerHTML = labelForToggleButton(false);
             });
             toggle.title = "collapse all docs";
-            onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
-                collapseDocs(e, "show");
-            });
+            if (fromAutoCollapse !== true) {
+                onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
+                    collapseDocs(e, "show");
+                });
+            }
         } else {
             updateLocalStorage("rustdoc-collapse", "true");
             addClass(toggle, "will-expand");
@@ -1797,10 +1799,11 @@
                 e.innerHTML = labelForToggleButton(true);
             });
             toggle.title = "expand all docs";
-
-            onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
-                collapseDocs(e, "hide", pageId);
-            });
+            if (fromAutoCollapse !== true) {
+                onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
+                    collapseDocs(e, "hide", pageId);
+                });
+            }
         }
     }
 
@@ -1921,17 +1924,19 @@
         }
     }
 
-    function autoCollapseAllImpls(pageId) {
-        // Automatically minimize all non-inherent impls
-        onEach(document.getElementsByClassName('impl'), function(n) {
-            // inherent impl ids are like 'impl' or impl-<number>'
-            var inherent = (n.id.match(/^impl(?:-\d+)?$/) !== null);
-            if (!inherent) {
-                onEach(n.childNodes, function(m) {
-                    if (hasClass(m, "collapse-toggle")) {
-                        collapseDocs(m, "hide", pageId);
-                    }
-                });
+    function autoCollapse(pageId, collapse) {
+        if (collapse) {
+            toggleAllDocs(pageId, true);
+        }
+        onEach(document.getElementsByClassName("collapse-toggle"), function(e) {
+            // inherent impl ids are like 'impl' or impl-<number>'.
+            // they will never be hidden by default.
+            var n = e.parentNode;
+            if (n.id.match(/^impl(?:-\d+)?$/) === null) {
+                // Automatically minimize all non-inherent impls
+                if (collapse || hasClass(n, 'impl')) {
+                    collapseDocs(e, "hide", pageId);
+                }
             }
         });
     }
@@ -2044,8 +2049,6 @@
         }
     });
 
-    autoCollapseAllImpls(getPageId());
-
     function createToggleWrapper(tog) {
         var span = document.createElement('span');
         span.className = 'toggle-label';
@@ -2175,9 +2178,7 @@
         hideSidebar();
     };
 
-    if (getCurrentValue("rustdoc-collapse") === "true") {
-        toggleAllDocs(getPageId());
-    }
+    autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true");
 }());
 
 // Sets the focus on the search bar at the top of the page