bold.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module basic-styles/bold
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import BoldEngine from './boldengine';
  10. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  11. import boldIcon from '../theme/icons/bold.svg';
  12. /**
  13. * The bold feature. It introduces the Bold button and the <kbd>Ctrl+B</kbd> keystroke.
  14. *
  15. * It uses the {@link module:basic-styles/boldengine~BoldEngine bold engine feature}.
  16. *
  17. * @extends module:core/plugin~Plugin
  18. */
  19. export default class Bold extends Plugin {
  20. /**
  21. * @inheritDoc
  22. */
  23. static get requires() {
  24. return [ BoldEngine ];
  25. }
  26. /**
  27. * @inheritDoc
  28. */
  29. static get pluginName() {
  30. return 'basic-styles/bold';
  31. }
  32. /**
  33. * @inheritDoc
  34. */
  35. init() {
  36. const editor = this.editor;
  37. const t = editor.t;
  38. const command = editor.commands.get( 'bold' );
  39. const keystroke = 'CTRL+B';
  40. // Add bold button to feature components.
  41. editor.ui.componentFactory.add( 'bold', locale => {
  42. const view = new ButtonView( locale );
  43. view.set( {
  44. label: t( 'Bold' ),
  45. icon: boldIcon,
  46. keystroke,
  47. tooltip: true
  48. } );
  49. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  50. // Execute command.
  51. this.listenTo( view, 'execute', () => editor.execute( 'bold' ) );
  52. return view;
  53. } );
  54. // Set the Ctrl+B keystroke.
  55. editor.keystrokes.set( keystroke, 'bold' );
  56. }
  57. }