Skip to content

Commit

Permalink
Improved manual sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2ciek committed Sep 20, 2019
1 parent 64c1cb2 commit 7cabf03
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ <h2>Second editor</h2>
<p>foo</p>
</div>

<h2>Actions</h2>
<button id="attach-inspector">Attach inspector to all editors</button>
<button id="detach-inspector-from-editors">Detach inspector from editors</button>
<button id="destroy-inspector">Destroy inspector</button>

<script>
class DummyUploadAdapter {
constructor( loader ) {
Expand Down Expand Up @@ -74,6 +79,24 @@ <h2>Second editor</h2>
};
}

let editorNames = [];

document.querySelector( '#destroy-inspector' ).addEventListener( 'click', () => {
CKEditorInspector.destroy();
editorNames = [];
} );

document.querySelector( '#attach-inspector' ).addEventListener( 'click', () => {
const names = CKEditorInspector.attachToAll();

editorNames.push( ...names );
} );

document.querySelector( '#detach-inspector-from-editors' ).addEventListener( 'click', () => {
editorNames.forEach( name => CKEditorInspector.detach( name ) );
editorNames = [];
} );

DecoupledEditor
.create( document.querySelector( '#first-editor-content' ), {
extraPlugins: [ UploadAdapter ]
Expand All @@ -82,6 +105,7 @@ <h2>Second editor</h2>
window.firstEditor = editor;
document.body.insertBefore( editor.ui.view.toolbar.element, editor.ui.getEditableElement() );
CKEditorInspector.attach( { 'first-editor': editor } );
editorNames.push( 'first-editor' );
} )
.catch( error => {
console.error( error );
Expand All @@ -94,7 +118,8 @@ <h2>Second editor</h2>
.then( editor => {
window.secondEditor = editor;
document.body.insertBefore( editor.ui.view.toolbar.element, editor.ui.getEditableElement() );
CKEditorInspector.attach( editor );
const [ name ] = CKEditorInspector.attach( editor );
editorNames.push( name );
} )
.catch( error => {
console.error( error );
Expand Down

0 comments on commit 7cabf03

Please sign in to comment.