mirror of
https://github.com/koel/koel
synced 2024-12-25 20:13:06 +00:00
30 lines
811 B
TypeScript
30 lines
811 B
TypeScript
import { Directive } from 'vue'
|
|
import { $ } from '@/utils'
|
|
|
|
export const droppable: Directive = {
|
|
created: (el: HTMLElement, binding) => {
|
|
const acceptsDrops = binding.arg === undefined || Boolean(binding.arg)
|
|
|
|
if (!acceptsDrops) {
|
|
return
|
|
}
|
|
|
|
el.addEventListener('dragenter', (event: DragEvent) => {
|
|
event.preventDefault()
|
|
$.addClass(el, 'droppable')
|
|
event.dataTransfer!.dropEffect = 'move'
|
|
|
|
return false
|
|
})
|
|
|
|
el.addEventListener('dragover', (event: DragEvent) => event.preventDefault())
|
|
el.addEventListener('dragleave', () => $.removeClass(el, 'droppable'))
|
|
|
|
el.addEventListener('drop', (event: DragEvent) => {
|
|
event.preventDefault()
|
|
event.stopPropagation()
|
|
$.removeClass(el, 'droppable')
|
|
binding.value(event)
|
|
})
|
|
}
|
|
}
|