bold.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Feature from '../core/feature.js';
  6. import BoldEngine from './boldengine.js';
  7. import ButtonController from '../ui/button/button.js';
  8. import ButtonView from '../ui/button/buttonview.js';
  9. import Model from '../ui/model.js';
  10. /**
  11. * The Bold feature. It introduces the `bold` button and <kbd>CTRL+B</kbd> keystroke.
  12. *
  13. * It uses the {@link basic-styles.BoldEngine Bold engine feature}.
  14. *
  15. * @memberOf basic-styles
  16. * @extends core.Feature
  17. */
  18. export default class Bold extends Feature {
  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. // Create button model.
  33. const buttonModel = new Model( {
  34. isEnabled: true,
  35. isOn: false,
  36. label: t( 'Bold' ),
  37. icon: 'bold'
  38. } );
  39. // Bind button model to command.
  40. buttonModel.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  41. // Execute command.
  42. this.listenTo( buttonModel, 'execute', () => editor.execute( 'bold' ) );
  43. // Add bold button to feature components.
  44. editor.ui.featureComponents.add( 'bold', ButtonController, ButtonView, buttonModel );
  45. // Set the CTRL+B keystroke.
  46. editor.keystrokes.set( 'CTRL+B', 'bold' );
  47. }
  48. }