multipleeditors.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import { getPerformanceData, renderPerformanceDataButtons } from '../../_utils/utils';
  9. const editorCount = 5;
  10. renderPerformanceDataButtons( document.querySelector( '#fixture-buttons' ) );
  11. const fixtures = getPerformanceData();
  12. const editorsWrapper = document.getElementById( 'editors-wrapper' );
  13. const buttons = document.querySelectorAll( '#test-controls button' );
  14. for ( let i = 0; i < editorCount; i++ ) {
  15. const editorElement = document.createElement( 'div' );
  16. editorElement.setAttribute( 'id', `editor_${ i }` );
  17. editorsWrapper.appendChild( editorElement );
  18. }
  19. for ( const button of buttons ) {
  20. const fixtureName = button.getAttribute( 'data-file-name' );
  21. const content = fixtures[ fixtureName ];
  22. button.addEventListener( 'click', function() {
  23. for ( let i = 0; i < editorCount; i++ ) {
  24. const editorElement = document.querySelector( `#editor_${ i }` );
  25. editorElement.innerHTML = content;
  26. ClassicEditor
  27. .create( editorElement, {
  28. plugins: [ ArticlePluginSet ],
  29. toolbar: [
  30. 'heading',
  31. '|',
  32. 'bold',
  33. 'italic',
  34. 'link',
  35. 'bulletedList',
  36. 'numberedList',
  37. '|',
  38. 'outdent',
  39. 'indent',
  40. '|',
  41. 'blockQuote',
  42. 'insertTable',
  43. 'mediaEmbed',
  44. 'undo',
  45. 'redo'
  46. ],
  47. image: {
  48. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
  49. },
  50. table: {
  51. contentToolbar: [
  52. 'tableColumn',
  53. 'tableRow',
  54. 'mergeTableCells'
  55. ]
  56. }
  57. } )
  58. .then( editor => {
  59. window.editor = editor;
  60. } )
  61. .catch( err => {
  62. console.error( err.stack );
  63. } );
  64. }
  65. } );
  66. button.disabled = false;
  67. }