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 #499 from ckeditor/t/494
Browse files Browse the repository at this point in the history
Test: Added a custom stack to the ContextualBalloon manual test. Closes #494.
  • Loading branch information
Piotr Jasiun authored May 16, 2019
2 parents 33d85bf + d185837 commit 600b415
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
9 changes: 9 additions & 0 deletions tests/manual/contextualballoon/contextualballoon.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@
margin: 5em auto;
max-width: 70%;
}

.highlight {
background: yellow;
}

.ck p.custom-view {
font-size: 14px;
padding: 10px 10px 9px;
}
</style>
83 changes: 81 additions & 2 deletions tests/manual/contextualballoon/contextualballoon.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,95 @@
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
import BalloonToolbar from '../../../src/toolbar/balloon/balloontoolbar';
import ContextualBalloon from '../../../src/panel/balloon/contextualballoon';
import View from '../../../src/view';

class CustomStackHighlight {
static get requires() {
return [ ContextualBalloon ];
}

constructor( editor ) {
this.editor = editor;

this._markerToView = new Map();
}

init() {
this.editor.conversion.for( 'editingDowncast' ).markerToHighlight( {
model: 'highlight',
view: () => {
return { classes: 'highlight' };
}
} );

this.editor.model.document.selection.markers.on( 'add', ( evt, item ) => this._add( item ) );
this.editor.model.document.selection.markers.on( 'remove', ( evt, item ) => this._remove( item ) );
}

_add( marker ) {
const view = new View();

view.setTemplate( {
tag: 'p',
attributes: {
class: 'custom-view'
},
children: [
{ text: 'View in separate stack.' }
]
} );

this._markerToView.set( marker, view );

this.editor.plugins.get( ContextualBalloon ).add( {
view,
stackId: 'custom',
position: {
target: this._getMarkerDomElement( marker )
}
} );
}

_remove( marker ) {
this.editor.plugins.get( ContextualBalloon ).remove( this._markerToView.get( marker ) );
this._markerToView.delete( marker );
}

_getMarkerDomElement( marker ) {
const editing = this.editor.editing;
const viewElement = Array.from( editing.mapper.markerNameToElements( marker.name ).values() )[ 0 ];

return editing.view.domConverter.mapViewToDom( viewElement );
}
}

// Finally the editor.
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ ArticlePluginSet, BalloonToolbar ],
plugins: [ ArticlePluginSet, BalloonToolbar, CustomStackHighlight ],
toolbar: [ 'bold', 'link' ],
balloonToolbar: [ 'bold', 'link' ]
} )
.then( editor => {
window.editor = editor;

editor.model.change( writer => {
const root = editor.model.document.getRoot();

[
{ id: 1, start: [ 1, 5 ], end: [ 1, 26 ] },
{ id: 2, start: [ 5, 5 ], end: [ 5, 26 ] },
{ id: 3, start: [ 10, 5 ], end: [ 10, 26 ] }
].forEach( data => {
writer.addMarker( `highlight:${ data.id }`, {
range: writer.createRange(
writer.createPositionFromPath( root, data.start ),
writer.createPositionFromPath( root, data.end )
),
usingOperation: true
} );
} );
} );
} )
.catch( err => {
console.error( err.stack );
Expand Down
7 changes: 7 additions & 0 deletions tests/manual/contextualballoon/contextualballoon.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## Single stack

1. Select some text in the middle of the content - contextual toolbar should show up.
2. Click link icon in the contextual toolbar - link balloon should open at the position as contextual toolbar.
3. Close link balloon (Esc press or Cancel button) - contextual toolbar should show up.
4. Repeat this for backward selection.

## Multiple stacks

1. Select some highlighted text - "View in separate stack." should show up.
2. Switch stacks by clicking navigation buttons - you should switch between toolbar and custom view.

0 comments on commit 600b415

Please sign in to comment.