italicui.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module basic-styles/italic/italicui
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import italicIcon from '../../theme/icons/italic.svg';
  11. const ITALIC = 'italic';
  12. /**
  13. * The italic UI feature. It introduces the Italic button.
  14. *
  15. * @extends module:core/plugin~Plugin
  16. */
  17. export default class ItalicUI extends Plugin {
  18. /**
  19. * @inheritDoc
  20. */
  21. init() {
  22. const editor = this.editor;
  23. const t = editor.t;
  24. // Add bold button to feature components.
  25. editor.ui.componentFactory.add( ITALIC, locale => {
  26. const command = editor.commands.get( ITALIC );
  27. const view = new ButtonView( locale );
  28. view.set( {
  29. label: t( 'Italic' ),
  30. icon: italicIcon,
  31. keystroke: 'CTRL+I',
  32. tooltip: true,
  33. isToggleable: true
  34. } );
  35. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  36. // Execute command.
  37. this.listenTo( view, 'execute', () => {
  38. editor.execute( ITALIC );
  39. editor.focus();
  40. } );
  41. return view;
  42. } );
  43. }
  44. }