This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
listui.js
64 lines (53 loc) · 1.78 KB
/
listui.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
/**
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
/**
* @module list/listui
*/
import numberedListIcon from '../theme/icons/numberedlist.svg';
import bulletedListIcon from '../theme/icons/bulletedlist.svg';
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
/**
* The list UI feature. It introduces the `'numberedList'` and `'bulletedList'` buttons that
* allow to convert paragraphs to and from list items and indent or outdent them.
*
* @extends module:core/plugin~Plugin
*/
export default class ListUI extends Plugin {
/**
* @inheritDoc
*/
init() {
// Create two buttons and link them with numberedList and bulletedList commands.
const t = this.editor.t;
this._addButton( 'numberedList', t( 'Numbered List' ), numberedListIcon );
this._addButton( 'bulletedList', t( 'Bulleted List' ), bulletedListIcon );
}
/**
* Helper method for initializing a button and linking it with an appropriate command.
*
* @private
* @param {String} commandName The name of the command.
* @param {Object} label The button label.
* @param {String} icon The source of the icon.
*/
_addButton( commandName, label, icon ) {
const editor = this.editor;
editor.ui.componentFactory.add( commandName, locale => {
const command = editor.commands.get( commandName );
const buttonView = new ButtonView( locale );
buttonView.set( {
label,
icon,
tooltip: true
} );
// Bind button model to command.
buttonView.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
// Execute command.
this.listenTo( buttonView, 'execute', () => editor.execute( commandName ) );
return buttonView;
} );
}
}