Add support for acceptable types to WoltLabSuite/Core/Upload
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 30 Jun 2020 09:26:46 +0000 (11:26 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 30 Jun 2020 09:28:59 +0000 (11:28 +0200)
see #3414

wcfsetup/install/files/js/WoltLabSuite/Core/Upload.js

index 4b0254c85ada97e558748c04164fa5bd241ab05a..0b03a829f9b937341ec87958a0cef9eb2175cb2d 100644 (file)
@@ -44,6 +44,8 @@ define(['AjaxRequest', 'Core', 'Dom/ChangeListener', 'Language', 'Dom/Util', 'Do
                        action: 'upload',
                        // is true if multiple files can be uploaded at once
                        multiple: false,
+                       // array of accepted file types, null if any file type is allowed
+                       acceptableFiles: null,
                        // name if the upload field
                        name: '__files[]',
                        // is true if every file from a multi-file selection is uploaded in its own request
@@ -89,6 +91,9 @@ define(['AjaxRequest', 'Core', 'Dom/ChangeListener', 'Language', 'Dom/Util', 'Do
                        if (this._options.multiple) {
                                elAttr(this._fileUpload, 'multiple', 'true');
                        }
+                       if (this._options.acceptableFiles !== null) {
+                               elAttr(this._fileUpload, 'accept', this._options.acceptableFiles.join(','));
+                       }
                        this._fileUpload.addEventListener('change', this._upload.bind(this));
                        
                        this._button = elCreate('p');