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

Bound ImageUploadButton#isEnabled to ImageUploadCommand#isEnabled. #44

Merged
merged 1 commit into from
Jul 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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