utils.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 window, console */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import FontColor from '@ckeditor/ckeditor5-font/src/fontcolor';
  9. import FontBackgroundColor from '@ckeditor/ckeditor5-font/src/fontbackgroundcolor';
  10. import FontFamily from '@ckeditor/ckeditor5-font/src/fontfamily';
  11. import FontSize from '@ckeditor/ckeditor5-font/src/fontsize';
  12. import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
  13. import StrikeThrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough';
  14. import smallFixture from '../_data/small.html';
  15. import mediumFixture from '../_data/medium.html';
  16. import largeFixture from '../_data/large.html';
  17. import smallInlineCssFixture from '../_data/small-inline-css.html';
  18. import fullWebsitesStyledFixture from '../_data/full-websites-styled.html';
  19. /**
  20. * Renders a button for each performance fixture in a given `container`.
  21. *
  22. * @param {HTMLElement} container
  23. */
  24. export function renderPerformanceDataButtons( container ) {
  25. let html = '';
  26. const labels = {
  27. 'small': 'short (semantic)',
  28. 'medium': 'medium (semantic)',
  29. 'large': 'long (semantic)',
  30. 'smallInlineCss': 'short inline styled',
  31. 'fullWebsitesStyled': 'full websites (styled)',
  32. };
  33. for ( const fixtureName of Object.keys( labels ) ) {
  34. html += `<button id="${ fixtureName }-content" data-file-name="${ fixtureName }" disabled>${ labels[ fixtureName ] }</button>`;
  35. }
  36. container.innerHTML = html;
  37. }
  38. /**
  39. * Returns a predefined set of performance markup files.
  40. *
  41. * const fixtures = loadPerformanceData();
  42. * window.editor.setData( fixtures.small );
  43. * console.log( fixtures.medium );
  44. *
  45. * @returns {Object.<String, String>}
  46. */
  47. export function getPerformanceData() {
  48. return {
  49. small: smallFixture,
  50. medium: mediumFixture,
  51. large: largeFixture,
  52. smallInlineCss: smallInlineCssFixture,
  53. fullWebsitesStyled: fullWebsitesStyledFixture,
  54. };
  55. }
  56. /**
  57. * Creates a manual performance test editor instance.
  58. *
  59. * @param {HTMLElement} domElement
  60. * @returns {Promise.<module:core/editor/editor~Editor>}
  61. */
  62. export function createPerformanceEditor( domElement ) {
  63. const config = {
  64. plugins: [ ArticlePluginSet, FontColor, FontBackgroundColor, FontFamily, FontSize, Underline, StrikeThrough ],
  65. toolbar: [
  66. 'heading',
  67. '|',
  68. 'bold',
  69. 'italic',
  70. 'link',
  71. 'fontColor',
  72. 'fontBackgroundColor',
  73. 'fontFamily',
  74. 'fontSize',
  75. 'underline',
  76. 'strikeThrough',
  77. 'bulletedList',
  78. 'numberedList',
  79. '|',
  80. 'outdent',
  81. 'indent',
  82. '|',
  83. 'blockQuote',
  84. 'insertTable',
  85. 'mediaEmbed',
  86. 'undo',
  87. 'redo'
  88. ],
  89. fontSize: {
  90. options: [
  91. 11,
  92. 19,
  93. 32
  94. ]
  95. }
  96. };
  97. return ClassicEditor.create( domElement, config )
  98. .then( editor => {
  99. window.editor = editor;
  100. return editor;
  101. } )
  102. .catch( err => {
  103. console.error( err.stack );
  104. } );
  105. }