restrictedediting.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. enableSwitchToStandardMode();
  14. enableSwitchToRestrictedMode();
  15. function enableSwitchToRestrictedMode() {
  16. restrictedModeButton.removeAttribute( 'disabled' );
  17. restrictedModeButton.addEventListener( 'click', startRestrictedMode );
  18. }
  19. function enableSwitchToStandardMode() {
  20. standardModeButton.removeAttribute( 'disabled' );
  21. standardModeButton.addEventListener( 'click', startStandardMode );
  22. }
  23. async function startStandardMode() {
  24. standardModeButton.removeEventListener( 'click', startStandardMode );
  25. standardModeButton.setAttribute( 'disabled', 'disabled' );
  26. await reloadEditor( {
  27. plugins: [ ArticlePluginSet, Table, RestrictedEditingException ],
  28. toolbar: [
  29. 'heading', '|', 'bold', 'italic', 'link', '|',
  30. 'bulletedList', 'numberedList', 'blockQuote', 'insertTable', '|',
  31. 'restrictedEditingException', '|', 'undo', 'redo'
  32. ],
  33. image: {
  34. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
  35. },
  36. table: {
  37. contentToolbar: [
  38. 'tableColumn',
  39. 'tableRow',
  40. 'mergeTableCells'
  41. ]
  42. }
  43. } );
  44. enableSwitchToRestrictedMode();
  45. }
  46. async function startRestrictedMode() {
  47. restrictedModeButton.removeEventListener( 'click', startRestrictedMode );
  48. restrictedModeButton.setAttribute( 'disabled', 'disabled' );
  49. await reloadEditor( {
  50. plugins: [ ArticlePluginSet, Table, RestrictedEditing ],
  51. toolbar: [ 'bold', 'italic', 'link', '|', 'restrictedEditing', '|', 'undo', 'redo' ]
  52. } );
  53. enableSwitchToStandardMode();
  54. }
  55. async function reloadEditor( config ) {
  56. if ( window.editor ) {
  57. await window.editor.destroy();
  58. }
  59. window.editor = await ClassicEditor.create( document.querySelector( '#editor' ), config );
  60. }