restrictededitingexceptionui.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. /**
  6. * @module restricted-editing/restrictededitingexceptionui
  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. * @extends module:core/plugin~Plugin
  13. */
  14. export default class RestrictedEditingExceptionUI extends Plugin {
  15. /**
  16. * @inheritDoc
  17. */
  18. init() {
  19. const editor = this.editor;
  20. const t = editor.t;
  21. editor.ui.componentFactory.add( 'restrictedEditingException', locale => {
  22. const command = editor.commands.get( 'restrictedEditingException' );
  23. const view = new ButtonView( locale );
  24. view.set( {
  25. icon: unlockIcon,
  26. tooltip: true,
  27. isToggleable: true
  28. } );
  29. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  30. view.bind( 'label' ).to( command, 'value', value => {
  31. return value ? t( 'Disable editing' ) : t( 'Enable editing' );
  32. } );
  33. this.listenTo( view, 'execute', () => editor.execute( 'restrictedEditingException' ) );
  34. return view;
  35. } );
  36. }
  37. }