8
0

indent-block.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /* globals console, window, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import MultiCommand from '@ckeditor/ckeditor5-core/src/multicommand';
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import IndentBlock from '../../src/indentblock';
  11. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  12. class Indent extends Plugin {
  13. init() {
  14. const editor = this.editor;
  15. const t = editor.t;
  16. editor.commands.add( 'indent', new MultiCommand( editor ) );
  17. editor.commands.add( 'outdent', new MultiCommand( editor ) );
  18. this._createButton( 'indent', t( '>' ) );
  19. this._createButton( 'outdent', t( '<' ) );
  20. // TODO: temporary - tests only
  21. this._createButton( 'indentList', t( '> List' ) );
  22. this._createButton( 'outdentList', t( '< List' ) );
  23. // TODO: temporary - tests only
  24. this._createButton( 'indentBlock', t( '> Block' ) );
  25. this._createButton( 'outdentBlock', t( '< Block' ) );
  26. }
  27. _createButton( commandName, label ) {
  28. const editor = this.editor;
  29. editor.ui.componentFactory.add( commandName, locale => {
  30. const command = editor.commands.get( commandName );
  31. const view = new ButtonView( locale );
  32. view.set( {
  33. label,
  34. withText: true,
  35. tooltip: true
  36. } );
  37. view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
  38. // Execute command.
  39. this.listenTo( view, 'execute', () => editor.execute( commandName ) );
  40. return view;
  41. } );
  42. }
  43. }
  44. ClassicEditor
  45. .create( document.querySelector( '#editor' ), {
  46. plugins: [ ArticlePluginSet, Indent, IndentBlock ],
  47. toolbar: [
  48. 'heading',
  49. '|',
  50. 'indent',
  51. 'outdent',
  52. '|',
  53. 'indentList',
  54. 'outdentList',
  55. '|',
  56. 'indentBlock',
  57. 'outdentBlock',
  58. '|',
  59. 'bulletedList',
  60. 'numberedList',
  61. '|',
  62. 'blockQuote',
  63. 'insertTable',
  64. 'undo',
  65. 'redo'
  66. ],
  67. image: {
  68. toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
  69. },
  70. table: {
  71. contentToolbar: [
  72. 'tableColumn',
  73. 'tableRow',
  74. 'mergeTableCells'
  75. ]
  76. }
  77. } )
  78. .then( editor => {
  79. window.editor = editor;
  80. } )
  81. .catch( err => {
  82. console.error( err.stack );
  83. } );