Added support for multi-drop and Safari
authorAlexander Ebert <ebert@woltlab.com>
Wed, 17 Sep 2014 10:11:39 +0000 (12:11 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 17 Sep 2014 10:11:39 +0000 (12:11 +0200)
wcfsetup/install/files/js/3rdParty/redactor/plugins/wupload.js

index 3a80b6acc07bd2813e237fe08f595c25c001d80a..c6fd016ef0bc50809c0c9f68fb0b9151ed8dd721 100644 (file)
@@ -49,7 +49,8 @@ RedactorPlugins.wupload = {
                }
                
                // IE and WebKit set 'Files', Firefox sets 'application/x-moz-file' for files being dragged
-               if (event.dataTransfer.types[0] !== 'Files' && event.dataTransfer.types[0] !== 'application/x-moz-file') {
+               // and Safari just provides 'Files' along with a huge list of other stuff
+               if (event.dataTransfer.types[0] !== 'application/x-moz-file' && event.dataTransfer.types.indexOf('Files') === -1) {
                        this._isFile = false;
                        
                        return;
@@ -152,14 +153,19 @@ RedactorPlugins.wupload = {
                
                event = event.originalEvent || event;
                
-               if (event.dataTransfer && event.dataTransfer.files.length == 1) {
+               if (event.dataTransfer && event.dataTransfer.files.length) {
                        event.preventDefault();
                        
                        // reset overlay
                        var $containerID = this.$source.wcfIdentify();
                        this._revertDropArea(undefined, $containerID);
                        
-                       WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'upload_' + $containerID, { file: event.dataTransfer.files[0] });
+                       for (var $i = 0; $i < event.dataTransfer.files.length; $i++) {
+                               var $file = event.dataTransfer.files[$i];
+                               if ($file.type) {
+                                       WCF.System.Event.fireEvent('com.woltlab.wcf.redactor', 'upload_' + $containerID, { file: $file });
+                               }
+                       }
                }
        },