restricteddocumentui.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 core/restricteddocumentui
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import restrictedDocumentIcon from '../theme/icons/restricted.svg';
  11. /**
  12. * @extends module:core/plugin~Plugin
  13. */
  14. export default class RestrictedDocumentUI extends Plugin {
  15. /**
  16. * @inheritDoc
  17. */
  18. init() {
  19. const editor = this.editor;
  20. const t = editor.t;
  21. editor.ui.componentFactory.add( 'nonRestricted', locale => {
  22. const command = editor.commands.get( 'nonRestricted' );
  23. const view = new ButtonView( locale );
  24. view.set( {
  25. label: t( 'Restricted editing' ),
  26. icon: restrictedDocumentIcon,
  27. tooltip: true,
  28. isToggleable: true
  29. } );
  30. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  31. this.listenTo( view, 'execute', () => editor.execute( 'nonRestricted' ) );
  32. return view;
  33. } );
  34. }
  35. }