Skip to content

Fix doc [−] button bug by escaping differently #24973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 7, 2015

Conversation

roryokane
Copy link
Contributor

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 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.

The cause of the problem is described here: rust-lang#24797 (comment) .

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.
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.
@rust-highfive
Copy link
Contributor

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

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.
@Gankra
Copy link
Contributor

Gankra commented Apr 30, 2015

Could this be factored out to MINUS and PLUS vars just because \uwhatever is completely opaque?

@@ -1460,7 +1460,8 @@ 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">[&#x2212;]</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I suppose this interferes with having a single uniform declaration of this :/

@Gankra Gankra assigned Gankra and unassigned nikomatsakis Apr 30, 2015
@Gankra
Copy link
Contributor

Gankra commented Apr 30, 2015

Alternatively, this might be a good time to simply replace (my? probably mine...) janky logic with something more robust. One option, I believe, would be to instead mark these with classes and have the rendering specified with CSS's content(). Then all logic can be done based on simple classes and rendering can be specified in one location.

@Gankra
Copy link
Contributor

Gankra commented Apr 30, 2015

Proof of concept seems to work: https://jsfiddle.net/gh388tjc/

@roryokane
Copy link
Contributor Author

A slightly more realistic version of the proof of concept: https://jsfiddle.net/roryokane/669csde1/

I think that approach – just setting the button’s class, and specifying its rendering only in CSS – won’t work. CSS can’t change the title attribute of an element, so the button will keep saying “collapse all docs” even when it is in the ‘[+]’ state.

But I agree that it would be nice to consolidate rendering as much as possible. It would also be nice to look at the element’s class to determine its current state, instead of examining its content with toggle.html() == "[\u2212]".

@roryokane
Copy link
Contributor Author

There is also an inconsistency in the button rendering that should be fixed. Individual-element buttons surround the inner symbol with span.inner, while the toggle-all button puts it in the same text element as the [].

The inner element’s purpose seems only to work around the different widths of the hyphen and plus sign by making them display as the same width using CSS. Now that the proper symbols are used, inner can be removed completely, for simplicity. That would make the button-label-setting code the same for both types of buttons.

But perhaps all this refactoring should be delayed to another issue. The collapse button is broken right now, and this fix works, and at least doesn’t make the code quality any worse.

@Gankra
Copy link
Contributor

Gankra commented Apr 30, 2015

I think I'd only really support either a proper solution to the problem or a revert of the problematic commit.

@alexcrichton
Copy link
Member

@roryokane would you be ok implementing the class-based approach here? You probably won't be able to use toggleClass anyway so having separate logic in each branch (to e.g. change title) seems plausible.

@roryokane
Copy link
Contributor Author

Sure, I will change the button code to check for a class instead of just checking its text content.

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.)
@roryokane
Copy link
Contributor Author

I have implemented and tested the requested refactoring. Details are in the commit message:

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.)

@alexcrichton
Copy link
Member

@bors: r+ 61bb091 p=1

Thanks!

@bors
Copy link
Collaborator

bors commented May 7, 2015

⌛ Testing commit 61bb091 with merge f0ac7e0...

bors added a commit that referenced this pull request May 7, 2015
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.
@bors
Copy link
Collaborator

bors commented May 7, 2015

💔 Test failed - auto-mac-64-nopt-t

@alexcrichton
Copy link
Member

@bors: retry

On Thu, May 7, 2015 at 11:33 AM, bors [email protected] wrote:

[image: 💔] Test failed - auto-mac-64-nopt-t
http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/4883


Reply to this email directly or view it on GitHub
#24973 (comment).

@bors
Copy link
Collaborator

bors commented May 7, 2015

@bors
Copy link
Collaborator

bors commented May 7, 2015

@bors bors merged commit 61bb091 into rust-lang:master May 7, 2015
@roryokane roryokane deleted the fix-minus-doc-buttons branch May 7, 2015 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants