-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
52 lines (43 loc) · 1.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import axeCore from 'axe-core'
import merge from 'deepmerge'
import { checkAndReport, resetCache } from './audit'
import { clear, defaultOptions, draf } from './utils'
export default function install (Vue, options = {}) {
// Browser only
if (typeof window === 'undefined') return
// merge options
options = merge(defaultOptions, options)
// set config
axeCore.configure({ ...options.config })
// register plugins
options.plugins.forEach(plugin => axeCore.registerPlugin(plugin))
// vue-axe methods in Vue Instance
Vue.prototype.$axe = {
run ({ clearConsole = options.clearConsoleOnUpdate, element, label } = {}) {
clear(clearConsole, options)
draf(() => checkAndReport(options, element, (label || 'Run manually')))
},
plugins: axeCore.plugins
}
// if false, disable automatic verification
if (!options.auto) return
function axeRun () {
const componentsName = this.$options.name || ''
resetCache()
draf(() => checkAndReport(options, this.$el, componentsName))
}
// Rechecking when updating specific component
let timeout = null
Vue.mixin({
updated () {
timeout && clearTimeout(timeout)
timeout = setTimeout(axeRun.bind(this), 2500)
},
// Used for change of route
beforeDestroy () {
clear(true, options)
}
})
// First check
setTimeout(() => draf(() => checkAndReport(options, null, 'App')), options.delay)
}