italic.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/italic
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ItalicEngine from './italicengine';
  10. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  11. import italicIcon from '../theme/icons/italic.svg';
  12. /**
  13. * The italic feature. It introduces the Italic button and the <kbd>Ctrl+I</kbd> keystroke.
  14. *
  15. * It uses the {@link module:basic-styles/italicengine~ItalicEngine italic engine feature}.
  16. *
  17. * @extends module:core/plugin~Plugin
  18. */
  19. export default class Italic extends Plugin {
  20. /**
  21. * @inheritDoc
  22. */
  23. static get requires() {
  24. return [ ItalicEngine ];
  25. }
  26. /**
  27. * @inheritDoc
  28. */
  29. init() {
  30. const editor = this.editor;
  31. const t = editor.t;
  32. const command = editor.commands.get( 'italic' );
  33. const keystroke = 'CTRL+I';
  34. // Add bold button to feature components.
  35. editor.ui.componentFactory.add( 'italic', ( locale ) => {
  36. const view = new ButtonView( locale );
  37. view.set( {
  38. label: t( 'Italic' ),
  39. icon: italicIcon,
  40. keystroke,
  41. tooltip: true
  42. } );
  43. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  44. // Execute command.
  45. this.listenTo( view, 'execute', () => editor.execute( 'italic' ) );
  46. return view;
  47. } );
  48. // Set the Ctrl+I keystroke.
  49. editor.keystrokes.set( keystroke, 'italic' );
  50. }
  51. }