all-features.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 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 ImageResize from '@ckeditor/ckeditor5-image/src/imageresize';
  34. import LinkImage from '@ckeditor/ckeditor5-link/src/linkimage';
  35. import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';
  36. ClassicEditor
  37. .create( document.querySelector( '#editor' ), {
  38. plugins: [
  39. ArticlePluginSet, CodeBlock, Alignment,
  40. TableProperties, TableCellProperties, SpecialCharacters, SpecialCharactersEssentials,
  41. Code, Underline, Strikethrough, Superscript, Subscript,
  42. Highlight, FontColor, FontBackgroundColor, FontFamily, FontSize,
  43. IndentBlock, WordCount, EasyImage,
  44. TodoList, PageBreak, HorizontalLine, Mention, RemoveFormat, TextTransformation,
  45. ImageResize, LinkImage
  46. ],
  47. toolbar: [
  48. 'heading',
  49. '|',
  50. 'removeFormat', 'bold', 'italic', 'strikethrough', 'underline', 'code', 'subscript', 'superscript', 'link',
  51. '|',
  52. 'highlight', 'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor',
  53. '|',
  54. 'bulletedList', 'numberedList', 'todoList',
  55. '|',
  56. 'blockQuote', 'imageUpload', 'insertTable', 'mediaEmbed', 'codeBlock',
  57. '|',
  58. 'alignment', 'outdent', 'indent',
  59. '|',
  60. 'pageBreak', 'horizontalLine', 'specialCharacters',
  61. '|',
  62. 'undo', 'redo'
  63. ],
  64. cloudServices: CS_CONFIG,
  65. table: {
  66. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableProperties', 'tableCellProperties' ]
  67. },
  68. image: {
  69. styles: [
  70. 'alignCenter',
  71. 'alignLeft',
  72. 'alignRight'
  73. ],
  74. resizeOptions: [
  75. {
  76. name: 'imageResize:original',
  77. label: 'Original size',
  78. value: null
  79. },
  80. {
  81. name: 'imageResize:50',
  82. label: '50%',
  83. value: '50'
  84. },
  85. {
  86. name: 'imageResize:75',
  87. label: '75%',
  88. value: '75'
  89. }
  90. ],
  91. toolbar: [
  92. 'imageTextAlternative', '|',
  93. 'imageStyle:alignLeft', 'imageStyle:alignCenter', 'imageStyle:alignRight', '|',
  94. 'imageResize'
  95. ]
  96. },
  97. placeholder: 'Type the content here!',
  98. mention: {
  99. feeds: [
  100. {
  101. marker: '@',
  102. feed: [
  103. '@apple', '@bears', '@brownie', '@cake', '@cake', '@candy', '@canes', '@chocolate', '@cookie', '@cotton', '@cream',
  104. '@cupcake', '@danish', '@donut', '@dragée', '@fruitcake', '@gingerbread', '@gummi', '@ice', '@jelly-o',
  105. '@liquorice', '@macaroon', '@marzipan', '@oat', '@pie', '@plum', '@pudding', '@sesame', '@snaps', '@soufflé',
  106. '@sugar', '@sweet', '@topping', '@wafer'
  107. ],
  108. minimumCharacters: 1
  109. }
  110. ]
  111. }
  112. } )
  113. .then( editor => {
  114. window.editor = editor;
  115. editor.plugins.get( 'WordCount' ).on( 'update', ( evt, stats ) => {
  116. console.log( `Characters: ${ stats.characters }, words: ${ stats.words }.` );
  117. } );
  118. document.getElementById( 'clear-content' ).addEventListener( 'click', () => {
  119. editor.setData( '' );
  120. } );
  121. // The "Print editor data" button logic.
  122. document.getElementById( 'print-data-action' ).addEventListener( 'click', () => {
  123. const iframeElement = document.getElementById( 'print-data-container' );
  124. /* eslint-disable max-len */
  125. iframeElement.srcdoc = '<html>' +
  126. '<head>' +
  127. `<title>${ document.title }</title>` +
  128. '<link rel="stylesheet" href="https://ckeditor.com/docs/ckeditor5/latest/snippets/features/page-break/snippet.css" type="text/css">' +
  129. '</head>' +
  130. '<body class="ck-content">' +
  131. editor.getData() +
  132. '<script>' +
  133. 'window.addEventListener( \'DOMContentLoaded\', () => { window.print(); } );' +
  134. '</script>' +
  135. '</body>' +
  136. '</html>';
  137. /* eslint-enable max-len */
  138. } );
  139. const button = document.getElementById( 'read-only' );
  140. button.addEventListener( 'click', () => {
  141. editor.isReadOnly = !editor.isReadOnly;
  142. button.textContent = editor.isReadOnly ? 'Turn off read-only mode' : 'Turn on read-only mode';
  143. editor.editing.view.focus();
  144. } );
  145. } )
  146. .catch( err => {
  147. console.error( err.stack );
  148. } );