bold.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. iconAlign: 'left'
  39. } );
  40. // Bind button model to command.
  41. buttonModel.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  42. // Execute command.
  43. this.listenTo( buttonModel, 'execute', () => editor.execute( 'bold' ) );
  44. // Add bold button to feature components.
  45. editor.ui.featureComponents.add( 'bold', ButtonController, ButtonView, buttonModel );
  46. // Set the CTRL+B keystroke.
  47. editor.keystrokes.set( 'CTRL+B', 'bold' );
  48. }
  49. }