koel/resources/assets/js/directives/droppable.ts

24 lines
668 B
TypeScript
Raw Normal View History

2022-04-15 14:24:30 +00:00
import { Directive } from 'vue'
export const droppable: Directive = {
created: (el: HTMLElement, binding) => {
2022-04-25 16:38:33 +00:00
el.addEventListener('dragenter', (event: DragEvent) => {
2022-04-15 14:24:30 +00:00
event.preventDefault()
2022-07-25 12:57:58 +00:00
el.classList.add('droppable')
2022-04-15 14:24:30 +00:00
event.dataTransfer!.dropEffect = 'move'
return false
})
el.addEventListener('dragover', (event: DragEvent) => event.preventDefault())
2022-07-25 12:57:58 +00:00
el.addEventListener('dragleave', () => el.classList.remove('droppable'))
2022-04-15 14:24:30 +00:00
2022-04-25 16:38:33 +00:00
el.addEventListener('drop', (event: DragEvent) => {
2022-04-15 14:24:30 +00:00
event.preventDefault()
event.stopPropagation()
2022-07-25 12:57:58 +00:00
el.classList.remove('droppable')
binding.value(event)
2022-04-15 14:24:30 +00:00
})
}
}