Skip to content

Commit f0ac7e0

Browse files
committed
Auto merge of rust-lang#24973 - roryokane:fix-minus-doc-buttons, r=alexcrichton
My change in rust-lang#24797 had a bug, described in that issue’s comments, and first discovered in issue rust-lang#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.
2 parents a39d4fc + 61bb091 commit f0ac7e0

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

src/librustdoc/html/render.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,9 @@ impl<'a> fmt::Display for Item<'a> {
14601460
try!(write!(fmt, "<span class='out-of-band'>"));
14611461
try!(write!(fmt,
14621462
r##"<span id='render-detail'>
1463-
<a id="toggle-all-docs" href="#" title="collapse all docs">[&minus;]</a>
1463+
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
1464+
[<span class='inner'>&#x2212;</span>]
1465+
</a>
14641466
</span>"##));
14651467

14661468
// Write `src` tag

src/librustdoc/html/static/main.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ pre.rust { position: relative; }
581581

582582
.collapse-toggle > .inner {
583583
display: inline-block;
584-
width: 1ch;
584+
width: 1.2ch;
585585
text-align: center;
586586
}
587587

src/librustdoc/html/static/main.js

+27-13
Original file line numberDiff line numberDiff line change
@@ -806,22 +806,35 @@
806806
window.location = $('.srclink').attr('href');
807807
}
808808

809+
function labelForToggleButton(sectionIsCollapsed) {
810+
if (sectionIsCollapsed) {
811+
// button will expand the section
812+
return "+";
813+
} else {
814+
// button will collapse the section
815+
// note that this text is also set in the HTML template in render.rs
816+
return "\u2212"; // "\u2212" is '−' minus sign
817+
}
818+
}
819+
809820
$("#toggle-all-docs").on("click", function() {
810821
var toggle = $("#toggle-all-docs");
811-
if (toggle.html() == "[&minus;]") {
812-
toggle.html("[&plus;]");
813-
toggle.attr("title", "expand all docs");
814-
$(".docblock").hide();
815-
$(".toggle-label").show();
816-
$(".toggle-wrapper").addClass("collapsed");
817-
$(".collapse-toggle").children(".inner").html("&plus;");
818-
} else {
819-
toggle.html("[&minus;]");
822+
if (toggle.hasClass("will-expand")) {
823+
toggle.removeClass("will-expand");
824+
toggle.children(".inner").text(labelForToggleButton(false));
820825
toggle.attr("title", "collapse all docs");
821826
$(".docblock").show();
822827
$(".toggle-label").hide();
823828
$(".toggle-wrapper").removeClass("collapsed");
824-
$(".collapse-toggle").children(".inner").html("&minus;");
829+
$(".collapse-toggle").children(".inner").text(labelForToggleButton(false));
830+
} else {
831+
toggle.addClass("will-expand");
832+
toggle.children(".inner").text(labelForToggleButton(true));
833+
toggle.attr("title", "expand all docs");
834+
$(".docblock").hide();
835+
$(".toggle-label").show();
836+
$(".toggle-wrapper").addClass("collapsed");
837+
$(".collapse-toggle").children(".inner").text(labelForToggleButton(true));
825838
}
826839
});
827840

@@ -835,20 +848,21 @@
835848
if (relatedDoc.is(":visible")) {
836849
relatedDoc.slideUp({duration:'fast', easing:'linear'});
837850
toggle.parent(".toggle-wrapper").addClass("collapsed");
838-
toggle.children(".inner").html("&plus;");
851+
toggle.children(".inner").text(labelForToggleButton(true));
839852
toggle.children(".toggle-label").fadeIn();
840853
} else {
841854
relatedDoc.slideDown({duration:'fast', easing:'linear'});
842855
toggle.parent(".toggle-wrapper").removeClass("collapsed");
843-
toggle.children(".inner").html("&minus;");
856+
toggle.children(".inner").text(labelForToggleButton(false));
844857
toggle.children(".toggle-label").hide();
845858
}
846859
}
847860
});
848861

849862
$(function() {
850863
var toggle = $("<a/>", {'href': 'javascript:void(0)', 'class': 'collapse-toggle'})
851-
.html("[<span class='inner'>&minus;</span>]");
864+
.html("[<span class='inner'></span>]");
865+
toggle.children(".inner").text(labelForToggleButton(false));
852866

853867
$(".method").each(function() {
854868
if ($(this).next().is(".docblock") ||

0 commit comments

Comments
 (0)