UNPKG

1.42 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/strikethrough/strikethroughui
8 */
9
10import { Plugin } from 'ckeditor5/src/core';
11import { ButtonView } from 'ckeditor5/src/ui';
12
13import strikethroughIcon from '../../theme/icons/strikethrough.svg';
14
15const STRIKETHROUGH = 'strikethrough';
16
17/**
18 * The strikethrough UI feature. It introduces the Strikethrough button.
19 *
20 * @extends module:core/plugin~Plugin
21 */
22export default class StrikethroughUI extends Plugin {
23 /**
24 * @inheritDoc
25 */
26 static get pluginName() {
27 return 'StrikethroughUI';
28 }
29
30 /**
31 * @inheritDoc
32 */
33 init() {
34 const editor = this.editor;
35 const t = editor.t;
36
37 // Add strikethrough button to feature components.
38 editor.ui.componentFactory.add( STRIKETHROUGH, locale => {
39 const command = editor.commands.get( STRIKETHROUGH );
40 const view = new ButtonView( locale );
41
42 view.set( {
43 label: t( 'Strikethrough' ),
44 icon: strikethroughIcon,
45 keystroke: 'CTRL+SHIFT+X',
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( STRIKETHROUGH );
55 editor.editing.view.focus();
56 } );
57
58 return view;
59 } );
60 }
61}