Created
May 3, 2019 18:26
-
-
Save yosukehasumi/dbe0f45c9742a5d2350b351a6b03290f to your computer and use it in GitHub Desktop.
Drag Event handler class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.DragEventHandler = (containers) -> | |
focused = false | |
this.windowDragoverOn = -> | |
unless focused | |
focused = true | |
for container in containers | |
container.classList.add('window-dragover') | |
this.windowDragoverOff = -> | |
if focused | |
focused = false | |
for container in containers | |
container.classList.remove('window-dragover') | |
addEvent = (obj, evt, fn) -> | |
if obj.addEventListener | |
obj.addEventListener(evt, fn, false) | |
else if obj.attachEvent | |
obj.attachEvent("on" + evt, fn) | |
this.init = -> | |
addEvent window, 'dragover', (event) => | |
event = event ? event : window.event | |
event.preventDefault() | |
this.windowDragoverOn() | |
addEvent window, 'drop', (event) => | |
event = event ? event : window.event | |
event.preventDefault() | |
this.windowDragoverOff() | |
addEvent document, 'mouseout', (event) => | |
event = event ? event : window.event | |
from = event.relatedTarget || event.toElement | |
if (!from || from.nodeName == "HTML") | |
this.windowDragoverOff() | |
this.init() | |
return this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment