restrictedediting.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. const currentModeDisplay = document.getElementById( 'current-mode' );
  14. enableSwitchToStandardMode();
  15. enableSwitchToRestrictedMode();
  16. function enableSwitchToRestrictedMode() {
  17. restrictedModeButton.removeAttribute( 'disabled' );
  18. restrictedModeButton.addEventListener( 'click', startRestrictedMode );
  19. }
  20. function enableSwitchToStandardMode() {
  21. standardModeButton.removeAttribute( 'disabled' );
  22. standardModeButton.addEventListener( 'click', startStandardMode );
  23. }
  24. async function startStandardMode() {
  25. standardModeButton.removeEventListener( 'click', startStandardMode );
  26. standardModeButton.setAttribute( 'disabled', 'disabled' );
  27. await reloadEditor( {
  28. plugins: [ ArticlePluginSet, Table, RestrictedEditingException ],
  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. currentModeDisplay.innerHTML = 'Current Mode: <span class="mode mode-standard">STANDARD</span>';
  46. enableSwitchToRestrictedMode();
  47. }
  48. async function startRestrictedMode() {
  49. restrictedModeButton.removeEventListener( 'click', startRestrictedMode );
  50. restrictedModeButton.setAttribute( 'disabled', 'disabled' );
  51. await reloadEditor( {
  52. plugins: [ ArticlePluginSet, Table, RestrictedEditing ],
  53. toolbar: [ 'bold', 'italic', 'link', '|', 'restrictedEditing', '|', 'undo', 'redo' ]
  54. } );
  55. currentModeDisplay.innerHTML = 'Current Mode: <span class="mode mode-restricted">RESTRICTED</span>';
  56. enableSwitchToStandardMode();
  57. }
  58. async function reloadEditor( config ) {
  59. if ( window.editor ) {
  60. await window.editor.destroy();
  61. }
  62. window.editor = await ClassicEditor.create( document.querySelector( '#editor' ), config );
  63. }