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 #44 from ckeditor/t/43
Browse files Browse the repository at this point in the history
Fix: Bound ImageUploadButton#isEnabled to ImageUploadCommand#isEnabled. Closes #43.
  • Loading branch information
Piotr Jasiun committed Jul 12, 2017
2 parents aff6382 + f0aa610 commit ba6de66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/imageuploadbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class ImageUploadButton extends Plugin {
// Setup `insertImage` button.
editor.ui.componentFactory.add( 'insertImage', locale => {
const view = new FileDialogButtonView( locale );
const command = editor.commands.get( 'imageUpload' );

view.set( {
label: t( 'Insert image' ),
Expand All @@ -45,6 +46,8 @@ export default class ImageUploadButton extends Plugin {
allowMultipleFiles: true
} );

view.bind( 'isEnabled' ).to( command );

view.on( 'done', ( evt, files ) => {
for ( const file of files ) {
editor.execute( 'imageUpload', { file } );
Expand Down
13 changes: 13 additions & 0 deletions tests/imageuploadbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ describe( 'ImageUploadButton', () => {
expect( button ).to.be.instanceOf( FileDialogButtonView );
} );

it( 'should be disabled while ImageUploadCommand is disabled', () => {
const button = editor.ui.componentFactory.create( 'insertImage' );
const command = editor.commands.get( 'imageUpload' );

command.isEnabled = true;

expect( button.isEnabled ).to.true;

command.isEnabled = false;

expect( button.isEnabled ).to.false;
} );

it( 'should execute imageUpload command', () => {
const executeStub = sinon.stub( editor, 'execute' );
const button = editor.ui.componentFactory.create( 'insertImage' );
Expand Down

0 comments on commit ba6de66

Please sign in to comment.