italic.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 '../feature.js';
  6. import ItalicEngine from './italicengine.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. * Italic feature. It requires {@link basicStyles.ItalicEngine ItalicEngine feature}.
  12. * This feature creates also a UI component (`italic` button) and registers `CTRL+I` keystroke.
  13. *
  14. * @memberOf basicStyles
  15. * @extends ckeditor5.Feature
  16. */
  17. export default class Italic extends Feature {
  18. /**
  19. * @inheritDoc
  20. */
  21. static get requires() {
  22. return [ ItalicEngine ];
  23. }
  24. /**
  25. * @inheritDoc
  26. */
  27. init() {
  28. const editor = this.editor;
  29. const t = editor.t;
  30. const command = editor.commands.get( 'italic' );
  31. // Create button model.
  32. const buttonModel = new Model( {
  33. isEnabled: true,
  34. isOn: false,
  35. label: t( 'Italic' ),
  36. icon: 'italic',
  37. iconAlign: 'left'
  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( 'italic' ) );
  43. // Add bold button to feature components.
  44. editor.ui.featureComponents.add( 'italic', ButtonController, ButtonView, buttonModel );
  45. // Set the CTRL+I keystroke.
  46. editor.keystrokes.set( 'CTRL+I', 'italic' );
  47. }
  48. }