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