| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- /**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- /* globals console, window, document */
- import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
- import ArticlePluginSet from '../_utils/articlepluginset';
- import MultiCommand from '../../src/multicommand';
- import Plugin from '../../src/plugin';
- import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
- class IndentOutdent extends Plugin {
- init() {
- const editor = this.editor;
- const t = editor.t;
- this._createButton( 'indent', t( 'Indent' ) );
- this._createButton( 'outdent', t( 'Outdent' ) );
- }
- _createButton( commandName, label ) {
- const editor = this.editor;
- editor.ui.componentFactory.add( commandName, locale => {
- const command = editor.commands.get( commandName );
- const view = new ButtonView( locale );
- view.set( {
- label,
- withText: true,
- tooltip: true
- } );
- view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
- // Execute command.
- this.listenTo( view, 'execute', () => editor.execute( commandName ) );
- return view;
- } );
- }
- afterInit() {
- const editor = this.editor;
- const indentCommand = new MultiCommand( editor );
- indentCommand.registerChildCommand( editor.commands.get( 'indentList' ) );
- editor.commands.add( 'indent', indentCommand );
- const outdentCommand = new MultiCommand( editor );
- outdentCommand.registerChildCommand( editor.commands.get( 'outdentList' ) );
- editor.commands.add( 'outdent', outdentCommand );
- }
- }
- class IndentBlock extends Plugin {
- init() {
- const schema = this.editor.model.schema;
- const conversion = this.editor.conversion;
- schema.extend( 'paragraph', { allowAttributes: 'indent' } );
- schema.extend( 'heading1', { allowAttributes: 'indent' } );
- conversion.for( 'upcast' ).attributeToAttribute( {
- view: {
- styles: {
- 'margin-left': /[\s\S]+/
- }
- },
- model: {
- key: 'indent',
- value: viewElement => {
- return viewElement.getStyle( 'margin-left' );
- }
- }
- } );
- conversion.for( 'downcast' ).attributeToAttribute( {
- model: 'indent',
- view: modelAttributeValue => {
- return {
- key: 'style',
- value: {
- 'margin-left': modelAttributeValue
- }
- };
- }
- } );
- }
- }
- ClassicEditor
- .create( document.querySelector( '#editor' ), {
- plugins: [ ArticlePluginSet, IndentOutdent, IndentBlock ],
- toolbar: [
- 'heading',
- '|',
- 'bold',
- 'italic',
- 'link',
- '|',
- 'indent',
- 'outdent',
- '|',
- 'bulletedList',
- 'numberedList',
- '|',
- 'blockQuote',
- 'insertTable',
- 'mediaEmbed',
- 'undo',
- 'redo'
- ],
- image: {
- toolbar: [ 'imageStyle:full', 'imageStyle:side', '|', 'imageTextAlternative' ]
- },
- table: {
- contentToolbar: [
- 'tableColumn',
- 'tableRow',
- 'mergeTableCells'
- ]
- }
- } )
- .then( editor => {
- window.editor = editor;
- } )
- .catch( err => {
- console.error( err.stack );
- } );
|