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

Commit

Permalink
Merge pull request #65 from ckeditor/t/64
Browse files Browse the repository at this point in the history
Feature: Added a separator between image styles and text alternative buttons in the image toolbar. Closes #64.
  • Loading branch information
Reinmar committed Feb 28, 2017
2 parents 6edd823 + 081d852 commit 925a538
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/imagestyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export default class ImageStyle extends Plugin {
const defaultImageToolbarConfig = this.editor.config.get( 'image.defaultToolbar' );

if ( defaultImageToolbarConfig ) {
if ( defaultImageToolbarConfig.length ) {
defaultImageToolbarConfig.push( '|' );
}

styles.forEach( style => defaultImageToolbarConfig.push( style.name ) );
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/imagetextalternative.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default class ImageTextAlternative extends Plugin {
const defaultImageToolbarConfig = this.editor.config.get( 'image.defaultToolbar' );

if ( defaultImageToolbarConfig ) {
if ( defaultImageToolbarConfig.length ) {
defaultImageToolbarConfig.push( '|' );
}

defaultImageToolbarConfig.push( 'imageTextAlternative' );
}

Expand Down
4 changes: 1 addition & 3 deletions src/imagetoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ export default class ImageToolbar extends Plugin {
promises.push( panel.content.add( toolbar ) );

// Add buttons to the toolbar.
for ( let name of toolbarConfig ) {
promises.push( toolbar.items.add( editor.ui.componentFactory.create( name ) ) );
}
promises.push( toolbar.fillFromConfig( toolbarConfig, editor.ui.componentFactory ) );

// Add balloon panel to editor's UI.
promises.push( editor.ui.view.body.add( panel ) );
Expand Down
23 changes: 23 additions & 0 deletions tests/imagestyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* For licensing, see LICENSE.md.
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
import ImageToolbar from '../src/imagetoolbar';
import ImageStyle from '../src/imagestyle';
Expand Down Expand Up @@ -86,6 +87,28 @@ describe( 'ImageStyle', () => {
} );
} );

it( 'should add separator before the button if toolbar is present and already has items', () => {
const editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );

const FooPlugin = class extends Plugin {
init() {
this.editor.ui.componentFactory.add( 'foo', () => new ButtonView() );

this.editor.config.get( 'image.defaultToolbar' ).push( 'foo' );
}
};

return ClassicTestEditor.create( editorElement, {
plugins: [ FooPlugin, ImageStyle, ImageToolbar ]
} )
.then( newEditor => {
expect( newEditor.config.get( 'image.defaultToolbar' ) ).to.eql( [ 'foo', '|', 'imageStyleFull', 'imageStyleSide' ] );

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

it( 'should not add buttons to image toolbar if configuration is present', () => {
const editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );
Expand Down
23 changes: 23 additions & 0 deletions tests/imagetextalternative.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* For licensing, see LICENSE.md.
*/

import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
import Image from '../src/image';
import ImageToolbar from '../src/imagetoolbar';
Expand Down Expand Up @@ -109,6 +110,28 @@ describe( 'ImageTextAlternative', () => {
newEditor.destroy();
} );
} );

it( 'should add separator before the button if toolbar is present and already has items', () => {
const editorElement = global.document.createElement( 'div' );
global.document.body.appendChild( editorElement );

const FooPlugin = class extends Plugin {
init() {
this.editor.ui.componentFactory.add( 'foo', () => new ButtonView() );

this.editor.config.get( 'image.defaultToolbar' ).push( 'foo' );
}
};

return ClassicTestEditor.create( editorElement, {
plugins: [ FooPlugin, ImageTextAlternative, ImageToolbar ]
} )
.then( newEditor => {
expect( newEditor.config.get( 'image.defaultToolbar' ) ).to.eql( [ 'foo', '|', 'imageTextAlternative' ] );

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

describe( 'balloon panel form', () => {
Expand Down

0 comments on commit 925a538

Please sign in to comment.