8
0

bold.js 1.3 KB

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