8
0
Эх сурвалжийг харах

Allowed multiple files to be selected from file dialog.

Szymon Kupś 8 жил өмнө
parent
commit
65b90af2e6

+ 2 - 1
packages/ckeditor5-upload/src/imageupload.js

@@ -40,7 +40,8 @@ export default class ImageUpload extends Plugin {
 				label: t( 'Insert image' ),
 				label: t( 'Insert image' ),
 				icon: imageIcon,
 				icon: imageIcon,
 				tooltip: true,
 				tooltip: true,
-				acceptedType: 'image/*'
+				acceptedType: 'image/*',
+				allowMultipleFiles: true
 			} );
 			} );
 
 
 			view.on( 'done', ( evt, files ) => {
 			view.on( 'done', ( evt, files ) => {

+ 19 - 1
packages/ckeditor5-upload/src/ui/filedialogbuttonview.js

@@ -44,6 +44,15 @@ export default class FileDialogButtonView extends ButtonView {
 		 */
 		 */
 		this.fileInputView.bind( 'acceptedType' ).to( this, 'acceptedType' );
 		this.fileInputView.bind( 'acceptedType' ).to( this, 'acceptedType' );
 
 
+		/**
+		 * Indicates if multiple files can be selected. Defaults to `true`.
+		 *
+		 * @observable
+		 * @member {Boolean} #allowMultipleFiles
+		 */
+		this.set( 'allowMultipleFiles', false );
+		this.fileInputView.bind( 'allowMultipleFiles' ).to( this, 'allowMultipleFiles' );
+
 		/**
 		/**
 		 * Fired when file dialog is closed with file selected.
 		 * Fired when file dialog is closed with file selected.
 		 *
 		 *
@@ -99,6 +108,14 @@ class FileInputView extends View {
 		 */
 		 */
 		this.set( 'acceptedType' );
 		this.set( 'acceptedType' );
 
 
+		/**
+		 * Indicates if multiple files can be selected. Defaults to `false`.
+		 *
+		 * @observable
+		 * @member {Boolean} #allowMultipleFiles
+		 */
+		this.set( 'allowMultipleFiles', false );
+
 		const bind = this.bindTemplate;
 		const bind = this.bindTemplate;
 
 
 		this.template = new Template( {
 		this.template = new Template( {
@@ -110,7 +127,8 @@ class FileInputView extends View {
 				],
 				],
 				type: 'file',
 				type: 'file',
 				tabindex: '-1',
 				tabindex: '-1',
-				accept: bind.to( 'acceptedType' )
+				accept: bind.to( 'acceptedType' ),
+				multiple: bind.to( 'allowMultipleFiles' )
 			},
 			},
 
 
 			on: {
 			on: {

+ 6 - 0
packages/ckeditor5-upload/tests/ui/filedialogbuttonview.js

@@ -46,6 +46,12 @@ describe( 'FileDialogButtonView', () => {
 		expect( view.fileInputView.acceptedType ).to.equal( 'audio/*' );
 		expect( view.fileInputView.acceptedType ).to.equal( 'audio/*' );
 	} );
 	} );
 
 
+	it( 'should pass allowMultipleFiles to input view', () => {
+		view.set( { allowMultipleFiles: true } );
+
+		expect( view.fileInputView.allowMultipleFiles ).to.be.true;
+	} );
+
 	it( 'should delegate input view done event', ( done ) => {
 	it( 'should delegate input view done event', ( done ) => {
 		const files = [];
 		const files = [];