8
0

strike.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @license Copyright (c) 2017, CKSource - Rémy Hubscher. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module notes/ckeditor-build/strike
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import StrikeEngine from './strikeengine';
  10. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  11. import strikeIcon from '../theme/icons/strike.svg';
  12. /**
  13. * The strike feature. It introduces the Strike button and the <kbd>Ctrl+E</kbd> keystroke.
  14. *
  15. * It uses the {@link module:basic-styles/strikeengine~StrikeEngine strike engine feature}.
  16. *
  17. * @extends module:core/plugin~Plugin
  18. */
  19. export default class Strike extends Plugin {
  20. /**
  21. * @inheritDoc
  22. */
  23. static get requires() {
  24. return [ StrikeEngine ];
  25. }
  26. /**
  27. * @inheritDoc
  28. */
  29. static get pluginName() {
  30. return 'Strike';
  31. }
  32. /**
  33. * @inheritDoc
  34. */
  35. init() {
  36. const editor = this.editor;
  37. const t = editor.t;
  38. const command = editor.commands.get( 'strike' );
  39. const keystroke = 'CTRL+E';
  40. // Add strike button to feature components.
  41. editor.ui.componentFactory.add( 'strike', locale => {
  42. const view = new ButtonView( locale );
  43. view.set( {
  44. label: t( 'Strike' ),
  45. icon: strikeIcon,
  46. keystroke,
  47. tooltip: true
  48. } );
  49. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  50. // Execute command.
  51. this.listenTo( view, 'execute', () => editor.execute( 'strike' ) );
  52. return view;
  53. } );
  54. // Set the Ctrl+ALT+S keystroke.
  55. editor.keystrokes.set( keystroke, 'strike' );
  56. }
  57. }