Skip to content

Commit 65f8899

Browse files
committed
Auto merge of #24694 - liigo:toggle-all-docs-using-one-link, r=alexcrichton
Combine the two links, [-] and [+], at top-right corner of the page, to use a single and the same one, so that: - one less link to be created/displayed - be consistent with other [-]/[+] links in the same page - people can easily toggle docs without moving their mouse pointer I also added tooltips/titles to these links.
2 parents 1114fcd + 7a53081 commit 65f8899

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

Diff for: src/librustdoc/html/render.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ 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="collapse-all" href="#">[-]</a>&nbsp;<a id="expand-all" href="#">[+]</a>
1463+
<a id="toggle-all-docs" href="#" title="collapse all docs">[-]</a>
14641464
</span>"##));
14651465

14661466
// Write `src` tag
@@ -1473,8 +1473,8 @@ impl<'a> fmt::Display for Item<'a> {
14731473
match self.href(self.cx) {
14741474
Some(l) => {
14751475
try!(write!(fmt, "<a id='src-{}' class='srclink' \
1476-
href='{}'>[src]</a>",
1477-
self.item.def_id.node, l));
1476+
href='{}' title='{}'>[src]</a>",
1477+
self.item.def_id.node, l, "goto source code"));
14781478
}
14791479
None => {}
14801480
}

Diff for: src/librustdoc/html/static/main.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -806,18 +806,23 @@
806806
window.location = $('.srclink').attr('href');
807807
}
808808

809-
$("#expand-all").on("click", function() {
810-
$(".docblock").show();
811-
$(".toggle-label").hide();
812-
$(".toggle-wrapper").removeClass("collapsed");
813-
$(".collapse-toggle").children(".inner").html("-");
814-
});
815-
816-
$("#collapse-all").on("click", function() {
817-
$(".docblock").hide();
818-
$(".toggle-label").show();
819-
$(".toggle-wrapper").addClass("collapsed");
820-
$(".collapse-toggle").children(".inner").html("+");
809+
$("#toggle-all-docs").on("click", function() {
810+
var toggle = $("#toggle-all-docs");
811+
if (toggle.html() == "[-]") {
812+
toggle.html("[+]");
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("+");
818+
} else {
819+
toggle.html("[-]");
820+
toggle.attr("title", "collapse all docs");
821+
$(".docblock").show();
822+
$(".toggle-label").hide();
823+
$(".toggle-wrapper").removeClass("collapsed");
824+
$(".collapse-toggle").children(".inner").html("-");
825+
}
821826
});
822827

823828
$(document).on("click", ".collapse-toggle", function() {

0 commit comments

Comments
 (0)