Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Safari drag&drop functionality when cancelling dragover event in parent element #458

Closed
wants to merge 1 commit into from

Conversation

gonchuki
Copy link
Contributor

At least on Safari Windows, if you cancel the dragover event on any parent element of the droppable area (to prevent the browser from opening a file that was dropped outside of our designated area), then Safari completely ignores the drop action. (nothing happens at all)

This patch has been on our production code for at least 4 months so I would say it's quite safe for merging. Not sure if anyone should actually depend on this event bubbling up on the DOM, we don't use the built-in queue plugin so let me know if this patch is no good.

…ent.body (or any parent element of the droppable area)
@j-manu
Copy link

j-manu commented Mar 30, 2012

How did you actually cancel the event? I tried capturing the event and calling preventDefault, by adding a listener to "body" but the browser (FF) opens the image if it is dropped outside the drop zone. The event on body does not seem to fire.
Since the user can drop the file anywhere, body seemed the only logical place to trap all drops but it is not working out :(

@gonchuki
Copy link
Contributor Author

if (document.body.addEventListener) {
  document.body.addEventListener('dragover', function (e) { if (e.dataTransfer && (Array.prototype.indexOf.call(e.dataTransfer.types, 'Files') !== -1)) e.dataTransfer.dropEffect = 'none'; e.preventDefault(); }, false);
  document.body.addEventListener('drop', function (e) { e.preventDefault(); }, false);
}

short explanation:

  • you need to prevent both drop and dragover for this to work
  • you only want to prevent users from dropping files, dragging and dropping text into forms should still be accepted, thus that's why I check on e.dataTransfer
  • the drop effect thing changes the cursor to the "forbidden" one.

@NeoXidizer
Copy link

gonchuki, thank you very much for this fix!
P.S. this code also breaks the latest safari on Windows

$('#dropZone').bind('dragover', function(e){
    $(this).addClass('hover');return 0;
});

jayarjo pushed a commit that referenced this pull request Feb 24, 2013
…ent.body (or any parent element of the droppable area). Close #458.
@jayarjo
Copy link
Contributor

jayarjo commented Feb 24, 2013

In Plupload 2 we've now removed the whole fakeSafariDragDrop thing.

@jayarjo jayarjo closed this Feb 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants