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