|
|
@@ -13,28 +13,19 @@ import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
import Undo from '@ckeditor/ckeditor5-undo/src/undo';
|
|
|
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
|
|
|
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
|
|
|
-import testUtils from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
|
|
|
-
|
|
|
-let editor, editable, observer;
|
|
|
|
|
|
const data = '<h2>Hello world!</h2><p>This is an editor instance.</p>';
|
|
|
|
|
|
+window.editors = [];
|
|
|
+
|
|
|
function initEditor() {
|
|
|
ClassicEditor
|
|
|
.create( data, {
|
|
|
plugins: [ Enter, Typing, Paragraph, Undo, Heading, Bold, Italic ],
|
|
|
toolbar: [ 'heading', '|', 'bold', 'italic', 'undo', 'redo' ]
|
|
|
} )
|
|
|
- .then( newEditor => {
|
|
|
- console.log( 'Editor was initialized', newEditor );
|
|
|
- console.log( 'You can now play with it using global `editor` and `editable` variables.' );
|
|
|
-
|
|
|
- window.editor = editor = newEditor;
|
|
|
- window.editable = editable = editor.editing.view.document.getRoot();
|
|
|
-
|
|
|
- observer = testUtils.createObserver();
|
|
|
- observer.observe( 'Editable', editable, [ 'isFocused' ] );
|
|
|
-
|
|
|
+ .then( editor => {
|
|
|
+ window.editors.push( editor );
|
|
|
document.body.appendChild( editor.element );
|
|
|
} )
|
|
|
.catch( err => {
|
|
|
@@ -43,17 +34,12 @@ function initEditor() {
|
|
|
}
|
|
|
|
|
|
function destroyEditor() {
|
|
|
- editor.destroy()
|
|
|
- .then( () => {
|
|
|
- editor.element.remove();
|
|
|
-
|
|
|
- window.editor = editor = null;
|
|
|
- window.editable = editable = null;
|
|
|
-
|
|
|
- observer.stopListening();
|
|
|
- observer = null;
|
|
|
- console.log( 'Editor was destroyed' );
|
|
|
- } );
|
|
|
+ window.editors.forEach( editor => {
|
|
|
+ editor.destroy()
|
|
|
+ .then( () => {
|
|
|
+ editor.element.remove();
|
|
|
+ } );
|
|
|
+ } );
|
|
|
}
|
|
|
|
|
|
document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );
|