all-features.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. insert: {
  97. integrations: [
  98. 'insertImageViaUrl'
  99. ]
  100. }
  101. },
  102. placeholder: 'Type the content here!',
  103. mention: {
  104. feeds: [
  105. {
  106. marker: '@',
  107. feed: [
  108. '@apple', '@bears', '@brownie', '@cake', '@cake', '@candy', '@canes', '@chocolate', '@cookie', '@cotton', '@cream',
  109. '@cupcake', '@danish', '@donut', '@dragée', '@fruitcake', '@gingerbread', '@gummi', '@ice', '@jelly-o',
  110. '@liquorice', '@macaroon', '@marzipan', '@oat', '@pie', '@plum', '@pudding', '@sesame', '@snaps', '@soufflé',
  111. '@sugar', '@sweet', '@topping', '@wafer'
  112. ],
  113. minimumCharacters: 1
  114. }
  115. ]
  116. },
  117. link: {
  118. decorators: {
  119. isExternal: {
  120. mode: 'manual',
  121. label: 'Open in a new tab',
  122. attributes: {
  123. target: '_blank',
  124. rel: 'noopener noreferrer'
  125. }
  126. },
  127. isDownloadable: {
  128. mode: 'manual',
  129. label: 'Downloadable',
  130. attributes: {
  131. download: 'download'
  132. }
  133. },
  134. isGallery: {
  135. mode: 'manual',
  136. label: 'Gallery link',
  137. attributes: {
  138. class: 'gallery'
  139. }
  140. }
  141. }
  142. }
  143. } )
  144. .then( editor => {
  145. window.editor = editor;
  146. editor.plugins.get( 'WordCount' ).on( 'update', ( evt, stats ) => {
  147. console.log( `Characters: ${ stats.characters }, words: ${ stats.words }.` );
  148. } );
  149. document.getElementById( 'clear-content' ).addEventListener( 'click', () => {
  150. editor.setData( '' );
  151. } );
  152. // The "Print editor data" button logic.
  153. document.getElementById( 'print-data-action' ).addEventListener( 'click', () => {
  154. const iframeElement = document.getElementById( 'print-data-container' );
  155. /* eslint-disable max-len */
  156. iframeElement.srcdoc = '<html>' +
  157. '<head>' +
  158. `<title>${ document.title }</title>` +
  159. '<link rel="stylesheet" href="https://ckeditor.com/docs/ckeditor5/latest/snippets/features/page-break/snippet.css" type="text/css">' +
  160. '</head>' +
  161. '<body class="ck-content">' +
  162. editor.getData() +
  163. '<script>' +
  164. 'window.addEventListener( \'DOMContentLoaded\', () => { window.print(); } );' +
  165. '</script>' +
  166. '</body>' +
  167. '</html>';
  168. /* eslint-enable max-len */
  169. } );
  170. const button = document.getElementById( 'read-only' );
  171. button.addEventListener( 'click', () => {
  172. editor.isReadOnly = !editor.isReadOnly;
  173. button.textContent = editor.isReadOnly ? 'Turn off read-only mode' : 'Turn on read-only mode';
  174. editor.editing.view.focus();
  175. } );
  176. } )
  177. .catch( err => {
  178. console.error( err.stack );
  179. } );