@@ -3,34 +3,34 @@ import { scrollTargetIntoView } from '~/utils'
3
3
4
4
// --- Utility methods ---
5
5
6
- // Convert local links to router push or scrollIntoView
6
+ // Convert local links to router push or scroll target into view
7
7
const linkToRouter = event => {
8
8
if ( ! event || event . type !== 'click' ) {
9
9
return
10
10
}
11
- const target = event . target && event . target . closest ? event . target . closest ( 'a[href]' ) : null
11
+ const $target = event . target && event . target . closest ? event . target . closest ( 'a[href]' ) : null
12
+ // Early exit if click inside an example, not a link,
13
+ // or default prevented or is a Vue instance
12
14
if (
13
- ! target ||
15
+ ! $ target ||
14
16
event . type !== 'click' ||
15
- target . __vue__ ||
16
- target . closest ( '.bd-example' ) ||
17
- target . closest ( 'pre' ) ||
17
+ $ target. __vue__ ||
18
+ $ target. closest ( '.bd-example' ) ||
19
+ $ target. closest ( 'pre' ) ||
18
20
event . defaultPrevented
19
21
) {
20
- // Early exit if click inside an example, not a link, or
21
- // default prevented or is a Vue instance
22
22
return
23
23
}
24
- const href = target . getAttribute ( 'href' )
24
+ const href = $ target. getAttribute ( 'href' )
25
25
if ( href && href . indexOf ( '/' ) === 0 && href . indexOf ( '//' ) !== 0 ) {
26
- // if local page-to-page-docs link, convert click to `$router.push()`
26
+ // If local page-to-page-docs link, convert click to `$router.push()`
27
27
event . preventDefault ( )
28
28
if ( typeof window !== 'undefined' && window . $nuxt ) {
29
- // Since we are a functional component, we can't use this.$router
29
+ // Since we are a functional component, we can't use ` this.$router`
30
30
window . $nuxt . $router . push ( href )
31
31
}
32
32
} else if ( href && href . indexOf ( '#' ) === 0 ) {
33
- // In page anchor link, so use scrollIntoView utility method
33
+ // In page anchor link, so use `scrollTargetIntoView` utility method
34
34
scrollTargetIntoView ( event , href )
35
35
}
36
36
// Else, normal browser link handling (i.e. external links)
0 commit comments