/
standardeditingmodeui.js
53 lines (44 loc) · 1.36 KB
/
standardeditingmodeui.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
/**
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module restricted-editing/standardeditingmodeui
*/
import { Plugin } from 'ckeditor5/src/core';
import { ButtonView } from 'ckeditor5/src/ui';
import unlockIcon from '../theme/icons/contentunlock.svg';
/**
* The standard editing mode UI feature.
*
* It introduces the `'restrictedEditingException'` button that marks text as unrestricted for editing.
*
* @extends module:core/plugin~Plugin
*/
export default class StandardEditingModeUI extends Plugin {
/**
* @inheritDoc
*/
init() {
const editor = this.editor;
const t = editor.t;
editor.ui.componentFactory.add( 'restrictedEditingException', locale => {
const command = editor.commands.get( 'restrictedEditingException' );
const view = new ButtonView( locale );
view.set( {
icon: unlockIcon,
tooltip: true,
isToggleable: true
} );
view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
view.bind( 'label' ).to( command, 'value', value => {
return value ? t( 'Disable editing' ) : t( 'Enable editing' );
} );
this.listenTo( view, 'execute', () => {
editor.execute( 'restrictedEditingException' );
editor.editing.view.focus();
} );
return view;
} );
}
}