utils.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. * Loads a predefined set of performance markup files.
  40. *
  41. * loadPerformanceData()
  42. * .then( fixtures => {
  43. * window.editor.setData( fixtures.small );
  44. * console.log( fixtures.medium );
  45. * } );
  46. *
  47. * @returns {Promise.<Object.<String, String>>}
  48. */
  49. export function loadPerformanceData() {
  50. return Promise.resolve( {
  51. fullWebsitesStyled: fullWebsitesStyledFixture,
  52. large: largeFixture,
  53. medium: mediumFixture,
  54. small: smallFixture,
  55. smallInlineCss: smallInlineCssFixture,
  56. } );
  57. }
  58. /**
  59. * Creates a manual performance test editor instance.
  60. *
  61. * @param {HTMLElement} domElement
  62. * @returns {Promise.<module:core/editor/editor~Editor>}
  63. */
  64. export function createPerformanceEditor( domElement ) {
  65. const config = {
  66. plugins: [ ArticlePluginSet, FontColor, FontBackgroundColor, FontFamily, FontSize, Underline, StrikeThrough ],
  67. toolbar: [
  68. 'heading',
  69. '|',
  70. 'bold',
  71. 'italic',
  72. 'link',
  73. 'fontColor',
  74. 'fontBackgroundColor',
  75. 'fontFamily',
  76. 'fontSize',
  77. 'underline',
  78. 'strikeThrough',
  79. 'bulletedList',
  80. 'numberedList',
  81. '|',
  82. 'outdent',
  83. 'indent',
  84. '|',
  85. 'blockQuote',
  86. 'insertTable',
  87. 'mediaEmbed',
  88. 'undo',
  89. 'redo'
  90. ],
  91. fontSize: {
  92. options: [
  93. 11,
  94. 19,
  95. 32
  96. ]
  97. }
  98. };
  99. return ClassicEditor.create( domElement, config )
  100. .then( editor => {
  101. window.editor = editor;
  102. } )
  103. .catch( err => {
  104. console.error( err.stack );
  105. } );
  106. }