restrictedediting-focus.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import Table from '@ckeditor/ckeditor5-table/src/table';
  9. import StandardEditingMode from '../../src/standardeditingmode';
  10. import RestrictedEditingMode from '../../src/restrictededitingmode';
  11. const restrictedModeButton = document.getElementById( 'mode-restricted' );
  12. const standardModeButton = document.getElementById( 'mode-standard' );
  13. restrictedModeButton.addEventListener( 'change', handleModeChange );
  14. standardModeButton.addEventListener( 'change', handleModeChange );
  15. startMode( document.querySelector( 'input[name="mode"]:checked' ).value );
  16. async function handleModeChange( evt ) {
  17. await startMode( evt.target.value );
  18. }
  19. async function startMode( selectedMode ) {
  20. if ( selectedMode === 'standard' ) {
  21. await startStandardEditingMode();
  22. } else {
  23. await startRestrictedEditingMode();
  24. }
  25. }
  26. async function startStandardEditingMode() {
  27. await reloadEditor( {
  28. plugins: [ ArticlePluginSet, Table, StandardEditingMode ],
  29. toolbar: [
  30. 'heading', '|', 'bold', 'italic', 'link', '|',
  31. 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', '|',
  32. 'restrictedEditingException', '|', 'undo', 'redo'
  33. ],
  34. image: {
  35. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
  36. },
  37. table: {
  38. contentToolbar: [
  39. 'tableColumn',
  40. 'tableRow',
  41. 'mergeTableCells'
  42. ]
  43. }
  44. } );
  45. }
  46. async function startRestrictedEditingMode() {
  47. await reloadEditor( {
  48. plugins: [ ArticlePluginSet, Table, RestrictedEditingMode ],
  49. toolbar: [ 'bold', 'italic', 'link', '|', 'restrictedEditing', '|', 'undo', 'redo' ]
  50. } );
  51. }
  52. async function reloadEditor( config ) {
  53. if ( window.editor ) {
  54. await window.editor.destroy();
  55. }
  56. window.editor = await ClassicEditor.create( document.querySelector( '#editor' ), config );
  57. }