Skip to content

Commit

Permalink
feat: Adding option to register and execute plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ktquez committed May 12, 2020
1 parent a9e0323 commit fb21d52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface VueAxe
{
run({ clearConsole, element }: RunOptions): void;

plugins: Record<object>;

clearConsole(forceClear: boolean): void;

debounce(): void;
Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,25 @@ export default function install (Vue, options) {
minor: 'padding:2px 4px;border-radius:5px;background-color:#333;color:#FFCE85;font-weight:normal;',
title: 'font-color:black;font-weight:bold;',
url: 'font-color:#4D4D4D;font-weight:normal;'
}
},
plugins: []
}

options = merge(defaultOptions, options)

axeCore.configure({ ...options.config })

// register plugins
options.plugins.forEach(plugin => axeCore.registerPlugin(plugin))

// vue-axe methods in Vue Instance
Vue.prototype.$axe = {
run ({ clearConsole = true, element = document } = {}) {
this.clearConsole(clearConsole)
if (!clearConsole) resetLastNotification()
Vue.nextTick().then(() => checkAndReport(options, element))
},
plugins: axeCore.plugins,
clearConsole (forceClear = false) {
resetCache()

Expand All @@ -54,10 +60,12 @@ export default function install (Vue, options) {
}, 1000, { maxWait: 5000 })
}

// Rechecking when updating specific component
Vue.mixin({
updated () {
this.$axe.debounce()
},
// Used for change of route
beforeDestroy () {
this.$axe.clearConsole(true)
}
Expand Down

0 comments on commit fb21d52

Please sign in to comment.