classiceditor-data.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  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. const data = '<h2>Hello world!</h2><p>This is an editor instance.</p>';
  15. window.editors = [];
  16. const container = document.querySelector( '.container' );
  17. function initEditor() {
  18. ClassicEditor
  19. .create( data, {
  20. plugins: [ Enter, Typing, Paragraph, Undo, Heading, Bold, Italic ],
  21. toolbar: [ 'heading', '|', 'bold', 'italic', 'undo', 'redo' ]
  22. } )
  23. .then( editor => {
  24. window.editors.push( editor );
  25. container.appendChild( editor.element );
  26. } )
  27. .catch( err => {
  28. console.error( err.stack );
  29. } );
  30. }
  31. function destroyEditor() {
  32. window.editors.forEach( editor => {
  33. editor.destroy()
  34. .then( () => {
  35. editor.element.remove();
  36. } );
  37. } );
  38. }
  39. document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );
  40. document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );