BrightspaceUILabs / file-uploader

Polymer-based web component for D2L file uploader
Apache License 2.0
4 stars 6 forks source link

Only style the drop-zone if the dragged content contains a file. #23

Open dbatiste opened 7 years ago

dbatiste commented 7 years ago

See animated GIF below for current behavior - it's possible to drag & drop other things besides files, and we should only apply the valid drop-zone styles if the dragged content contains a file. I think this can be achievable with something like the following snippet (this is existing behavior from the LMS MVC FileDrop behavior code... copied almost verbatim).

var isFileDropValid = function( evt ) {
   if ( !isUploading && evt.dataTransfer != null  && evt.dataTransfer.types != null ) {

      var dataTypes = evt.dataTransfer.types;
      for( var i=0; i<dataTypes.length; i++ ) {
         // Correcting a bizarre error where FF allows you to drag all the things
         if( dataTypes[i] == 'application/x-moz-file-promise' ) {
            return false;
         }
         if ( dataTypes[i] == 'Files' ) {
            return true;
         }
      }

   }
   return false;
};

It looks like the current __onDrop method in d2l-file-uploader contains similar logic - I think its validation logic should be factored out (and possibly changed a little) into a separate method, and called from other drag events.

non-file-file-upload