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

Commit

Permalink
Internal: Updated the usage of UI components which are now driven by …
Browse files Browse the repository at this point in the history
…synchronous initialization and destruction (see https://github.com/ckeditor/ckeditor5-ui/issues/225).
  • Loading branch information
Reinmar committed Jul 5, 2017
2 parents b806152 + 165863f commit 16a6ada
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/image/ui/imageballoonpanelview.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class ImageBalloonPanelView extends BalloonPanelView {
// Let the focusTracker know about new focusable UI element.
this.editor.ui.focusTracker.add( this.element );

return super.init();
super.init();
}

/**
Expand Down
40 changes: 20 additions & 20 deletions src/imagetextalternative.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ export default class ImageTextAlternative extends Plugin {
init() {
this._createButton();

return this._createBalloonPanel().then( panel => {
/**
* Balloon panel containing text alternative change form.
*
* @member {module:image/image/ui/imageballoonpanel~ImageBalloonPanelView} #baloonPanel
*/
this.balloonPanel = panel;

/**
* Form containing textarea and buttons, used to change `alt` text value.
*
* @member {module:image/imagetextalternative/ui/textalternativeformview~TextAlternativeFormView} #form
*/
this.form = panel.content.get( 0 );
} );
const panel = this._createBalloonPanel();

/**
* Balloon panel containing text alternative change form.
*
* @member {module:image/image/ui/imageballoonpanel~ImageBalloonPanelView} #baloonPanel
*/
this.balloonPanel = panel;

/**
* Form containing textarea and buttons, used to change `alt` text value.
*
* @member {module:image/imagetextalternative/ui/textalternativeformview~TextAlternativeFormView} #form
*/
this.form = panel.content.get( 0 );
}

/**
Expand Down Expand Up @@ -94,7 +94,7 @@ export default class ImageTextAlternative extends Plugin {
* Creates balloon panel.
*
* @private
* @return {Promise.<module:image/image/ui/imageballoonpanel~ImageBalloonPanelView>}
* @return {module:image/image/ui/imageballoonpanel~ImageBalloonPanelView}
*/
_createBalloonPanel() {
const editor = this.editor;
Expand Down Expand Up @@ -139,10 +139,10 @@ export default class ImageTextAlternative extends Plugin {
callback: () => this._hideBalloonPanel()
} );

return Promise.all( [
panel.content.add( form ),
editor.ui.view.body.add( panel )
] ).then( () => panel );
panel.content.add( form );
editor.ui.view.body.add( panel );

return panel;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/imagetoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export default class ImageToolbar extends Plugin {
}

const panel = this._panel = new ImageBalloonPanel( editor );
const promises = [];
const toolbar = new ToolbarView();

// Add CSS class to the toolbar.
Expand All @@ -77,13 +76,13 @@ export default class ImageToolbar extends Plugin {
} );

// Add toolbar to balloon panel.
promises.push( panel.content.add( toolbar ) );
panel.content.add( toolbar );

// Add buttons to the toolbar.
promises.push( toolbar.fillFromConfig( toolbarConfig, editor.ui.componentFactory ) );
toolbar.fillFromConfig( toolbarConfig, editor.ui.componentFactory );

// Add balloon panel to editor's UI.
promises.push( editor.ui.view.body.add( panel ) );
editor.ui.view.body.add( panel );

// Show balloon panel each time image widget is selected.
this.listenTo( this.editor.editing.view, 'render', () => {
Expand All @@ -98,8 +97,6 @@ export default class ImageToolbar extends Plugin {
this.show();
}
} );

return Promise.all( promises );
}

/**
Expand Down
28 changes: 13 additions & 15 deletions tests/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,23 @@ describe( 'Image', () => {
// When image is selected along with text.
setModelData( newEditor.document, '<paragraph>fo[o</paragraph><image alt="alt text" src="foo.png"></image>]' );

return contextualToolbar._showPanel()
.then( () => {
// ContextualToolbar should be visible.
expect( balloon.visibleView ).to.equal( contextualToolbar.toolbarView );
contextualToolbar._showPanel();

// When only image is selected.
setModelData( newEditor.document, '<paragraph>foo</paragraph>[<image alt="alt text" src="foo.png"></image>]' );
// ContextualToolbar should be visible.
expect( balloon.visibleView ).to.equal( contextualToolbar.toolbarView );

return contextualToolbar._showPanel()
.then( () => {
// ContextualToolbar should not be visible.
expect( balloon.visibleView ).to.be.null;
// When only image is selected.
setModelData( newEditor.document, '<paragraph>foo</paragraph>[<image alt="alt text" src="foo.png"></image>]' );

// Cleaning up.
editorElement.remove();
contextualToolbar._showPanel();

return newEditor.destroy();
} );
} );
// ContextualToolbar should not be visible.
expect( balloon.visibleView ).to.be.null;

// Cleaning up.
editorElement.remove();

return newEditor.destroy();
} );
} );

Expand Down
16 changes: 3 additions & 13 deletions tests/image/ui/imageballoonpanelview.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,15 @@ describe( 'ImageBalloonPanel', () => {
return editor.destroy();
} );

it( 'init method should return a promise', () => {
const panel = new ImageBalloonPanel( editor );
const promise = panel.init();

expect( promise ).to.be.instanceof( Promise );

return promise;
} );

it( 'should add element to editor\'s focus tracker after init', () => {
const spy = sinon.spy( editor.ui.focusTracker, 'add' );
const panel = new ImageBalloonPanel( editor );

sinon.assert.notCalled( spy );

return panel.init().then( () => {
sinon.assert.calledOnce( spy );
sinon.assert.calledWithExactly( spy, panel.element );
} );
panel.init();
sinon.assert.calledOnce( spy );
sinon.assert.calledWithExactly( spy, panel.element );
} );

it( 'should detach panel when focus is removed', () => {
Expand Down

0 comments on commit 16a6ada

Please sign in to comment.