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

Commit ba6de66

Browse files
author
Piotr Jasiun
committed
Merge pull request #44 from ckeditor/t/43
Fix: Bound ImageUploadButton#isEnabled to ImageUploadCommand#isEnabled. Closes #43.
2 parents aff6382 + f0aa610 commit ba6de66

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/imageuploadbutton.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default class ImageUploadButton extends Plugin {
3636
// Setup `insertImage` button.
3737
editor.ui.componentFactory.add( 'insertImage', locale => {
3838
const view = new FileDialogButtonView( locale );
39+
const command = editor.commands.get( 'imageUpload' );
3940

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

49+
view.bind( 'isEnabled' ).to( command );
50+
4851
view.on( 'done', ( evt, files ) => {
4952
for ( const file of files ) {
5053
editor.execute( 'imageUpload', { file } );

tests/imageuploadbutton.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ describe( 'ImageUploadButton', () => {
3737
expect( button ).to.be.instanceOf( FileDialogButtonView );
3838
} );
3939

40+
it( 'should be disabled while ImageUploadCommand is disabled', () => {
41+
const button = editor.ui.componentFactory.create( 'insertImage' );
42+
const command = editor.commands.get( 'imageUpload' );
43+
44+
command.isEnabled = true;
45+
46+
expect( button.isEnabled ).to.true;
47+
48+
command.isEnabled = false;
49+
50+
expect( button.isEnabled ).to.false;
51+
} );
52+
4053
it( 'should execute imageUpload command', () => {
4154
const executeStub = sinon.stub( editor, 'execute' );
4255
const button = editor.ui.componentFactory.create( 'insertImage' );

0 commit comments

Comments
 (0)