2021-10-20 10:59:36 +08:00
|
|
|
let target
|
2021-10-20 01:11:27 +08:00
|
|
|
|
2021-10-20 10:59:36 +08:00
|
|
|
function clearTarget () {
|
|
|
|
if (!target) {
|
|
|
|
return
|
|
|
|
}
|
2021-10-20 01:11:27 +08:00
|
|
|
|
2021-10-20 10:59:36 +08:00
|
|
|
delete target.dataset.target
|
|
|
|
}
|
|
|
|
|
2021-10-21 14:40:06 +08:00
|
|
|
export default ({ app, route }) => {
|
2021-10-20 10:59:36 +08:00
|
|
|
document.documentElement.addEventListener('click', clearTarget)
|
2021-10-20 01:11:27 +08:00
|
|
|
|
|
|
|
app.router.afterEach(to => {
|
2021-10-20 10:59:36 +08:00
|
|
|
clearTarget()
|
|
|
|
|
2021-10-20 01:11:27 +08:00
|
|
|
if (!to.hash) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
const selector = decodeURIComponent(to.hash)
|
|
|
|
const anchor = document.querySelector(selector)
|
2021-10-21 18:38:51 +08:00
|
|
|
if (!anchor) {
|
|
|
|
return
|
|
|
|
}
|
2021-10-20 01:11:27 +08:00
|
|
|
|
|
|
|
if (anchor.tagName === 'CODE') {
|
|
|
|
target = anchor.closest('tr')
|
2021-10-21 14:40:06 +08:00
|
|
|
} else if (route.name === 'changelog' && anchor.tagName === 'H2') {
|
|
|
|
target = anchor.closest('.version-item')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (target) {
|
2021-10-20 01:11:27 +08:00
|
|
|
target.dataset.target = ''
|
|
|
|
}
|
|
|
|
}, 0)
|
|
|
|
})
|
|
|
|
}
|