richeditor.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment';
  9. import AutoFormat from '@ckeditor/ckeditor5-autoformat/src/autoformat';
  10. import AutoSave from '@ckeditor/ckeditor5-autosave/src/autosave';
  11. import Strikethrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough';
  12. import Subscript from '@ckeditor/ckeditor5-basic-styles/src/subscript';
  13. import Superscript from '@ckeditor/ckeditor5-basic-styles/src/superscript';
  14. import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
  15. import Code from '@ckeditor/ckeditor5-basic-styles/src/code';
  16. import CodeBlock from '@ckeditor/ckeditor5-code-block/src/codeblock';
  17. import FontBackgroundColor from '@ckeditor/ckeditor5-font/src/fontbackgroundcolor';
  18. import FontColor from '@ckeditor/ckeditor5-font/src/fontcolor';
  19. import FontFamily from '@ckeditor/ckeditor5-font/src/fontfamily';
  20. import FontSize from '@ckeditor/ckeditor5-font/src/fontsize';
  21. import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
  22. import HorizontalLine from '@ckeditor/ckeditor5-horizontal-line/src/horizontalline';
  23. import TodoList from '@ckeditor/ckeditor5-list/src/todolist';
  24. import Mention from '@ckeditor/ckeditor5-mention/src/mention';
  25. import PageBreak from '@ckeditor/ckeditor5-page-break/src/pagebreak';
  26. import PasteFromOffice from '@ckeditor/ckeditor5-paste-from-office/src/pastefromoffice';
  27. import RemoveFormat from '@ckeditor/ckeditor5-remove-format/src/removeformat';
  28. import StandardEditingMode from '@ckeditor/ckeditor5-restricted-editing/src/standardeditingmode';
  29. import SpecialCharacters from '@ckeditor/ckeditor5-special-characters/src/specialcharacters';
  30. import TableProperties from '@ckeditor/ckeditor5-table/src/tableproperties';
  31. import TableCellProperties from '@ckeditor/ckeditor5-table/src/tablecellproperties';
  32. import ImageUpload from '@ckeditor/ckeditor5-image/src/imageupload';
  33. import ImageResize from '@ckeditor/ckeditor5-image/src/imageresize';
  34. import IndentBlock from '@ckeditor/ckeditor5-indent/src/indentblock';
  35. import { UploadAdapterMock } from '@ckeditor/ckeditor5-upload/tests/_utils/mocks';
  36. import WordCount from '@ckeditor/ckeditor5-word-count/src/wordcount';
  37. import { getPerformanceData, renderPerformanceDataButtons } from '../../_utils/utils';
  38. import smallTablesInlineCssFixture from '../../_data/small-tables-inline-css.html';
  39. renderPerformanceDataButtons( document.querySelector( '#fixture-buttons' ), {
  40. 'smallTablesInlineCss': 'text and tables (styled)'
  41. } );
  42. let editor;
  43. ClassicEditor
  44. .create( document.querySelector( '#editor' ), {
  45. plugins: [
  46. ArticlePluginSet,
  47. Alignment,
  48. AutoFormat,
  49. AutoSave,
  50. Strikethrough,
  51. Subscript,
  52. Superscript,
  53. Underline,
  54. Code,
  55. CodeBlock,
  56. FontBackgroundColor,
  57. FontColor,
  58. FontFamily,
  59. FontSize,
  60. Highlight,
  61. HorizontalLine,
  62. TodoList,
  63. Mention,
  64. PageBreak,
  65. PasteFromOffice,
  66. RemoveFormat,
  67. StandardEditingMode,
  68. SpecialCharacters,
  69. TableProperties,
  70. TableCellProperties,
  71. ImageUpload,
  72. ImageResize,
  73. WordCount,
  74. IndentBlock
  75. ],
  76. toolbar: {
  77. items: [
  78. 'heading',
  79. '|',
  80. 'bold',
  81. 'italic',
  82. 'strikethrough',
  83. 'subscript',
  84. 'superscript',
  85. 'underline',
  86. 'code',
  87. 'alignment',
  88. 'link',
  89. 'removeFormat',
  90. '|',
  91. 'fontBackgroundColor',
  92. 'fontColor',
  93. 'fontFamily',
  94. 'fontSize',
  95. 'highlight',
  96. '|',
  97. 'bulletedList',
  98. 'numberedList',
  99. 'todoList',
  100. 'outdent',
  101. 'indent',
  102. '|',
  103. 'blockQuote',
  104. 'insertTable',
  105. 'mediaEmbed',
  106. 'codeBlock',
  107. 'horizontalLine',
  108. 'pageBreak',
  109. 'specialCharacters',
  110. 'restrictedEditingException',
  111. 'undo',
  112. 'redo'
  113. ],
  114. shouldNotGroupWhenFull: true
  115. },
  116. table: {
  117. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableCellProperties' ]
  118. },
  119. image: {
  120. toolbar: [ 'imageStyle:full', 'imageStyle:side', 'imageTextAlternative' ]
  121. }
  122. } )
  123. .then( newEditor => {
  124. // Editor is not exposed as window.editor to disable CKEditor5 Inspector for performance tests.
  125. editor = newEditor;
  126. addWordCountListener( newEditor );
  127. addUploadMockAdapter( newEditor );
  128. } )
  129. .catch( err => {
  130. console.error( err.stack );
  131. } );
  132. function addWordCountListener( editor ) {
  133. const wordCount = editor.plugins.get( WordCount );
  134. const wordCountElement = document.getElementById( 'word-count' );
  135. const characterCountElement = document.getElementById( 'character-count' );
  136. wordCountElement.innerHTML = wordCount.words;
  137. characterCountElement.innerHTML = wordCount.characters;
  138. wordCount.on( 'change:words', ( evt, name, value ) => {
  139. document.getElementById( 'word-count' ).innerHTML = value;
  140. } );
  141. wordCount.on( 'change:characters', ( evt, name, value ) => {
  142. document.getElementById( 'character-count' ).innerHTML = value;
  143. } );
  144. document.getElementById( 'word-count-wrapper' ).style.display = 'block';
  145. }
  146. function addUploadMockAdapter( editor ) {
  147. editor.plugins.get( 'FileRepository' ).createUploadAdapter = loader => {
  148. return new UploadAdapterMock( loader );
  149. };
  150. }
  151. const fixtures = getPerformanceData();
  152. fixtures.smallTablesInlineCss = smallTablesInlineCssFixture;
  153. const buttons = document.querySelectorAll( '#test-controls button' );
  154. for ( const button of buttons ) {
  155. button.addEventListener( 'click', function() {
  156. const content = fixtures[ this.getAttribute( 'data-file-name' ) ];
  157. editor.setData( content );
  158. } );
  159. button.disabled = false;
  160. }