creator-inline.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global console:false */
  6. 'use strict';
  7. import CKEDITOR from '/ckeditor.js';
  8. import InlineCreator from '/tests/ckeditor5/creator/manual/_utils/creator/inlinecreator.js';
  9. import testUtils from '/tests/utils/_utils/utils.js';
  10. let editor, editable, observer;
  11. function initEditor() {
  12. CKEDITOR.create( '#editor', {
  13. creator: InlineCreator,
  14. toolbar: [ 'bold', 'italic' ]
  15. } )
  16. .then( ( newEditor ) => {
  17. console.log( 'Editor was initialized', newEditor );
  18. console.log( 'You can now play with it using global `editor` and `editable` variable.' );
  19. window.editor = editor = newEditor;
  20. window.editable = editable = editor.editables.get( 0 );
  21. observer = testUtils.createObserver();
  22. observer.observe( 'Editable', editable );
  23. } );
  24. }
  25. function destroyEditor() {
  26. editor.destroy()
  27. .then( () => {
  28. window.editor = editor = null;
  29. window.editable = editable = null;
  30. observer.stopListening();
  31. observer = null;
  32. console.log( 'Editor was destroyed' );
  33. } );
  34. }
  35. document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );
  36. document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );