8
0

subscriptui.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/subscript/subscriptui
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import subscriptIcon from '../../theme/icons/subscript.svg';
  11. const SUBSCRIPT = 'subscript';
  12. /**
  13. * The subscript UI feature. It introduces the Subscript button.
  14. *
  15. * @extends module:core/plugin~Plugin
  16. */
  17. export default class SubscriptUI extends Plugin {
  18. /**
  19. * @inheritDoc
  20. */
  21. init() {
  22. const editor = this.editor;
  23. const t = editor.t;
  24. // Add subscript button to feature components.
  25. editor.ui.componentFactory.add( SUBSCRIPT, locale => {
  26. const command = editor.commands.get( SUBSCRIPT );
  27. const view = new ButtonView( locale );
  28. view.set( {
  29. label: t( 'Subscript' ),
  30. icon: subscriptIcon,
  31. tooltip: true,
  32. isToggleable: true
  33. } );
  34. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  35. // Execute command.
  36. this.listenTo( view, 'execute', () => {
  37. editor.execute( SUBSCRIPT );
  38. editor.editing.view.focus();
  39. } );
  40. return view;
  41. } );
  42. }
  43. }