File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -23,26 +23,28 @@ export default {
23
23
this .init ()
24
24
},
25
25
26
+ beforeDestroy () {
27
+ window .removeEventListener (' hashchange' , this .handleFocusElement , false )
28
+ },
29
+
26
30
methods: {
27
31
init () {
28
- window .addEventListener (' hashchange' , () => {
29
- this . focusElement (location .hash . substring (1 ))
30
- }, false )
32
+ window .addEventListener (' hashchange' , this . handleFocusElement , false )
33
+ if (location .hash && location . hash . substring (1 )) this . handleFocusElement ( )
34
+ },
31
35
32
- if (location .hash && location .hash .substring (1 )) {
33
- this .focusElement (location .hash .substring (1 ))
34
- }
36
+ handleFocusElement () {
37
+ this .focusElement (location .hash .substring (1 ))
35
38
},
36
39
37
40
focusElement (id ) {
38
41
if (! id) return
39
42
const element = window .document .getElementById (id)
40
- if (element) {
41
- if (! / ^ (a| select| input| button| textarea)/ i .test (element .tagName .toLowerCase ())) {
42
- element .setAttribute (' tabindex' , - 1 )
43
- }
44
- element .focus ()
43
+ if (! element) return
44
+ if (! / ^ (a| select| input| button| textarea)/ i .test (element .tagName .toLowerCase ())) {
45
+ element .setAttribute (' tabindex' , - 1 )
45
46
}
47
+ element .focus ()
46
48
}
47
49
}
48
50
}
Original file line number Diff line number Diff line change 1
- import VueSkipTo from './skip-to .vue'
1
+ import VueSkipTo from './VueSkipTo .vue'
2
2
3
3
export default function install ( Vue ) {
4
+ if ( install . installed ) return
5
+ install . installed = true
4
6
Vue . component ( 'VueSkipTo' , VueSkipTo )
5
7
}
6
8
You can’t perform that action at this time.
0 commit comments