@@ -3,27 +3,41 @@ function formatCrateName(crateTitleAndVersion) {
3
3
return stringParts [ 0 ] + ' = "' + stringParts [ 1 ] + '"' ;
4
4
}
5
5
6
- function copyTextHandler ( ) {
7
- const crateTitleAndVersion = document . getElementById ( "crate-title" ) ;
8
- // On rustdoc pages, we use `textTransform: uppercase`, which copies as uppercase.
9
- // To avoid that, reset the styles temporarily.
10
- const oldTransform = crateTitleAndVersion . style . textTransform ;
11
- crateTitleAndVersion . style . textTransform = "none" ;
12
- const temporaryInput = document . createElement ( "input" ) ;
13
-
14
- temporaryInput . type = "text" ;
15
- temporaryInput . value = formatCrateName ( crateTitleAndVersion . innerText ) ;
16
-
17
- document . body . append ( temporaryInput ) ;
18
- temporaryInput . select ( ) ;
19
- document . execCommand ( "copy" ) ;
20
-
21
- temporaryInput . remove ( ) ;
22
- crateTitleAndVersion . style . textTransform = oldTransform ;
23
- }
24
-
25
6
( function ( ) {
26
7
const clipboard = document . getElementById ( "clipboard" ) ;
8
+ let resetClipboardTimeout = null ;
9
+ let resetClipboardIcon = clipboard . innerHTML ;
10
+
11
+ function resetClipboard ( ) {
12
+ resetClipboardTimeout = null ;
13
+ clipboard . innerHTML = resetClipboardIcon ;
14
+ }
15
+
16
+ function copyTextHandler ( ) {
17
+ const crateTitleAndVersion = document . getElementById ( "crate-title" ) ;
18
+ // On rustdoc pages, we use `textTransform: uppercase`, which copies as uppercase.
19
+ // To avoid that, reset the styles temporarily.
20
+ const oldTransform = crateTitleAndVersion . style . textTransform ;
21
+ crateTitleAndVersion . style . textTransform = "none" ;
22
+ const temporaryInput = document . createElement ( "input" ) ;
23
+
24
+ temporaryInput . type = "text" ;
25
+ temporaryInput . value = formatCrateName ( crateTitleAndVersion . innerText ) ;
26
+
27
+ document . body . append ( temporaryInput ) ;
28
+ temporaryInput . select ( ) ;
29
+ document . execCommand ( "copy" ) ;
30
+
31
+ temporaryInput . remove ( ) ;
32
+ crateTitleAndVersion . style . textTransform = oldTransform ;
33
+
34
+ clipboard . textContent = "✓" ;
35
+ if ( resetClipboardTimeout !== null ) {
36
+ clearTimeout ( resetClipboardTimeout ) ;
37
+ }
38
+ resetClipboardTimeout = setTimeout ( resetClipboard , 1000 ) ;
39
+ }
40
+
27
41
if ( clipboard != null ) clipboard . addEventListener ( "click" , copyTextHandler ) ;
28
42
for ( const e of document . querySelectorAll ( 'a[data-fragment="retain"]' ) ) {
29
43
e . addEventListener ( 'mouseover' , ( ) => e . hash = document . location . hash ) ;
0 commit comments