memory.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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, document */
  6. import ClassicEditor from '../../src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. /*
  9. * Memory-leak safe version of classic editor manual test does not:
  10. * - define global variables (such as let editor; in main file scope)
  11. * - console.log() objects
  12. * - add event listeners with () => {} methods which reference other
  13. */
  14. function initEditor() {
  15. let editor;
  16. ClassicEditor
  17. .create( document.querySelector( '#editor' ), {
  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. editor = newEditor;
  53. document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );
  54. } )
  55. .catch( err => {
  56. console.error( err.stack );
  57. } );
  58. function destroyEditor() {
  59. editor.destroy().then( () => console.log( 'Editor was destroyed' ) );
  60. editor = null;
  61. document.getElementById( 'destroyEditor' ).removeEventListener( 'click', destroyEditor );
  62. }
  63. }
  64. document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );