classiceditor-data.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals console:false, document, window */
  6. import ClassicEditor from '../../src/classiceditor';
  7. import Enter from '@ckeditor/ckeditor5-enter/src/enter';
  8. import Typing from '@ckeditor/ckeditor5-typing/src/typing';
  9. import Heading from '@ckeditor/ckeditor5-heading/src/heading';
  10. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  11. import Undo from '@ckeditor/ckeditor5-undo/src/undo';
  12. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  13. import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';
  14. window.editors = [];
  15. let counter = 1;
  16. const container = document.querySelector( '.container' );
  17. function initEditor() {
  18. ClassicEditor
  19. .create( `<h2>Hello world! #${ counter }</h2><p>This is an editor instance.</p>`, {
  20. plugins: [ Enter, Typing, Paragraph, Undo, Heading, Bold, Italic ],
  21. toolbar: [ 'heading', '|', 'bold', 'italic', 'undo', 'redo' ]
  22. } )
  23. .then( editor => {
  24. counter += 1;
  25. window.editors.push( editor );
  26. container.appendChild( editor.ui.element );
  27. } )
  28. .catch( err => {
  29. console.error( err.stack );
  30. } );
  31. }
  32. function destroyEditors() {
  33. window.editors.forEach( editor => {
  34. editor.destroy()
  35. .then( () => {
  36. editor.ui.element.remove();
  37. } );
  38. } );
  39. window.editors = [];
  40. counter = 1;
  41. }
  42. document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );
  43. document.getElementById( 'destroyEditors' ).addEventListener( 'click', destroyEditors );