8
0

standardeditingmodeui.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /**
  6. * @module restricted-editing/standardeditingmodeui
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import unlockIcon from '../theme/icons/contentunlock.svg';
  11. /**
  12. * The standard editing mode UI feature.
  13. *
  14. * It introduces the `'restrictedEditingException'` button that marks text as unrestricted for editing.
  15. *
  16. * @extends module:core/plugin~Plugin
  17. */
  18. export default class StandardEditingModeUI extends Plugin {
  19. /**
  20. * @inheritDoc
  21. */
  22. init() {
  23. const editor = this.editor;
  24. const t = editor.t;
  25. editor.ui.componentFactory.add( 'restrictedEditingException', locale => {
  26. const command = editor.commands.get( 'restrictedEditingException' );
  27. const view = new ButtonView( locale );
  28. view.set( {
  29. icon: unlockIcon,
  30. tooltip: true,
  31. isToggleable: true
  32. } );
  33. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  34. view.bind( 'label' ).to( command, 'value', value => {
  35. return value ? t( 'Disable editing' ) : t( 'Enable editing' );
  36. } );
  37. this.listenTo( view, 'execute', () => {
  38. editor.execute( 'restrictedEditingException' );
  39. editor.editing.view.focus();
  40. } );
  41. return view;
  42. } );
  43. }
  44. }