8
0

superscriptui.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @license Copyright (c) 2003-2019, 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/superscript/superscriptui
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import superscriptIcon from '../../theme/icons/superscript.svg';
  11. const SUPERSCRIPT = 'superscript';
  12. /**
  13. * The superscript UI feature. It introduces the Superscript button.
  14. *
  15. * @extends module:core/plugin~Plugin
  16. */
  17. export default class SuperscriptUI extends Plugin {
  18. /**
  19. * @inheritDoc
  20. */
  21. init() {
  22. const editor = this.editor;
  23. const t = editor.t;
  24. // Add superscript button to feature components.
  25. editor.ui.componentFactory.add( SUPERSCRIPT, locale => {
  26. const command = editor.commands.get( SUPERSCRIPT );
  27. const view = new ButtonView( locale );
  28. view.set( {
  29. label: t( 'Superscript' ),
  30. icon: superscriptIcon,
  31. tooltip: true
  32. } );
  33. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  34. // Execute command.
  35. this.listenTo( view, 'execute', () => editor.execute( SUPERSCRIPT ) );
  36. return view;
  37. } );
  38. }
  39. }