/
indentui.js
79 lines (67 loc) · 2 KB
/
indentui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module indent/indentui
*/
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import indentIcon from '../theme/icons/indent.svg';
import outdentIcon from '../theme/icons/outdent.svg';
/**
* The indent UI feature.
*
* This plugin registers the `'indent'` and `'outdent'` buttons.
*
* **Note**: In order for the commands to work, at least one of the compatible features is required. Read more in
* the {@link module:indent/indent~Indent indent feature} API documentation.
*
* @extends module:core/plugin~Plugin
*/
export default class IndentUI extends Plugin {
/**
* @inheritDoc
*/
static get pluginName() {
return 'IndentUI';
}
/**
* @inheritDoc
*/
init() {
const editor = this.editor;
const locale = editor.locale;
const t = editor.t;
const localizedIndentIcon = locale.uiLanguageDirection == 'ltr' ? indentIcon : outdentIcon;
const localizedOutdentIcon = locale.uiLanguageDirection == 'ltr' ? outdentIcon : indentIcon;
this._defineButton( 'indent', t( 'Increase indent' ), localizedIndentIcon );
this._defineButton( 'outdent', t( 'Decrease indent' ), localizedOutdentIcon );
}
/**
* Defines a UI button.
*
* @param {String} commandName
* @param {String} label
* @param {String} icon
* @private
*/
_defineButton( commandName, label, icon ) {
const editor = this.editor;
editor.ui.componentFactory.add( commandName, locale => {
const command = editor.commands.get( commandName );
const view = new ButtonView( locale );
view.set( {
label,
icon,
tooltip: true
} );
view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
this.listenTo( view, 'execute', () => {
editor.execute( commandName );
editor.editing.view.focus();
} );
return view;
} );
}
}