about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-05-07 17:19:33 +0000
committerbors <bors@rust-lang.org>2015-05-07 17:19:33 +0000
commitf0ac7e04e647381e2bb87de1f3d0b108acb24d06 (patch)
treec7d59b02a4ea8c143541ec583297260de9b9be20
parenta39d4fc68472ed7a512a7de93f422d7697d92e06 (diff)
parent61bb091f068f401f768b1a0e377f22bb83e4584c (diff)
downloadrust-f0ac7e04e647381e2bb87de1f3d0b108acb24d06.tar.gz
rust-f0ac7e04e647381e2bb87de1f3d0b108acb24d06.zip
Auto merge of #24973 - roryokane:fix-minus-doc-buttons, r=alexcrichton
My change in #24797 had a bug, described in that issue’s comments, and first discovered in issue #24918. This fixes it.

I tested this new `main.js` by changing the `main.js` content of [a rendered docs page](https://doc.rust-lang.org/std/option/) to this new content. The ‘[−]’ button worked again.

I am also including another related fix, because it would require manual merging if I made a separate pull request for it. The page-global ‘[−]’ button currently adds `#` to the end of the URL whenever it is clicked. I am changing its `href` from `#` to `javascript:void(0)` (the same as the `href` for section-specific ‘[−]’ links) to fix that.
-rw-r--r--src/librustdoc/html/render.rs4
-rw-r--r--src/librustdoc/html/static/main.css2
-rw-r--r--src/librustdoc/html/static/main.js40
3 files changed, 31 insertions, 15 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 5a828e8376e..0642daeeb3a 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -1460,7 +1460,9 @@ impl<'a> fmt::Display for Item<'a> {
         try!(write!(fmt, "<span class='out-of-band'>"));
         try!(write!(fmt,
         r##"<span id='render-detail'>
-            <a id="toggle-all-docs" href="#" title="collapse all docs">[&minus;]</a>
+            <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
+                [<span class='inner'>&#x2212;</span>]
+            </a>
         </span>"##));
 
         // Write `src` tag
diff --git a/src/librustdoc/html/static/main.css b/src/librustdoc/html/static/main.css
index b907e9e20b6..2dc5ea99067 100644
--- a/src/librustdoc/html/static/main.css
+++ b/src/librustdoc/html/static/main.css
@@ -581,7 +581,7 @@ pre.rust { position: relative; }
 
 .collapse-toggle > .inner {
     display: inline-block;
-    width: 1ch;
+    width: 1.2ch;
     text-align: center;
 }
 
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index c2a59278a86..6a1d7bdfd83 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -806,22 +806,35 @@
         window.location = $('.srclink').attr('href');
     }
 
+    function labelForToggleButton(sectionIsCollapsed) {
+        if (sectionIsCollapsed) {
+            // button will expand the section
+            return "+";
+        } else {
+            // button will collapse the section
+            // note that this text is also set in the HTML template in render.rs
+            return "\u2212"; // "\u2212" is '−' minus sign
+        }
+    }
+
     $("#toggle-all-docs").on("click", function() {
         var toggle = $("#toggle-all-docs");
-        if (toggle.html() == "[&minus;]") {
-            toggle.html("[&plus;]");
-            toggle.attr("title", "expand all docs");
-            $(".docblock").hide();
-            $(".toggle-label").show();
-            $(".toggle-wrapper").addClass("collapsed");
-            $(".collapse-toggle").children(".inner").html("&plus;");
-        } else {
-            toggle.html("[&minus;]");
+        if (toggle.hasClass("will-expand")) {
+            toggle.removeClass("will-expand");
+            toggle.children(".inner").text(labelForToggleButton(false));
             toggle.attr("title", "collapse all docs");
             $(".docblock").show();
             $(".toggle-label").hide();
             $(".toggle-wrapper").removeClass("collapsed");
-            $(".collapse-toggle").children(".inner").html("&minus;");
+            $(".collapse-toggle").children(".inner").text(labelForToggleButton(false));
+        } else {
+            toggle.addClass("will-expand");
+            toggle.children(".inner").text(labelForToggleButton(true));
+            toggle.attr("title", "expand all docs");
+            $(".docblock").hide();
+            $(".toggle-label").show();
+            $(".toggle-wrapper").addClass("collapsed");
+            $(".collapse-toggle").children(".inner").text(labelForToggleButton(true));
         }
     });
 
@@ -835,12 +848,12 @@
             if (relatedDoc.is(":visible")) {
                 relatedDoc.slideUp({duration:'fast', easing:'linear'});
                 toggle.parent(".toggle-wrapper").addClass("collapsed");
-                toggle.children(".inner").html("&plus;");
+                toggle.children(".inner").text(labelForToggleButton(true));
                 toggle.children(".toggle-label").fadeIn();
             } else {
                 relatedDoc.slideDown({duration:'fast', easing:'linear'});
                 toggle.parent(".toggle-wrapper").removeClass("collapsed");
-                toggle.children(".inner").html("&minus;");
+                toggle.children(".inner").text(labelForToggleButton(false));
                 toggle.children(".toggle-label").hide();
             }
         }
@@ -848,7 +861,8 @@
 
     $(function() {
         var toggle = $("<a/>", {'href': 'javascript:void(0)', 'class': 'collapse-toggle'})
-            .html("[<span class='inner'>&minus;</span>]");
+            .html("[<span class='inner'></span>]");
+        toggle.children(".inner").text(labelForToggleButton(false));
 
         $(".method").each(function() {
             if ($(this).next().is(".docblock") ||