richeditor.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 CodeBlock from '@ckeditor/ckeditor5-code-block/src/codeblock';
  16. import FontBackgroundColor from '@ckeditor/ckeditor5-font/src/fontbackgroundcolor';
  17. import FontColor from '@ckeditor/ckeditor5-font/src/fontcolor';
  18. import FontFamily from '@ckeditor/ckeditor5-font/src/fontfamily';
  19. import FontSize from '@ckeditor/ckeditor5-font/src/fontsize';
  20. import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
  21. import HorizontalLine from '@ckeditor/ckeditor5-horizontal-line/src/horizontalline';
  22. import TodoList from '@ckeditor/ckeditor5-list/src/todolist';
  23. import Mention from '@ckeditor/ckeditor5-mention/src/mention';
  24. import PageBreak from '@ckeditor/ckeditor5-page-break/src/pagebreak';
  25. import PasteFromOffice from '@ckeditor/ckeditor5-paste-from-office/src/pastefromoffice';
  26. import RemoveFormat from '@ckeditor/ckeditor5-remove-format/src/removeformat';
  27. import StandardEditingMode from '@ckeditor/ckeditor5-restricted-editing/src/standardeditingmode';
  28. import SpecialCharacters from '@ckeditor/ckeditor5-special-characters/src/specialcharacters';
  29. import ImageUpload from '@ckeditor/ckeditor5-image/src/imageupload';
  30. import ImageResize from '@ckeditor/ckeditor5-image/src/imageresize';
  31. import { UploadAdapterMock } from '@ckeditor/ckeditor5-upload/tests/_utils/mocks';
  32. import WordCount from '@ckeditor/ckeditor5-word-count/src/wordcount';
  33. ClassicEditor
  34. .create( document.querySelector( '#editor' ), {
  35. plugins: [
  36. ArticlePluginSet,
  37. Alignment,
  38. AutoFormat,
  39. AutoSave,
  40. Strikethrough,
  41. Subscript,
  42. Superscript,
  43. Underline,
  44. CodeBlock,
  45. FontBackgroundColor,
  46. FontColor,
  47. FontFamily,
  48. FontSize,
  49. Highlight,
  50. HorizontalLine,
  51. TodoList,
  52. Mention,
  53. PageBreak,
  54. PasteFromOffice,
  55. RemoveFormat,
  56. StandardEditingMode,
  57. SpecialCharacters,
  58. ImageUpload,
  59. ImageResize,
  60. WordCount
  61. ],
  62. toolbar: {
  63. items: [
  64. 'heading',
  65. '|',
  66. 'bold',
  67. 'italic',
  68. 'strikethrough',
  69. 'subscript',
  70. 'superscript',
  71. 'underline',
  72. 'alignment',
  73. 'link',
  74. 'removeFormat',
  75. '|',
  76. 'fontBackgroundColor',
  77. 'fontColor',
  78. 'fontFamily',
  79. 'fontSize',
  80. 'highlight',
  81. '|',
  82. 'bulletedList',
  83. 'numberedList',
  84. 'todoList',
  85. 'outdent',
  86. 'indent',
  87. '|',
  88. 'blockQuote',
  89. 'insertTable',
  90. 'mediaEmbed',
  91. 'codeBlock',
  92. 'horizontalLine',
  93. 'pageBreak',
  94. 'specialCharacters',
  95. 'restrictedEditingException',
  96. 'undo',
  97. 'redo'
  98. ],
  99. shouldNotGroupWhenFull: true
  100. },
  101. table: {
  102. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells' ]
  103. },
  104. image: {
  105. toolbar: [ 'imageStyle:full', 'imageStyle:side', 'imageTextAlternative' ]
  106. }
  107. } )
  108. .then( editor => {
  109. window.editor = editor;
  110. addWordCountListener( editor );
  111. addUploadMockAdapter( editor );
  112. } )
  113. .catch( err => {
  114. console.error( err.stack );
  115. } );
  116. function addWordCountListener( editor ) {
  117. const wordCount = editor.plugins.get( WordCount );
  118. const wordCountElement = document.getElementById( 'word-count' );
  119. const characterCountElement = document.getElementById( 'character-count' );
  120. wordCountElement.innerHTML = wordCount.words;
  121. characterCountElement.innerHTML = wordCount.characters;
  122. wordCount.on( 'change:words', ( evt, name, value ) => {
  123. document.getElementById( 'word-count' ).innerHTML = value;
  124. } );
  125. wordCount.on( 'change:characters', ( evt, name, value ) => {
  126. document.getElementById( 'character-count' ).innerHTML = value;
  127. } );
  128. document.getElementById( 'word-count-wrapper' ).style.display = 'block';
  129. }
  130. function addUploadMockAdapter( editor ) {
  131. editor.plugins.get( 'FileRepository' ).createUploadAdapter = loader => {
  132. return new UploadAdapterMock( loader );
  133. };
  134. }