horizontallineui.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 horizontal-line/horizontallineui
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import horizontalLineIcon from '../theme/icons/horizontalline.svg';
  11. /**
  12. * The horizontal line UI plugin.
  13. *
  14. * @extends module:core/plugin~Plugin
  15. */
  16. export default class HorizontalLineUI extends Plugin {
  17. init() {
  18. const editor = this.editor;
  19. const t = editor.t;
  20. // Add the `horizontalLine` button to feature components.
  21. editor.ui.componentFactory.add( 'horizontalLine', locale => {
  22. const command = editor.commands.get( 'horizontalLine' );
  23. const view = new ButtonView( locale );
  24. view.set( {
  25. label: t( 'Horizontal line' ),
  26. icon: horizontalLineIcon,
  27. tooltip: true
  28. } );
  29. view.bind( 'isEnabled' ).to( command, 'isEnabled' );
  30. // Execute the command.
  31. this.listenTo( view, 'execute', () => {
  32. editor.execute( 'horizontalLine' );
  33. editor.editing.view.focus();
  34. } );
  35. return view;
  36. } );
  37. }
  38. }