UNPKG

1.34 kBJavaScriptView Raw
1/**
2 * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4 */
5
6/**
7 * @module basic-styles/underline/underlineui
8 */
9
10import { Plugin } from 'ckeditor5/src/core';
11import { ButtonView } from 'ckeditor5/src/ui';
12
13import underlineIcon from '../../theme/icons/underline.svg';
14
15const UNDERLINE = 'underline';
16
17/**
18 * The underline UI feature. It introduces the Underline button.
19 *
20 * @extends module:core/plugin~Plugin
21 */
22export default class UnderlineUI extends Plugin {
23 /**
24 * @inheritDoc
25 */
26 static get pluginName() {
27 return 'UnderlineUI';
28 }
29
30 /**
31 * @inheritDoc
32 */
33 init() {
34 const editor = this.editor;
35 const t = editor.t;
36
37 // Add bold button to feature components.
38 editor.ui.componentFactory.add( UNDERLINE, locale => {
39 const command = editor.commands.get( UNDERLINE );
40 const view = new ButtonView( locale );
41
42 view.set( {
43 label: t( 'Underline' ),
44 icon: underlineIcon,
45 keystroke: 'CTRL+U',
46 tooltip: true,
47 isToggleable: true
48 } );
49
50 view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
51
52 // Execute command.
53 this.listenTo( view, 'execute', () => {
54 editor.execute( UNDERLINE );
55 editor.editing.view.focus();
56 } );
57
58 return view;
59 } );
60 }
61}