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

Commit

Permalink
Used decorator for ContextualToolbar#show method.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Jul 18, 2017
1 parent e1feb17 commit 18e1c6b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
33 changes: 12 additions & 21 deletions src/toolbar/contextual/contextualtoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export default class ContextualToolbar extends Plugin {
this._handleFocusChange();

// The appearance of the ContextualToolbar method is event–driven.
// It is possible to stop the #show event and thus prevent the toolbar from showing up.
this.on( 'show', () => this._show(), { priority: 'low' } );
// It is possible to stop the #show event and this prevent the toolbar from showing up.
this.decorate( 'show' );
}

/**
Expand Down Expand Up @@ -158,25 +158,6 @@ export default class ContextualToolbar extends Plugin {
return;
}

this.fire( 'show' );
}

/**
* Hides the toolbar.
*/
hide() {
if ( this._balloon.hasView( this.toolbarView ) ) {
this.stopListening( this.editor.editing.view, 'render' );
this._balloon.remove( this.toolbarView );
}
}

/**
* Shows of the toolbar if the {@link #event:show} has not been stopped.
*
* @private
*/
_show() {
// Don not show the toolbar when all components inside are disabled
// see https://github.com/ckeditor/ckeditor5-ui/issues/269.
if ( Array.from( this.toolbarView.items ).every( item => item.isEnabled !== undefined && !item.isEnabled ) ) {
Expand All @@ -197,6 +178,16 @@ export default class ContextualToolbar extends Plugin {
} );
}

/**
* Hides the toolbar.
*/
hide() {
if ( this._balloon.hasView( this.toolbarView ) ) {
this.stopListening( this.editor.editing.view, 'render' );
this._balloon.remove( this.toolbarView );
}
}

/**
* Returns positioning options for the {@link #_balloon}. They control the way balloon is attached
* to the selection.
Expand Down
2 changes: 1 addition & 1 deletion tests/manual/contextualtoolbar/contextualtoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ClassicEditor.create( document.querySelector( '#editor' ), {
if ( selectionRange.containsRange( blockRange ) || selectionRange.isIntersecting( blockRange ) ) {
evt.stop();
}
} );
}, { priority: 'high' } );
} )
.catch( err => {
console.error( err.stack );
Expand Down
2 changes: 1 addition & 1 deletion tests/toolbar/contextual/contextualtoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ describe( 'ContextualToolbar', () => {

setData( editor.document, '<paragraph>b[a]r</paragraph>' );

contextualToolbar.on( 'show', evt => evt.stop() );
contextualToolbar.on( 'show', evt => evt.stop(), { priority: 'high' } );

contextualToolbar.show();
sinon.assert.notCalled( balloonAddSpy );
Expand Down

0 comments on commit 18e1c6b

Please sign in to comment.