memory.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 BalloonEditor from '../../src/ballooneditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. window.editors = {};
  9. /*
  10. * Memory-leak safe version of balloon 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 initEditors() {
  16. init( '#editor-1' );
  17. init( '#editor-2' );
  18. document.getElementById( 'destroyEditors' ).addEventListener( 'click', destroyEditors );
  19. function init( selector ) {
  20. BalloonEditor
  21. .create( document.querySelector( selector ), {
  22. plugins: [ ArticlePluginSet ],
  23. toolbar: {
  24. items: [
  25. 'heading',
  26. '|',
  27. 'bold',
  28. 'italic',
  29. 'link',
  30. 'bulletedList',
  31. 'numberedList',
  32. 'blockQuote',
  33. 'insertTable',
  34. 'mediaEmbed',
  35. 'undo',
  36. 'redo'
  37. ]
  38. },
  39. image: {
  40. toolbar: [
  41. 'imageStyle:full',
  42. 'imageStyle:side',
  43. '|',
  44. 'imageTextAlternative'
  45. ]
  46. },
  47. table: {
  48. contentToolbar: [
  49. 'tableColumn',
  50. 'tableRow',
  51. 'mergeTableCells'
  52. ]
  53. }
  54. } )
  55. .then( editor => {
  56. window.editors[ selector ] = editor;
  57. } )
  58. .catch( err => {
  59. console.error( err.stack );
  60. } );
  61. }
  62. function destroyEditors() {
  63. for ( const selector in window.editors ) {
  64. window.editors[ selector ].destroy().then( () => {
  65. window.editors[ selector ] = undefined;
  66. } );
  67. }
  68. document.getElementById( 'destroyEditors' ).removeEventListener( 'click', destroyEditors );
  69. }
  70. }
  71. document.getElementById( 'initEditors' ).addEventListener( 'click', initEditors );