File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 1
1
; ( function ( ) {
2
2
'use strict'
3
3
4
+ if ( ! window . navigator . clipboard ) return
5
+
6
+ var HEADING_RX = / H [ 2 - 6 ] /
7
+
4
8
var pageSpec = ( document . querySelector ( 'head meta[name=page-spec]' ) || { } ) . content
5
9
var editPageLink = document . querySelector ( '.toolbar .edit-this-page a' )
6
10
if ( ! ( pageSpec && editPageLink ) ) return
7
11
if ( editPageLink ) editPageLink . addEventListener ( 'click' , onEditPageLinkClick )
8
12
; [ ] . slice . call ( document . querySelectorAll ( '.doc a.anchor' ) ) . forEach ( function ( anchor ) {
9
- if ( / H [ 2 - 6 ] / . test ( anchor . parentNode . tagName ) ) anchor . addEventListener ( 'click' , onSectionAnchorClick . bind ( anchor ) )
13
+ if ( HEADING_RX . test ( anchor . parentNode . tagName ) ) anchor . addEventListener ( 'click' , onSectionAnchorClick . bind ( anchor ) )
10
14
} )
11
15
12
16
function onEditPageLinkClick ( e ) {
13
- if ( e . altKey ) navigator . clipboard . writeText ( pageSpec )
17
+ if ( e . altKey ) writeToClipboard ( pageSpec )
14
18
}
15
19
16
20
function onSectionAnchorClick ( e ) {
17
21
if ( e . altKey ) {
18
22
e . preventDefault ( )
19
- navigator . clipboard . writeText ( pageSpec + decodeFragment ( this . hash ) )
23
+ writeToClipboard ( pageSpec + decodeFragment ( this . hash ) )
20
24
}
21
25
}
22
26
23
27
function decodeFragment ( hash ) {
24
28
return ~ hash . indexOf ( '%' ) ? decodeURIComponent ( hash ) : hash
25
29
}
30
+
31
+ function writeToClipboard ( text ) {
32
+ window . navigator . clipboard . writeText ( text ) . then ( function ( ) { } , function ( ) { } )
33
+ }
26
34
} ) ( )
You can’t perform that action at this time.
0 commit comments