ProgerXP / FileDrop

Self-contained cross-browser pure JavaScript class for Drag & Drop and AJAX (multi) file upload.
filedropjs.org
The Unlicense
264 stars 61 forks source link

Can we get Some Compatibility Variables? #27

Closed matrad closed 9 years ago

matrad commented 9 years ago

Is it possible to check if File Drag & Drop is supported or if we're sending via iFrame callback?

Does there exist a global Info Var? I didn't found anything in the documentation

ProgerXP commented 9 years ago

FileDrop doesn't assume anything about browser capabilities. It sets all things up as if it supports both drag & drop and iframe. Once an event occurs FileDrop uses the corresponding mechanism to send the file.

This means that you can't determine what method FileDrop will use beforehand unless you manually check user agent or use some other tentative techniques. This also means that if user clicks on the drop zone, triggers file open dialog and this triggers iframe upload - this doesn't mean that the browser doesn't support drag & drop, it merely means the user has chosen not to drop the file but to select it in the dialog.

However, if the user does drag & drop and it works - you can be sure that the browser supports both methods.

If checking these capabilities when the event occurs works for you then you can do something like this:

myfiledrop.preview('upload', function (e) {
  if (this.eventFiles(e, true)) {
    alert('Will use AJAX to upload')
  } else {
    alert('Will fall back to IFrame upload')
  }
})
barneycarroll commented 9 years ago

I think it's wise for FileDrop to only expose this stuff in context at execution time. If you have other code that hinges on drag & drop support, you should make that assertion without relying on FileDrop's API (even if FileDrop's implementation details are also contingent on the same thing). Personally I would use Modernizr.

ProgerXP commented 9 years ago

To add to @barneycarroll's answer, if you specifically need drag & drop upload then you are better off disabling iframe as described in the docs. This gives you great flexibility (you can turn any element into a drop zone and style it) and you can forget about legacy stuff. So far only IE 10 and before is a problem.

matrad commented 9 years ago

Ok, that makes sense. What I wanted to display a different text when using the fallback method in the guy to tell that drag & drog support is not available.

But may there a Bug in the current Version? Because on IE<10 the Drag & Drop support is enabled, it only stops when setting the Global isIE9 to true manually. Otherwise it sends a POST Request with no data.

window.fd = {isIE9: true};

This I read on the main Page:

Disabled drag & drop for Internet Explorer 10 and below — even if they fire ondrop they actually send empty POST body upon submission. Regular