mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
37 lines
940 B
JavaScript
37 lines
940 B
JavaScript
import Vue from 'vue'
|
|
|
|
export default ({ app }) => {
|
|
Vue.directive('focus', {
|
|
// When the bound element is inserted into the DOM...
|
|
inserted: (el, binding) => {
|
|
// Focus the element
|
|
Vue.nextTick(() => {
|
|
if (binding.value !== false) {
|
|
const target = el instanceof HTMLInputElement ? el : el.querySelector('input')
|
|
if (target) {
|
|
target.focus()
|
|
}
|
|
}
|
|
})
|
|
},
|
|
})
|
|
|
|
Vue.directive('router-link', {
|
|
bind: (el, binding) => {
|
|
binding.clickEventListener = (e) => {
|
|
if (!e.metaKey && !e.ctrlKey) {
|
|
e.preventDefault()
|
|
app.router.push(el.getAttribute('href'))
|
|
}
|
|
}
|
|
el.addEventListener('click', binding.clickEventListener)
|
|
},
|
|
unbind: (el, binding) => {
|
|
// cleanup
|
|
if (binding.clickEventListener) {
|
|
el.removeEventListener('click', binding.clickEventListener)
|
|
}
|
|
},
|
|
})
|
|
}
|