memory.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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:false, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import TableProperties from '@ckeditor/ckeditor5-table/src/tableproperties';
  8. import TableCellProperties from '@ckeditor/ckeditor5-table/src/tablecellproperties';
  9. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  10. import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
  11. import Code from '@ckeditor/ckeditor5-basic-styles/src/code';
  12. import Strikethrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough';
  13. import Superscript from '@ckeditor/ckeditor5-basic-styles/src/superscript';
  14. import Subscript from '@ckeditor/ckeditor5-basic-styles/src/subscript';
  15. import FontColor from '@ckeditor/ckeditor5-font/src/fontcolor';
  16. import FontBackgroundColor from '@ckeditor/ckeditor5-font/src/fontbackgroundcolor';
  17. import FontFamily from '@ckeditor/ckeditor5-font/src/fontfamily';
  18. import FontSize from '@ckeditor/ckeditor5-font/src/fontsize';
  19. import CodeBlock from '@ckeditor/ckeditor5-code-block/src/codeblock';
  20. import WordCount from '@ckeditor/ckeditor5-word-count/src/wordcount';
  21. import TodoList from '@ckeditor/ckeditor5-list/src/todolist';
  22. import SpecialCharacters from '@ckeditor/ckeditor5-special-characters/src/specialcharacters';
  23. import SpecialCharactersEssentials from '@ckeditor/ckeditor5-special-characters/src/specialcharactersessentials';
  24. import PageBreak from '@ckeditor/ckeditor5-page-break/src/pagebreak';
  25. import HorizontalLine from '@ckeditor/ckeditor5-horizontal-line/src/horizontalline';
  26. import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
  27. import IndentBlock from '@ckeditor/ckeditor5-indent/src/indentblock';
  28. import EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
  29. import Mention from '@ckeditor/ckeditor5-mention/src/mention';
  30. import RemoveFormat from '@ckeditor/ckeditor5-remove-format/src/removeformat';
  31. import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment';
  32. import TextTransformation from '@ckeditor/ckeditor5-typing/src/texttransformation';
  33. import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';
  34. /*
  35. * Memory-leak safe version of balloon editor manual test does not:
  36. * - define global variables (such as let editor; in main file scope)
  37. * - console.log() objects
  38. * - add event listeners with () => {} methods which reference other
  39. */
  40. function initEditor() {
  41. ClassicEditor
  42. .create( document.querySelector( '#editor' ), {
  43. plugins: [
  44. ArticlePluginSet, CodeBlock, Alignment,
  45. TableProperties, TableCellProperties, SpecialCharacters, SpecialCharactersEssentials,
  46. Code, Underline, Strikethrough, Superscript, Subscript,
  47. Highlight, FontColor, FontBackgroundColor, FontFamily, FontSize,
  48. IndentBlock, WordCount, EasyImage,
  49. TodoList, PageBreak, HorizontalLine, Mention, RemoveFormat, TextTransformation
  50. ],
  51. toolbar: [
  52. 'heading',
  53. '|',
  54. 'removeFormat', 'bold', 'italic', 'strikethrough', 'underline', 'code', 'subscript', 'superscript', 'link',
  55. '|',
  56. 'highlight', 'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor',
  57. '|',
  58. 'bulletedList', 'numberedList', 'todoList',
  59. '|',
  60. 'blockQuote', 'imageUpload', 'insertTable', 'mediaEmbed', 'codeBlock',
  61. '|',
  62. 'alignment', 'outdent', 'indent',
  63. '|',
  64. 'pageBreak', 'horizontalLine', 'specialCharacters',
  65. '|',
  66. 'undo', 'redo'
  67. ],
  68. cloudServices: CS_CONFIG,
  69. table: {
  70. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableProperties', 'tableCellProperties' ]
  71. },
  72. image: {
  73. styles: [
  74. 'full',
  75. 'alignLeft',
  76. 'alignRight'
  77. ],
  78. toolbar: [ 'imageTextAlternative', '|', 'imageStyle:alignLeft', 'imageStyle:full', 'imageStyle:alignRight' ]
  79. },
  80. placeholder: 'Type the content here!',
  81. mention: {
  82. feeds: [
  83. {
  84. marker: '@',
  85. feed: [
  86. '@apple', '@bears', '@brownie', '@cake', '@cake', '@candy', '@canes', '@chocolate', '@cookie', '@cotton',
  87. '@cream', '@cupcake', '@danish', '@donut', '@dragée', '@fruitcake', '@gingerbread', '@gummi', '@ice',
  88. '@jelly-o', '@liquorice', '@macaroon', '@marzipan', '@oat', '@pie', '@plum', '@pudding', '@sesame',
  89. '@snaps', '@soufflé', '@sugar', '@sweet', '@topping', '@wafer'
  90. ],
  91. minimumCharacters: 1
  92. }
  93. ]
  94. }
  95. } )
  96. .then( editor => {
  97. editor.plugins.get( 'WordCount' ).on( 'update', ( evt, stats ) => {
  98. console.log( `Characters: ${ stats.characters }, words: ${ stats.words }.` );
  99. } );
  100. document.getElementById( 'clear-content' ).addEventListener( 'click', clearData );
  101. document.getElementById( 'print-data-action' ).addEventListener( 'click', printData );
  102. document.getElementById( 'read-only' ).addEventListener( 'click', readOnly );
  103. document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );
  104. function destroyEditor() {
  105. editor.destroy().then( () => console.log( 'Editor was destroyed' ) );
  106. editor = null;
  107. document.getElementById( 'destroyEditor' ).removeEventListener( 'click', destroyEditor );
  108. document.getElementById( 'clear-content' ).removeEventListener( 'click', clearData );
  109. document.getElementById( 'print-data-action' ).removeEventListener( 'click', printData );
  110. document.getElementById( 'read-only' ).removeEventListener( 'click', readOnly );
  111. }
  112. function readOnly() {
  113. editor.isReadOnly = !editor.isReadOnly;
  114. document.getElementById( 'read-only' ).textContent =
  115. editor.isReadOnly ? 'Turn off read-only mode' : 'Turn on read-only mode';
  116. editor.editing.view.focus();
  117. }
  118. function printData() {
  119. const iframeElement = document.getElementById( 'print-data-container' );
  120. /* eslint-disable max-len */
  121. iframeElement.srcdoc = '<html>' +
  122. '<head>' +
  123. `<title>${ document.title }</title>` +
  124. '<link rel="stylesheet" href="https://ckeditor.com/docs/ckeditor5/latest/snippets/features/page-break/snippet.css" type="text/css">' +
  125. '</head>' +
  126. '<body class="ck-content">' +
  127. editor.getData() +
  128. '<script>' +
  129. 'window.addEventListener( \'DOMContentLoaded\', () => { window.print(); } );' +
  130. '</script>' +
  131. '</body>' +
  132. '</html>';
  133. /* eslint-enable max-len */
  134. }
  135. function clearData() {
  136. editor.setData( '' );
  137. }
  138. } )
  139. .catch( err => {
  140. console.error( err.stack );
  141. } );
  142. }
  143. document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );