Skip to content

Commit

Permalink
Catch dragenter and dragleave at capture phase. Fixes #119
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Mar 16, 2015
1 parent b5e6eca commit 5ac65bd
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions modules/backends/HTML5.js
Expand Up @@ -79,7 +79,7 @@ function handleTopDragStart(e) {
}
}

function handleTopDragEnter(e) {
function handleTopDragEnterCapture(e) {
// IE requires this to not show a nodrag icon over the container
e.preventDefault();

Expand All @@ -88,6 +88,10 @@ function handleTopDragEnter(e) {
return;
}

// It is important to try to catch these at capture phase.
// This is currently the only way to have drop zones recognize
// they're being hovered if they fill the screen completely.

if (isFileDragDropEvent(e)) {
// File dragged from outside the document
DragDropActionCreators.startDragging(NativeDragItemTypes.FILE, null);
Expand Down Expand Up @@ -117,8 +121,8 @@ function handleTopDragOver(e) {
}
}

function handleTopDragLeave(e) {
if (isDraggingNativeItem(e)) {
function handleTopDragLeaveCapture(e) {
if (isDraggingNativeItem()) {
e.preventDefault();
}

Expand Down Expand Up @@ -151,9 +155,9 @@ var HTML5 = {
}

window.addEventListener('dragstart', handleTopDragStart);
window.addEventListener('dragenter', handleTopDragEnter);
window.addEventListener('dragenter', handleTopDragEnterCapture, true);
window.addEventListener('dragleave', handleTopDragLeaveCapture, true);
window.addEventListener('dragover', handleTopDragOver);
window.addEventListener('dragleave', handleTopDragLeave);
window.addEventListener('drop', handleTopDrop);
},

Expand All @@ -163,9 +167,9 @@ var HTML5 = {
}

window.removeEventListener('dragstart', handleTopDragStart);
window.removeEventListener('dragenter', handleTopDragEnter);
window.removeEventListener('dragenter', handleTopDragEnterCapture, true);
window.removeEventListener('dragleave', handleTopDragLeaveCapture, true);
window.removeEventListener('dragover', handleTopDragOver);
window.removeEventListener('dragleave', handleTopDragLeave);
window.removeEventListener('drop', handleTopDrop);
},

Expand Down

0 comments on commit 5ac65bd

Please sign in to comment.