richeditor.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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, window, 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. ClassicEditor
  43. .create( document.querySelector( '#editor' ), {
  44. plugins: [
  45. ArticlePluginSet,
  46. Alignment,
  47. AutoFormat,
  48. AutoSave,
  49. Strikethrough,
  50. Subscript,
  51. Superscript,
  52. Underline,
  53. Code,
  54. CodeBlock,
  55. FontBackgroundColor,
  56. FontColor,
  57. FontFamily,
  58. FontSize,
  59. Highlight,
  60. HorizontalLine,
  61. TodoList,
  62. Mention,
  63. PageBreak,
  64. PasteFromOffice,
  65. RemoveFormat,
  66. StandardEditingMode,
  67. SpecialCharacters,
  68. TableProperties,
  69. TableCellProperties,
  70. ImageUpload,
  71. ImageResize,
  72. WordCount,
  73. IndentBlock
  74. ],
  75. toolbar: {
  76. items: [
  77. 'heading',
  78. '|',
  79. 'bold',
  80. 'italic',
  81. 'strikethrough',
  82. 'subscript',
  83. 'superscript',
  84. 'underline',
  85. 'code',
  86. 'alignment',
  87. 'link',
  88. 'removeFormat',
  89. '|',
  90. 'fontBackgroundColor',
  91. 'fontColor',
  92. 'fontFamily',
  93. 'fontSize',
  94. 'highlight',
  95. '|',
  96. 'bulletedList',
  97. 'numberedList',
  98. 'todoList',
  99. 'outdent',
  100. 'indent',
  101. '|',
  102. 'blockQuote',
  103. 'insertTable',
  104. 'mediaEmbed',
  105. 'codeBlock',
  106. 'horizontalLine',
  107. 'pageBreak',
  108. 'specialCharacters',
  109. 'restrictedEditingException',
  110. 'undo',
  111. 'redo'
  112. ],
  113. shouldNotGroupWhenFull: true
  114. },
  115. table: {
  116. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableCellProperties' ]
  117. },
  118. image: {
  119. toolbar: [ 'imageStyle:full', 'imageStyle:side', 'imageTextAlternative' ]
  120. }
  121. } )
  122. .then( editor => {
  123. window.editor = editor;
  124. addWordCountListener( editor );
  125. addUploadMockAdapter( editor );
  126. } )
  127. .catch( err => {
  128. console.error( err.stack );
  129. } );
  130. function addWordCountListener( editor ) {
  131. const wordCount = editor.plugins.get( WordCount );
  132. const wordCountElement = document.getElementById( 'word-count' );
  133. const characterCountElement = document.getElementById( 'character-count' );
  134. wordCountElement.innerHTML = wordCount.words;
  135. characterCountElement.innerHTML = wordCount.characters;
  136. wordCount.on( 'change:words', ( evt, name, value ) => {
  137. document.getElementById( 'word-count' ).innerHTML = value;
  138. } );
  139. wordCount.on( 'change:characters', ( evt, name, value ) => {
  140. document.getElementById( 'character-count' ).innerHTML = value;
  141. } );
  142. document.getElementById( 'word-count-wrapper' ).style.display = 'block';
  143. }
  144. function addUploadMockAdapter( editor ) {
  145. editor.plugins.get( 'FileRepository' ).createUploadAdapter = loader => {
  146. return new UploadAdapterMock( loader );
  147. };
  148. }
  149. const fixtures = getPerformanceData();
  150. fixtures.smallTablesInlineCss = smallTablesInlineCssFixture;
  151. const buttons = document.querySelectorAll( '#test-controls button' );
  152. for ( const button of buttons ) {
  153. button.addEventListener( 'click', function() {
  154. const content = fixtures[ this.getAttribute( 'data-file-name' ) ];
  155. window.editor.setData( content );
  156. } );
  157. button.disabled = false;
  158. }