Skip to content

Reset the docs' copy path button after 1 second #84740

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 3 commits into from
May 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,8 @@ function hideThemeButtonState() {
searchState.setup();
}());

let reset_button_timeout;
Copy link
Member

Choose a reason for hiding this comment

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

I really don't like global variables like this. Instead, please wrap copy_path into an anonymous function like we do in multiple places here and move the reset_button_timeout declaration there.

Another thing: even though it's valid to send an undefined variable to clearTimeout, please initialize your value to null and check it before calling clearTimeout.


function copy_path(but) {
var parent = but.parentElement;
var path = [];
Expand All @@ -1513,4 +1515,12 @@ function copy_path(but) {
document.body.removeChild(el);

but.textContent = '✓';

window.clearTimeout(reset_button_timeout);
Copy link
Contributor Author

Choose a reason for hiding this comment

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


function reset_button() {
but.textContent = '⎘';
Copy link
Member

Choose a reason for hiding this comment

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

Please reset reset_button_timeout to null in here.

}

reset_button_timeout = window.setTimeout(reset_button, 1000);
}