all-features.js 5.5 KB

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