boldui.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 basic-styles/bold/boldui
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import boldIcon from '../../theme/icons/bold.svg';
  11. const BOLD = 'bold';
  12. /**
  13. * The bold UI feature. It introduces the Bold button.
  14. *
  15. * @extends module:core/plugin~Plugin
  16. */
  17. export default class BoldUI extends Plugin {
  18. /**
  19. * @inheritDoc
  20. */
  21. init() {
  22. const editor = this.editor;
  23. const t = editor.t;
  24. // Add bold button to feature components.
  25. editor.ui.componentFactory.add( BOLD, locale => {
  26. const command = editor.commands.get( BOLD );
  27. const view = new ButtonView( locale );
  28. view.set( {
  29. label: t( 'Bold' ),
  30. icon: boldIcon,
  31. keystroke: 'CTRL+B',
  32. tooltip: true,
  33. isToggleable: true
  34. } );
  35. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  36. // Execute command.
  37. this.listenTo( view, 'execute', () => editor.execute( BOLD ) );
  38. return view;
  39. } );
  40. }
  41. }