Skip to content
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

Move global click handlers to per-element ones. #85117

Merged
merged 1 commit into from
May 12, 2021

Conversation

jsha
Copy link
Contributor

@jsha jsha commented May 9, 2021

In rustdoc's main.js, we had an onclick handler for the whole document that would dispatch to handlers for various elements. This change attaches the handlers to the elements that trigger them, instead. This simplifies the code and avoids reimplementing the browser's bubbling functionality.

As part of this change, change from a class to an id for help button.

Move the handlers and associated code for highlighting source lines into source-script.js (and factor out a shared regex).

Demo at https://hoffman-andrews.com/rust/bubble-bubble-toil-and-trouble/std/string/struct.String.html

Note: this conflicts with / depends on #85074. Once that's merged I'll rebase this and resolve conflicts.

Part of #83332. Thanks to @Manishearth for the suggestion to not reimplement bubbling.

r? @GuillaumeGomez

@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 9, 2021
@bors
Copy link
Contributor

bors commented May 10, 2021

☔ The latest upstream changes (presumably #85074) made this pull request unmergeable. Please resolve the merge conflicts.

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented May 10, 2021

The source code pages are completely broken too (both the line numbers and the display).

You also forgot to update this line:

onEachLazy(document.getElementsByClassName("line-numbers"), function(e) {

I think a few others might be missing too.

@GuillaumeGomez
Copy link
Member

Also, that might conflict with #85148

@Manishearth
Copy link
Member

Thanks for working on this!

@jsha jsha force-pushed the bubble-bubble-toil-and-trouble branch from 6c26bd5 to b120726 Compare May 10, 2021 22:18
@jsha
Copy link
Contributor Author

jsha commented May 10, 2021

Rebased on latest master and fixed the review issues. I also wound up moving the handlers for source line highlighting into source-script.js. Updated the PR description, commit description, and demo.

@@ -1,3 +1,4 @@
(function() {
Copy link
Member

Choose a reason for hiding this comment

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

Nice! Could you move the eslint comments at the top please? Makes it easier to read.

Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

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

Just one last nit and then it's good to go. Thanks a lot for this improvement!

@jsha jsha force-pushed the bubble-bubble-toil-and-trouble branch from b120726 to 33d929c Compare May 11, 2021 17:52
@@ -105,7 +105,7 @@ crate fn render<T: Print, S: Print>(
placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \
type=\"search\">\
</div>\
<button type=\"button\" class=\"help-button\">?</button>
<button type=\"button\" id=\"help-button\">?</button>
Copy link
Member

@GuillaumeGomez GuillaumeGomez May 11, 2021

Choose a reason for hiding this comment

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

Please add this ID into init_id_map (we should really write a tidy check for that, gonna do that tomorrow).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What does the IdMap do?

Copy link
Member

Choose a reason for hiding this comment

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

When we generate IDs for anchors, we check this map to ensure that the ID doesn't already exists, otherwise, we add a -X (where X is a number) to avoid duplicates. It's also used (well, at least by me) to check that the ID doesn't already exist when I create a new one in some new HTML part. :)

In rustdoc's main.js, we had an onclick handler for the whole document
that would dispatch to handlers for various elements. This change
attaches the handlers to the elements that trigger them, instead.
This simplfies the code and avoids reimplementing the browser's bubbling
functionality.

As part of this change, change from a class to an id for help button.

Move the handlers and associated code for highlighting source lines into
source-script.js (and factor out a shared regex).
@jsha jsha force-pushed the bubble-bubble-toil-and-trouble branch from 33d929c to 0945451 Compare May 11, 2021 21:24
@GuillaumeGomez
Copy link
Member

Thanks!

@bors: r+

@bors
Copy link
Contributor

bors commented May 12, 2021

📌 Commit 0945451 has been approved by GuillaumeGomez

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 12, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request May 12, 2021
…laumeGomez

Rollup of 5 pull requests

Successful merges:

 - rust-lang#84793 (Recover from invalid `struct` item syntax)
 - rust-lang#85117 (Move global click handlers to per-element ones.)
 - rust-lang#85141 (Update documentation for SharedContext::maybe_collapsed_doc_value)
 - rust-lang#85174 (Fix border radius for doc code blocks in rustdoc)
 - rust-lang#85205 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 90f6fe8 into rust-lang:master May 12, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 12, 2021
@jsha jsha deleted the bubble-bubble-toil-and-trouble branch May 12, 2021 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants