all-features.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 Alignment from '@ckeditor/ckeditor5-alignment/src/alignment';
  8. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  9. import AutoImage from '@ckeditor/ckeditor5-image/src/autoimage';
  10. import AutoLink from '@ckeditor/ckeditor5-link/src/autolink';
  11. import Code from '@ckeditor/ckeditor5-basic-styles/src/code';
  12. import CodeBlock from '@ckeditor/ckeditor5-code-block/src/codeblock';
  13. import EasyImage from '@ckeditor/ckeditor5-easy-image/src/easyimage';
  14. import FontBackgroundColor from '@ckeditor/ckeditor5-font/src/fontbackgroundcolor';
  15. import FontColor from '@ckeditor/ckeditor5-font/src/fontcolor';
  16. import FontFamily from '@ckeditor/ckeditor5-font/src/fontfamily';
  17. import FontSize from '@ckeditor/ckeditor5-font/src/fontsize';
  18. import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
  19. import HorizontalLine from '@ckeditor/ckeditor5-horizontal-line/src/horizontalline';
  20. import ImageResize from '@ckeditor/ckeditor5-image/src/imageresize';
  21. import IndentBlock from '@ckeditor/ckeditor5-indent/src/indentblock';
  22. import LinkImage from '@ckeditor/ckeditor5-link/src/linkimage';
  23. import Mention from '@ckeditor/ckeditor5-mention/src/mention';
  24. import PageBreak from '@ckeditor/ckeditor5-page-break/src/pagebreak';
  25. import RemoveFormat from '@ckeditor/ckeditor5-remove-format/src/removeformat';
  26. import SpecialCharacters from '@ckeditor/ckeditor5-special-characters/src/specialcharacters';
  27. import SpecialCharactersEssentials from '@ckeditor/ckeditor5-special-characters/src/specialcharactersessentials';
  28. import Strikethrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough';
  29. import Subscript from '@ckeditor/ckeditor5-basic-styles/src/subscript';
  30. import Superscript from '@ckeditor/ckeditor5-basic-styles/src/superscript';
  31. import TableCellProperties from '@ckeditor/ckeditor5-table/src/tablecellproperties';
  32. import TableProperties from '@ckeditor/ckeditor5-table/src/tableproperties';
  33. import TextTransformation from '@ckeditor/ckeditor5-typing/src/texttransformation';
  34. import TodoList from '@ckeditor/ckeditor5-list/src/todolist';
  35. import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
  36. import WordCount from '@ckeditor/ckeditor5-word-count/src/wordcount';
  37. import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';
  38. ClassicEditor
  39. .create( document.querySelector( '#editor' ), {
  40. plugins: [
  41. ArticlePluginSet, Underline, Strikethrough, Superscript, Subscript, Code, RemoveFormat,
  42. FontColor, FontBackgroundColor, FontFamily, FontSize, Highlight,
  43. CodeBlock, TodoList, TableProperties, TableCellProperties,
  44. EasyImage, ImageResize, LinkImage, AutoImage,
  45. AutoLink, Mention, TextTransformation,
  46. Alignment, IndentBlock,
  47. PageBreak, HorizontalLine,
  48. SpecialCharacters, SpecialCharactersEssentials, WordCount
  49. ],
  50. toolbar: [
  51. 'heading',
  52. '|',
  53. 'removeFormat', 'bold', 'italic', 'strikethrough', 'underline', 'code', 'subscript', 'superscript', 'link',
  54. '|',
  55. 'highlight', 'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor',
  56. '|',
  57. 'bulletedList', 'numberedList', 'todoList',
  58. '|',
  59. 'blockQuote', 'imageUpload', 'insertTable', 'mediaEmbed', 'codeBlock',
  60. '|',
  61. 'alignment', 'outdent', 'indent',
  62. '|',
  63. 'pageBreak', 'horizontalLine', 'specialCharacters',
  64. '|',
  65. 'undo', 'redo'
  66. ],
  67. cloudServices: CS_CONFIG,
  68. table: {
  69. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableProperties', 'tableCellProperties' ]
  70. },
  71. image: {
  72. styles: [
  73. 'alignCenter',
  74. 'alignLeft',
  75. 'alignRight'
  76. ],
  77. resizeOptions: [
  78. {
  79. name: 'imageResize:original',
  80. label: 'Original size',
  81. value: null
  82. },
  83. {
  84. name: 'imageResize:50',
  85. label: '50%',
  86. value: '50'
  87. },
  88. {
  89. name: 'imageResize:75',
  90. label: '75%',
  91. value: '75'
  92. }
  93. ],
  94. toolbar: [
  95. 'imageTextAlternative', '|',
  96. 'imageStyle:alignLeft', 'imageStyle:alignCenter', 'imageStyle:alignRight', '|',
  97. 'imageResize'
  98. ],
  99. insert: {
  100. integrations: [
  101. 'insertImageViaUrl'
  102. ]
  103. }
  104. },
  105. placeholder: 'Type the content here!',
  106. mention: {
  107. feeds: [
  108. {
  109. marker: '@',
  110. feed: [
  111. '@apple', '@bears', '@brownie', '@cake', '@cake', '@candy', '@canes', '@chocolate', '@cookie', '@cotton', '@cream',
  112. '@cupcake', '@danish', '@donut', '@dragée', '@fruitcake', '@gingerbread', '@gummi', '@ice', '@jelly-o',
  113. '@liquorice', '@macaroon', '@marzipan', '@oat', '@pie', '@plum', '@pudding', '@sesame', '@snaps', '@soufflé',
  114. '@sugar', '@sweet', '@topping', '@wafer'
  115. ],
  116. minimumCharacters: 1
  117. }
  118. ]
  119. },
  120. link: {
  121. decorators: {
  122. isExternal: {
  123. mode: 'manual',
  124. label: 'Open in a new tab',
  125. attributes: {
  126. target: '_blank',
  127. rel: 'noopener noreferrer'
  128. }
  129. },
  130. isDownloadable: {
  131. mode: 'manual',
  132. label: 'Downloadable',
  133. attributes: {
  134. download: 'download'
  135. }
  136. },
  137. isGallery: {
  138. mode: 'manual',
  139. label: 'Gallery link',
  140. attributes: {
  141. class: 'gallery'
  142. }
  143. }
  144. }
  145. }
  146. } )
  147. .then( editor => {
  148. window.editor = editor;
  149. editor.plugins.get( 'WordCount' ).on( 'update', ( evt, stats ) => {
  150. console.log( `Characters: ${ stats.characters }, words: ${ stats.words }.` );
  151. } );
  152. document.getElementById( 'clear-content' ).addEventListener( 'click', () => {
  153. editor.setData( '' );
  154. } );
  155. // The "Print editor data" button logic.
  156. document.getElementById( 'print-data-action' ).addEventListener( 'click', () => {
  157. const iframeElement = document.getElementById( 'print-data-container' );
  158. /* eslint-disable max-len */
  159. iframeElement.srcdoc = '<html>' +
  160. '<head>' +
  161. `<title>${ document.title }</title>` +
  162. '<link rel="stylesheet" href="https://ckeditor.com/docs/ckeditor5/latest/snippets/features/page-break/snippet.css" type="text/css">' +
  163. '</head>' +
  164. '<body class="ck-content">' +
  165. editor.getData() +
  166. '<script>' +
  167. 'window.addEventListener( \'DOMContentLoaded\', () => { window.print(); } );' +
  168. '</script>' +
  169. '</body>' +
  170. '</html>';
  171. /* eslint-enable max-len */
  172. } );
  173. const button = document.getElementById( 'read-only' );
  174. button.addEventListener( 'click', () => {
  175. editor.isReadOnly = !editor.isReadOnly;
  176. button.textContent = editor.isReadOnly ? 'Turn off read-only mode' : 'Turn on read-only mode';
  177. editor.focus();
  178. } );
  179. } )
  180. .catch( err => {
  181. console.error( err.stack );
  182. } );