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(dnd): ignore non-file drag'n'drop events #1

Merged
merged 1 commit into from
Oct 18, 2017
Merged

fix(dnd): ignore non-file drag'n'drop events #1

merged 1 commit into from
Oct 18, 2017

Conversation

ramusus
Copy link
Owner

@ramusus ramusus commented Oct 18, 2017

Since we only deal with files, it makes sense to ignore all events non-file related (eg. dragging
plaintext). This commit fixes a few things that have changed in the browsers which subtly break
the current checks.

  • The contains function on dt.files has been removed from the spec and will always return
    undefined. Except for IE, which hasn't implemented the change.

  • The dt.files property always seems to be an empty array for non-drop events. Empty arrays are
    truthy, and so this will always satisfy the isValidFileDrag check before it can validate that
    the types array includes files

    • It will now only be truthy if the files array actually contains entries
  • There is a drop handler which binds to the document and always prevents all default drop
    behaviour from occurring, including things like dropping text into textfields

    • It will now only prevent default behaviour for file drops, which has the handy side-effect
      of preventing the page from navigating to the dropped file if the user misses the dropzone.

Fixes FineUploader#1588.

Brief description of the changes

{also describe what problem(s) these changes solve & reference any related issues/PRs}

What browsers and operating systems have you tested these changes on?

{example: Safari on iOS 9.1.0 and IE11 on Windows 8.1}

Have you written unit tests? If not, explain why.

{unit tests should accompany almost all PRs, unless the change is to documentation}

Since we only deal with files, it makes sense to ignore all events non-file related (eg. dragging
plaintext). This commit fixes a few things that have changed in the browsers which subtly break
the current checks.

* The `contains` function on `dt.files` has been removed from the spec and will always return
  undefined. Except for IE, which hasn't implemented the change.
  * Chrome and Firefox have replaced it with `includes`, which we now use
  * We've left a `contains` check in there for IE as a last resort
  * Remove the comment about it being Firefox only, since it also works in Chrome now
  * More info re: removal at: https://github.com/tc39/Array.prototype.includes#status

* The dt.files property always seems to be an empty array for non-drop events. Empty arrays are
  truthy, and so this will always satisfy the `isValidFileDrag` check before it can validate that
  the types array includes files
  * It will now only be truthy if the files array actually contains entries

* There is a drop handler which binds to the document and always prevents all default drop
  behaviour from occurring, including things like dropping text into textfields
  * It will now only prevent default behaviour for file drops, which has the handy side-effect
    of preventing the page from navigating to the dropped file if the user misses the dropzone.

Fixes FineUploader#1588.
@ramusus ramusus merged commit f516d0b into ramusus:develop Oct 18, 2017
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.

Fine-uploader seems to catch every drag'n'drop JS events.
2 participants