UNPKG

1.59 kBJavaScriptView Raw
1/**
2 * @license Copyright (c) 2003-2024, 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 * @module basic-styles/italic/italicui
7 */
8import { Plugin } from 'ckeditor5/src/core.js';
9import { MenuBarMenuListItemButtonView, ButtonView } from 'ckeditor5/src/ui.js';
10import { getButtonCreator } from '../utils.js';
11import italicIcon from '../../theme/icons/italic.svg';
12const ITALIC = 'italic';
13/**
14 * The italic UI feature. It introduces the Italic button.
15 */
16export default class ItalicUI extends Plugin {
17 /**
18 * @inheritDoc
19 */
20 static get pluginName() {
21 return 'ItalicUI';
22 }
23 /**
24 * @inheritDoc
25 */
26 init() {
27 const editor = this.editor;
28 const command = editor.commands.get(ITALIC);
29 const t = editor.locale.t;
30 const createButton = getButtonCreator({
31 editor,
32 commandName: ITALIC,
33 plugin: this,
34 icon: italicIcon,
35 keystroke: 'CTRL+I',
36 label: t('Italic')
37 });
38 // Add bold button to feature components.
39 editor.ui.componentFactory.add(ITALIC, () => {
40 const buttonView = createButton(ButtonView);
41 buttonView.set({
42 tooltip: true
43 });
44 buttonView.bind('isOn').to(command, 'value');
45 return buttonView;
46 });
47 editor.ui.componentFactory.add('menuBar:' + ITALIC, () => {
48 return createButton(MenuBarMenuListItemButtonView);
49 });
50 }
51}