removeformatui.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 remove-format/removeformatui
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import removeFormatIcon from '../theme/icons/remove-format.svg';
  11. const REMOVE_FORMAT = 'removeFormat';
  12. /**
  13. * The remove format UI plugin. It registers the `'removeFormat'` button which can be
  14. * used in the toolbar.
  15. *
  16. * @extends module:core/plugin~Plugin
  17. */
  18. export default class RemoveFormatUI extends Plugin {
  19. /**
  20. * @inheritDoc
  21. */
  22. static get pluginName() {
  23. return 'RemoveFormatUI';
  24. }
  25. /**
  26. * @inheritDoc
  27. */
  28. init() {
  29. const editor = this.editor;
  30. const t = editor.t;
  31. editor.ui.componentFactory.add( REMOVE_FORMAT, locale => {
  32. const command = editor.commands.get( REMOVE_FORMAT );
  33. const view = new ButtonView( locale );
  34. view.set( {
  35. label: t( 'Remove Format' ),
  36. icon: removeFormatIcon,
  37. tooltip: true
  38. } );
  39. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  40. // Execute the command.
  41. this.listenTo( view, 'execute', () => {
  42. editor.execute( REMOVE_FORMAT );
  43. editor.editing.view.focus();
  44. } );
  45. return view;
  46. } );
  47. }
  48. }