all-features.js 6.6 KB

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