allfeatures.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';
  33. const COLOR_PALETTE = [
  34. { color: 'hsl(0, 0%, 0%)', label: 'Black' },
  35. { color: 'hsl(0, 0%, 30%)', label: 'Dim grey' },
  36. { color: 'hsl(0, 0%, 60%)', label: 'Grey' },
  37. { color: 'hsl(0, 0%, 90%)', label: 'Light grey' },
  38. { color: 'hsl(0, 0%, 100%)', label: 'White', hasBorder: true },
  39. { color: 'hsl(0, 100%, 89%)', label: 'Pink' },
  40. { color: 'hsl(0, 75%, 60%)', label: 'Red' },
  41. { color: 'hsl(60, 75%, 60%)', label: 'Yellow' },
  42. { color: 'hsl(27, 100%, 85%)', label: 'Light Orange' },
  43. { color: 'hsl(30, 75%, 60%)', label: 'Orange' },
  44. { color: 'hsl(90, 75%, 60%)', label: 'Light green' },
  45. { color: 'hsl(120, 75%, 60%)', label: 'Green' },
  46. { color: 'hsl(150, 75%, 60%)', label: 'Aquamarine' },
  47. { color: 'hsl(120, 100%, 25%)', label: 'Dark green' },
  48. { color: 'hsl(180, 75%, 60%)', label: 'Turquoise' },
  49. { color: 'hsl(180, 52%, 58%)', label: 'Light Aqua', },
  50. { color: 'hsl(180, 97%, 31%)', label: 'Aqua' },
  51. { color: 'hsl(210, 75%, 60%)', label: 'Light blue' },
  52. { color: 'hsl(240, 75%, 60%)', label: 'Blue' },
  53. { color: 'hsl(270, 75%, 60%)', label: 'Purple' }
  54. ];
  55. ClassicEditor
  56. .create( document.querySelector( '#editor' ), {
  57. plugins: [
  58. ArticlePluginSet, CodeBlock, Alignment,
  59. TableProperties, TableCellProperties, SpecialCharacters, SpecialCharactersEssentials,
  60. Code, Underline, Strikethrough, Superscript, Subscript,
  61. Highlight, FontColor, FontBackgroundColor, FontFamily, FontSize,
  62. IndentBlock, WordCount, EasyImage,
  63. TodoList, PageBreak, HorizontalLine, Mention, RemoveFormat
  64. ],
  65. toolbar: [
  66. 'heading',
  67. '|',
  68. 'removeFormat', 'bold', 'italic', 'strikethrough', 'underline', 'code', 'subscript', 'superscript', 'link',
  69. '|',
  70. 'highlight', 'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor',
  71. '|',
  72. 'bulletedList', 'numberedList', 'todoList',
  73. '|',
  74. 'blockQuote', 'imageUpload', 'insertTable', 'mediaEmbed', 'codeBlock',
  75. '|',
  76. 'alignment', 'outdent', 'indent',
  77. '|',
  78. 'pageBreak', 'horizontalLine', 'specialCharacters',
  79. '|',
  80. 'undo', 'redo'
  81. ],
  82. cloudServices: CS_CONFIG,
  83. table: {
  84. contentToolbar: [ 'tableColumn', 'tableRow', 'mergeTableCells', 'tableProperties', 'tableCellProperties' ],
  85. tableProperties: {
  86. borderColors: COLOR_PALETTE,
  87. backgroundColors: COLOR_PALETTE
  88. },
  89. tableCellProperties: {
  90. borderColors: COLOR_PALETTE,
  91. backgroundColors: COLOR_PALETTE
  92. }
  93. },
  94. image: {
  95. styles: [
  96. 'full',
  97. 'alignLeft',
  98. 'alignRight'
  99. ],
  100. toolbar: [ 'imageTextAlternative', '|', 'imageStyle:alignLeft', 'imageStyle:full', 'imageStyle:alignRight' ]
  101. },
  102. placeholder: 'Type the content here!',
  103. mention: {
  104. feeds: [
  105. {
  106. marker: '@',
  107. feed: [ '@Barney', '@Lily', '@Marshall', '@Robin', '@Ted' ],
  108. minimumCharacters: 1
  109. }
  110. ]
  111. }
  112. } )
  113. .then( editor => {
  114. window.editor = editor;
  115. editor.plugins.get( 'WordCount' ).on( 'update', ( evt, stats ) => {
  116. console.log( `Characters: ${ stats.characters }, words: ${ stats.words }.` );
  117. } );
  118. document.getElementById( 'clear-content' ).addEventListener( 'click', () => {
  119. editor.setData( '' );
  120. } );
  121. // The "Print editor data" button logic.
  122. document.getElementById( 'print-data-action' ).addEventListener( 'click', () => {
  123. const iframeElement = document.getElementById( 'print-data-container' );
  124. /* eslint-disable max-len */
  125. iframeElement.srcdoc = '<html>' +
  126. '<head>' +
  127. `<title>${ document.title }</title>` +
  128. '<link rel="stylesheet" href="https://ckeditor.com/docs/ckeditor5/latest/snippets/features/page-break/snippet.css" type="text/css">' +
  129. '</head>' +
  130. '<body class="ck-content">' +
  131. editor.getData() +
  132. '<script>' +
  133. 'window.addEventListener( \'DOMContentLoaded\', () => { window.print(); } );' +
  134. '</script>' +
  135. '</body>' +
  136. '</html>';
  137. /* eslint-enable max-len */
  138. } );
  139. const button = document.getElementById( 'read-only' );
  140. button.addEventListener( 'click', () => {
  141. editor.isReadOnly = !editor.isReadOnly;
  142. button.textContent = editor.isReadOnly ? 'Turn off read-only mode' : 'Turn on read-only mode';
  143. editor.editing.view.focus();
  144. } );
  145. } )
  146. .catch( err => {
  147. console.error( err.stack );
  148. } );