From cde71fc1e6750d433c961d4f3a26bbd390d49d62 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Tue, 4 Jul 2017 11:00:27 +0200 Subject: [PATCH] Aligned Image package to the synchronous UI API. --- src/image/ui/imageballoonpanelview.js | 2 +- src/imagetextalternative.js | 40 ++++++++++++------------- src/imagetoolbar.js | 9 ++---- tests/image.js | 28 ++++++++--------- tests/image/ui/imageballoonpanelview.js | 16 ++-------- 5 files changed, 40 insertions(+), 55 deletions(-) diff --git a/src/image/ui/imageballoonpanelview.js b/src/image/ui/imageballoonpanelview.js index 32bd19fd..1ea38192 100644 --- a/src/image/ui/imageballoonpanelview.js +++ b/src/image/ui/imageballoonpanelview.js @@ -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(); } /** diff --git a/src/imagetextalternative.js b/src/imagetextalternative.js index c3cc1126..81febaa0 100644 --- a/src/imagetextalternative.js +++ b/src/imagetextalternative.js @@ -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 ); } /** @@ -94,7 +94,7 @@ export default class ImageTextAlternative extends Plugin { * Creates balloon panel. * * @private - * @return {Promise.} + * @return {module:image/image/ui/imageballoonpanel~ImageBalloonPanelView} */ _createBalloonPanel() { const editor = this.editor; @@ -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; } /** diff --git a/src/imagetoolbar.js b/src/imagetoolbar.js index f7cb8fba..78e95369 100644 --- a/src/imagetoolbar.js +++ b/src/imagetoolbar.js @@ -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. @@ -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', () => { @@ -98,8 +97,6 @@ export default class ImageToolbar extends Plugin { this.show(); } } ); - - return Promise.all( promises ); } /** diff --git a/tests/image.js b/tests/image.js index 52eb6ec2..cc4443a6 100644 --- a/tests/image.js +++ b/tests/image.js @@ -68,25 +68,23 @@ describe( 'Image', () => { // When image is selected along with text. setModelData( newEditor.document, 'fo[oalt text]' ); - 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, 'foo[alt text]' ); + // 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, 'foo[alt text]' ); - // 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(); } ); } ); diff --git a/tests/image/ui/imageballoonpanelview.js b/tests/image/ui/imageballoonpanelview.js index f4baab92..32a8dce2 100644 --- a/tests/image/ui/imageballoonpanelview.js +++ b/tests/image/ui/imageballoonpanelview.js @@ -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', () => {