-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1490,6 +1490,8 @@ function hideThemeButtonState() { | |
searchState.setup(); | ||
}()); | ||
|
||
let reset_button_timeout; | ||
|
||
function copy_path(but) { | ||
var parent = but.parentElement; | ||
var path = []; | ||
|
@@ -1513,4 +1515,12 @@ function copy_path(but) { | |
document.body.removeChild(el); | ||
|
||
but.textContent = '✓'; | ||
|
||
window.clearTimeout(reset_button_timeout); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't error the first time: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout#notes. |
||
|
||
function reset_button() { | ||
but.textContent = '⎘'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please reset |
||
} | ||
|
||
reset_button_timeout = window.setTimeout(reset_button, 1000); | ||
} |
There was a problem hiding this comment.
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 thereset_button_timeout
declaration there.Another thing: even though it's valid to send an undefined variable to
clearTimeout
, please initialize your value tonull
and check it before callingclearTimeout
.