richeditor.js 5.0 KB

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