all-features.js 6.9 KB

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