classiceditor-data.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. function initEditor() {
  17. ClassicEditor
  18. .create( data, {
  19. plugins: [ Enter, Typing, Paragraph, Undo, Heading, Bold, Italic ],
  20. toolbar: [ 'heading', '|', 'bold', 'italic', 'undo', 'redo' ]
  21. } )
  22. .then( editor => {
  23. window.editors.push( editor );
  24. document.body.appendChild( editor.element );
  25. } )
  26. .catch( err => {
  27. console.error( err.stack );
  28. } );
  29. }
  30. function destroyEditor() {
  31. window.editors.forEach( editor => {
  32. editor.destroy()
  33. .then( () => {
  34. editor.element.remove();
  35. } );
  36. } );
  37. }
  38. document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );
  39. document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );