Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #48 from ckeditor/t/35
Browse files Browse the repository at this point in the history
Fix: [Safari, Edge] The image upload (button) feature will not throw an error anymore when trying to access picked files. The feature should not use `for...of` loop on native `FileList` because Safari and Edge do not support `Symbol.iterator` for it yet. Closes #35.
  • Loading branch information
Reinmar authored Aug 15, 2017
2 parents fa2c7ad + 4815fd1 commit f4efd9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/imageuploadbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class ImageUploadButton extends Plugin {
view.bind( 'isEnabled' ).to( command );

view.on( 'done', ( evt, files ) => {
for ( const file of files ) {
for ( const file of Array.from( files ) ) {
const insertAt = findOptimalInsertionPosition( editor.document.selection );

if ( isImageType( file ) ) {
Expand Down
14 changes: 14 additions & 0 deletions tests/imageuploadbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,19 @@ describe( 'ImageUploadButton', () => {
button.fire( 'done', [ file ] );
sinon.assert.notCalled( executeStub );
} );

it( 'should work even if the FileList does not support iterators', () => {
const executeStub = sinon.stub( editor, 'execute' );
const button = editor.ui.componentFactory.create( 'insertImage' );
const files = {
0: createNativeFileMock(),
length: 1
};

button.fire( 'done', files );
sinon.assert.calledOnce( executeStub );
expect( executeStub.firstCall.args[ 0 ] ).to.equal( 'imageUpload' );
expect( executeStub.firstCall.args[ 1 ].file ).to.equal( files[ 0 ] );
} );
} );

0 comments on commit f4efd9b

Please sign in to comment.