From 2258aef74f4af9b7ac2087098494df77a6d5206c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Thu, 30 Apr 2015 00:07:42 -0400 Subject: [PATCH 1/5] =?UTF-8?q?Fix=20doc=20[=E2=88=92]=20button=20bug=20by?= =?UTF-8?q?=20escaping=20differently?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cause of the problem is described here: https://github.com/rust-lang/rust/pull/24797#issuecomment-97049765 . I tested this new `main.js` by changing the `main.js` content of a rendered docs page to this new content. The [−] button worked again. --- src/librustdoc/html/render.rs | 2 +- src/librustdoc/html/static/main.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 9a26a925847e4..3d5e13f327009 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1460,7 +1460,7 @@ impl<'a> fmt::Display for Item<'a> { try!(write!(fmt, "")); try!(write!(fmt, r##" - [−] + [−] "##)); // Write `src` tag diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index c2a59278a86dc..cfa599041ee2e 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -808,20 +808,20 @@ $("#toggle-all-docs").on("click", function() { var toggle = $("#toggle-all-docs"); - if (toggle.html() == "[−]") { - toggle.html("[+]"); + if (toggle.html() == "[\u2212]") { + toggle.html("[+]"); toggle.attr("title", "expand all docs"); $(".docblock").hide(); $(".toggle-label").show(); $(".toggle-wrapper").addClass("collapsed"); - $(".collapse-toggle").children(".inner").html("+"); + $(".collapse-toggle").children(".inner").html("+"); } else { - toggle.html("[−]"); + toggle.html("[\u2212]"); toggle.attr("title", "collapse all docs"); $(".docblock").show(); $(".toggle-label").hide(); $(".toggle-wrapper").removeClass("collapsed"); - $(".collapse-toggle").children(".inner").html("−"); + $(".collapse-toggle").children(".inner").html("\u2212"); } }); @@ -835,12 +835,12 @@ if (relatedDoc.is(":visible")) { relatedDoc.slideUp({duration:'fast', easing:'linear'}); toggle.parent(".toggle-wrapper").addClass("collapsed"); - toggle.children(".inner").html("+"); + toggle.children(".inner").html("+"); toggle.children(".toggle-label").fadeIn(); } else { relatedDoc.slideDown({duration:'fast', easing:'linear'}); toggle.parent(".toggle-wrapper").removeClass("collapsed"); - toggle.children(".inner").html("−"); + toggle.children(".inner").html("\u2212"); toggle.children(".toggle-label").hide(); } } @@ -848,7 +848,7 @@ $(function() { var toggle = $("", {'href': 'javascript:void(0)', 'class': 'collapse-toggle'}) - .html("[]"); + .html("[\u2212]"); $(".method").each(function() { if ($(this).next().is(".docblock") || From fc9bddd1052f3f4002438d70c109dd6d69eeeba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Thu, 30 Apr 2015 00:09:46 -0400 Subject: [PATCH 2/5] Change docs toggle href from # to javascript: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So that when you click the link, the URL doesn’t get # appended to it. The non-page-global docs toggle link, which is created in `main.js`, already uses this `href` value. --- src/librustdoc/html/render.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 3d5e13f327009..55935a9063093 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1460,7 +1460,7 @@ impl<'a> fmt::Display for Item<'a> { try!(write!(fmt, "")); try!(write!(fmt, r##" - [−] + [−] "##)); // Write `src` tag From 6ce05ae6bb0e5762dee940d043feb728e5583564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Thu, 30 Apr 2015 00:25:37 -0400 Subject: [PATCH 3/5] =?UTF-8?q?Fix=20style=20warning,=20=E2=80=9Cline=20lo?= =?UTF-8?q?nger=20than=20100=20chars=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Error was noted at https://travis-ci.org/rust-lang/rust/builds/60643081#L371 I didn’t just put the content of the node on another line, because that would add spaces around the element content, messing up the JavaScript that checks what the content is. --- src/librustdoc/html/render.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 55935a9063093..ad26d25c81ae4 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1460,7 +1460,8 @@ impl<'a> fmt::Display for Item<'a> { try!(write!(fmt, "")); try!(write!(fmt, r##" - [−] + [−] "##)); // Write `src` tag From 92565b3dfbacca4b2a851758e5e9a784fc5b156e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Thu, 7 May 2015 03:53:21 -0400 Subject: [PATCH 4/5] Refactor doc toggle button label changing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To separate concerns, instead of checking the state of `#toggle-all-docs` by looking at its label text, I add or remove a class `will-expand` depending on whether the button’s next click will expand everything. (The `if` statement’s two branches were swapped as part of this change.) I moved the desired text values to a function `labelForToggleButton`, so changing the values will be easier. I also note in a comment the other file where the text is duplicated. To allow the labels of both types of toggle buttons to be uniformly set, I added a `span.inner` to the global button too. I split the template in `render.rs` into multiple lines to make room for the `span`, and that adds whitespace around the `[` and `]` text elements. That seems to be okay, though – the page still looks the same. I updated the CSS styling for `.collapse-toggle > .inner` to add a little extra space around the symbol, to make minus signs easier to identify. (`#toggle-all-docs > .inner` does not need the same style, since its text size is bigger, so it naturally puts more space around the symbol.) --- src/librustdoc/html/render.rs | 5 ++-- src/librustdoc/html/static/main.css | 2 +- src/librustdoc/html/static/main.js | 40 +++++++++++++++++++---------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ad26d25c81ae4..f7ab5fc9b0958 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1460,8 +1460,9 @@ impl<'a> fmt::Display for Item<'a> { try!(write!(fmt, "")); try!(write!(fmt, r##" - [−] + + [] + "##)); // Write `src` tag diff --git a/src/librustdoc/html/static/main.css b/src/librustdoc/html/static/main.css index b907e9e20b698..2dc5ea9906744 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 cfa599041ee2e..92fb6402e7271 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() == "[\u2212]") { - toggle.html("[+]"); - toggle.attr("title", "expand all docs"); - $(".docblock").hide(); - $(".toggle-label").show(); - $(".toggle-wrapper").addClass("collapsed"); - $(".collapse-toggle").children(".inner").html("+"); - } else { - toggle.html("[\u2212]"); + 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("\u2212"); + $(".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("+"); + 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("\u2212"); + toggle.children(".inner").text(labelForToggleButton(false)); toggle.children(".toggle-label").hide(); } } @@ -848,7 +861,8 @@ $(function() { var toggle = $("", {'href': 'javascript:void(0)', 'class': 'collapse-toggle'}) - .html("[\u2212]"); + .html("[]"); + toggle.children(".inner").text(labelForToggleButton(false)); $(".method").each(function() { if ($(this).next().is(".docblock") || From 61bb091f068f401f768b1a0e377f22bb83e4584c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rory=20O=E2=80=99Kane?= Date: Thu, 7 May 2015 04:17:10 -0400 Subject: [PATCH 5/5] Remove trailing whitespace on blank line This style inconsistency was noted at https://travis-ci.org/rust-lang/rust/builds/61583070#L371 --- src/librustdoc/html/static/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 92fb6402e7271..6a1d7bdfd8358 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -816,7 +816,7 @@ return "\u2212"; // "\u2212" is '−' minus sign } } - + $("#toggle-all-docs").on("click", function() { var toggle = $("#toggle-all-docs"); if (toggle.hasClass("will-expand")) {