blockquoteui.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 block-quote/blockquoteui
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import quoteIcon from '@ckeditor/ckeditor5-core/theme/icons/quote.svg';
  11. import '../theme/blockquote.css';
  12. /**
  13. * The block quote UI plugin.
  14. *
  15. * It introduces the `'blockQuote'` button.
  16. *
  17. * @extends module:core/plugin~Plugin
  18. */
  19. export default class BlockQuoteUI extends Plugin {
  20. /**
  21. * @inheritDoc
  22. */
  23. init() {
  24. const editor = this.editor;
  25. const t = editor.t;
  26. editor.ui.componentFactory.add( 'blockQuote', locale => {
  27. const command = editor.commands.get( 'blockQuote' );
  28. const buttonView = new ButtonView( locale );
  29. buttonView.set( {
  30. label: t( 'Block quote' ),
  31. icon: quoteIcon,
  32. tooltip: true,
  33. isToggleable: true
  34. } );
  35. // Bind button model to command.
  36. buttonView.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  37. // Execute command.
  38. this.listenTo( buttonView, 'execute', () => {
  39. editor.execute( 'blockQuote' );
  40. editor.editing.view.focus();
  41. } );
  42. return buttonView;
  43. } );
  44. }
  45. }