memory.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license Copyright (c) 2003-2019, 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 DecoupledEditor from '../../src/decouplededitor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. const editorData = '<h2>Hello world</h2><p>This is the decoupled editor.</p><img src="sample.jpg" />';
  9. /*
  10. * Memory-leak safe version of decoupled editor manual test does not:
  11. * - define global variables (such as let editor; in main file scope)
  12. * - console.log() objects
  13. * - add event listeners with () => {} methods which reference other
  14. */
  15. function initEditor() {
  16. DecoupledEditor
  17. .create( editorData, {
  18. plugins: [ ArticlePluginSet ],
  19. toolbar: {
  20. items: [
  21. 'heading',
  22. '|',
  23. 'bold',
  24. 'italic',
  25. 'link',
  26. 'bulletedList',
  27. 'numberedList',
  28. 'blockQuote',
  29. 'insertTable',
  30. 'mediaEmbed',
  31. 'undo',
  32. 'redo'
  33. ]
  34. },
  35. image: {
  36. toolbar: [
  37. 'imageStyle:full',
  38. 'imageStyle:side',
  39. '|',
  40. 'imageTextAlternative'
  41. ]
  42. },
  43. table: {
  44. contentToolbar: [
  45. 'tableColumn',
  46. 'tableRow',
  47. 'mergeTableCells'
  48. ]
  49. }
  50. } )
  51. .then( newEditor => {
  52. window.editor = newEditor;
  53. document.querySelector( '.toolbar-container' ).appendChild( newEditor.ui.view.toolbar.element );
  54. document.querySelector( '.editable-container' ).appendChild( newEditor.ui.view.editable.element );
  55. document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );
  56. } )
  57. .catch( err => {
  58. console.error( err.stack );
  59. } );
  60. function destroyEditor() {
  61. window.editor.destroy().then( () => console.log( 'Editor was destroyed' ) );
  62. window.editor = null;
  63. document.getElementById( 'destroyEditor' ).removeEventListener( 'click', destroyEditor );
  64. }
  65. }
  66. document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );