memory.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @license Copyright (c) 2003-2019, 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 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. ClassicEditor
  16. .create( document.querySelector( '#editor' ), {
  17. plugins: [ ArticlePluginSet ],
  18. toolbar: {
  19. items: [
  20. 'heading',
  21. '|',
  22. 'bold',
  23. 'italic',
  24. 'link',
  25. 'bulletedList',
  26. 'numberedList',
  27. 'blockQuote',
  28. 'insertTable',
  29. 'mediaEmbed',
  30. 'undo',
  31. 'redo'
  32. ]
  33. },
  34. image: {
  35. toolbar: [
  36. 'imageStyle:full',
  37. 'imageStyle:side',
  38. '|',
  39. 'imageTextAlternative'
  40. ]
  41. },
  42. table: {
  43. contentToolbar: [
  44. 'tableColumn',
  45. 'tableRow',
  46. 'mergeTableCells'
  47. ]
  48. }
  49. } )
  50. .then( newEditor => {
  51. window.editor = newEditor;
  52. document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );
  53. } )
  54. .catch( err => {
  55. console.error( err.stack );
  56. } );
  57. function destroyEditor() {
  58. window.editor.destroy().then( () => console.log( 'Editor was destroyed' ) );
  59. window.editor = null;
  60. document.getElementById( 'destroyEditor' ).removeEventListener( 'click', destroyEditor );
  61. }
  62. }
  63. document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );