| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- /**
- * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- /* globals window, console */
- import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
- import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
- import FontColor from '@ckeditor/ckeditor5-font/src/fontcolor';
- import FontBackgroundColor from '@ckeditor/ckeditor5-font/src/fontbackgroundcolor';
- import FontFamily from '@ckeditor/ckeditor5-font/src/fontfamily';
- import FontSize from '@ckeditor/ckeditor5-font/src/fontsize';
- import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
- import StrikeThrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough';
- const predefinedFiles = [
- 'small',
- 'medium',
- 'large',
- 'small-inline-css',
- 'full-websites-styled'
- ];
- /**
- * Renders a button for each performance fixture in a given `container`.
- *
- * @param {HTMLElement} container
- */
- export function renderPerformanceDataButtons( container ) {
- let html = '';
- const labels = {
- 'small': 'small (semantic)',
- 'medium': 'medium (semantic)',
- 'large': 'large (semantic)',
- 'small-inline-css': 'Small inline styled',
- 'full-websites-styled': 'Full websites (styled)',
- };
- for ( const fixtureName of predefinedFiles ) {
- html += `<button id="${ fixtureName }-content" data-file-name="${ fixtureName }" disabled>${ labels[ fixtureName ] }</button>`;
- }
- container.innerHTML = html;
- }
- /**
- * Loads a predefined set of performance markup files.
- *
- * loadPerformanceData()
- * .then( fixtures => {
- * window.editor.setData( fixtures.small );
- * console.log( fixtures.medium );
- * } );
- *
- * @returns {Promise.<Object.<String, String>>}
- */
- export function loadPerformanceData() {
- return Promise.all( predefinedFiles.map( fileName => getFileContents( fileName ) ) )
- .then( responses => {
- const returnValue = {};
- for ( let i = 0; i < predefinedFiles.length; i++ ) {
- returnValue[ predefinedFiles[ i ] ] = responses[ i ];
- }
- return returnValue;
- } );
- function getFileContents( fileName ) {
- return window.fetch( `_utils/${ fileName }.txt` )
- .then( resp => resp.text() );
- }
- }
- /**
- * Creates a manual performance test editor instance.
- *
- * @param {HTMLElement} domElement
- * @returns {Promise.<module:core/editor/editor~Editor>}
- */
- export function createPerformanceEditor( domElement ) {
- const config = {
- plugins: [ ArticlePluginSet, FontColor, FontBackgroundColor, FontFamily, FontSize, Underline, StrikeThrough ],
- toolbar: [
- 'heading',
- '|',
- 'bold',
- 'italic',
- 'link',
- 'fontColor',
- 'fontBackgroundColor',
- 'fontFamily',
- 'fontSize',
- 'underline',
- 'strikeThrough',
- 'bulletedList',
- 'numberedList',
- '|',
- 'outdent',
- 'indent',
- '|',
- 'blockQuote',
- 'insertTable',
- 'mediaEmbed',
- 'undo',
- 'redo'
- ],
- fontSize: {
- options: [
- 11,
- 19,
- 32
- ]
- }
- };
- return ClassicEditor.create( domElement, config )
- .then( editor => {
- window.editor = editor;
- } )
- .catch( err => {
- console.error( err.stack );
- } );
- }
|