8
0

restrictedediting.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @license Copyright (c) 2003-2019, 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 RestrictedEditingException from '../../src/restrictededitingexception';
  10. import RestrictedEditing from '../../src/restrictedediting';
  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. startStandardMode();
  16. function handleModeChange( evt ) {
  17. if ( evt.target.value === 'standard' ) {
  18. startStandardMode();
  19. } else {
  20. startRestrictedMode();
  21. }
  22. }
  23. async function startStandardMode() {
  24. await reloadEditor( {
  25. plugins: [ ArticlePluginSet, Table, RestrictedEditingException ],
  26. toolbar: [
  27. 'heading', '|', 'bold', 'italic', 'link', '|',
  28. 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', '|',
  29. 'restrictedEditingException', '|', 'undo', 'redo'
  30. ],
  31. image: {
  32. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
  33. },
  34. table: {
  35. contentToolbar: [
  36. 'tableColumn',
  37. 'tableRow',
  38. 'mergeTableCells'
  39. ]
  40. }
  41. } );
  42. }
  43. async function startRestrictedMode() {
  44. await reloadEditor( {
  45. plugins: [ ArticlePluginSet, Table, RestrictedEditing ],
  46. toolbar: [ 'bold', 'italic', 'link', '|', 'restrictedEditing', '|', 'undo', 'redo' ]
  47. } );
  48. }
  49. async function reloadEditor( config ) {
  50. if ( window.editor ) {
  51. await window.editor.destroy();
  52. }
  53. window.editor = await ClassicEditor.create( document.querySelector( '#editor' ), config );
  54. }