-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
114 lines (98 loc) · 3.8 KB
/
plugin.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
(function() {
'use strict';
CKEDITOR.config.svgicons = false;
function addTemplate(templateName, separator, state) {
CKEDITOR.addTemplate(
templateName,
'<svg id="{id}_icon" xmlns="http://www.w3.org/2000/svg"'
+ ' class="cke_button_icon cke_svgicon cke_svgicon--{iconName}' + state + '">'
+ '<use xlink:href="#cke_svgicon' + separator + '{iconName}' + state + '"/>'
+ '<rect height="100%" width="100%" style="fill: transparent;"></rect>'
+ '</svg>');
}
addTemplate('buttonSVGIcon', '--', '');
addTemplate('buttonSVGIconRu', '--', '-ru');
addTemplate('buttonSVGIconEn', '--', '-en');
addTemplate('buttonSVGIconState', '--', '-{state}');
addTemplate('lisa_buttonSVGIcon', '_lisa--lisa_', '');
addTemplate('lisa_buttonSVGIconRu', '_lisa--lisa_', '-ru');
addTemplate('lisa_buttonSVGIconEn', '_lisa--lisa_', '-en');
addTemplate('lisa_buttonSVGIconState', '_lisa--lisa_', '-{state}');
CKEDITOR.plugins.add('svgicons', {
requires: 'exbutton',
modes: { 'wysiwyg': 1, 'source': 1 },
afterInit: function(editor) {
if (!editor.config.svgicons) {
return;
}
const templateNamePrefix = editor.config.svgicons === 'lisa' ? 'lisa_' : '';
var svgButtons = [
'AddImage',
'Attachment',
'AttachmentComputer',
'AttachmentDisk',
'AttachmentMail',
'BGColor',
'Blockquote',
'BulletedList',
'Emoticons',
'Font',
'FontSize',
'JustifyBlock',
'JustifyCenter',
'JustifyLeft',
'JustifyRight',
'Link',
'MailBGColor',
'MailFont',
'MailFontSize',
'MailTextColor',
'Maximize',
'MenuAlignment',
'MenuList',
'NumberedList',
'PasteFromWord',
'Redo',
'RemoveFormat',
'SwitchMode',
'TextColor',
'Undo',
'Unlink'
];
var svgButtonsLang = [
'Bold',
'Italic',
'MenuSelection',
'Strike',
'Underline'
];
svgButtons.forEach(function(buttonName) {
if (this.ui.items[ buttonName ]) {
this.ui.items[ buttonName ].args[0].icoTmpl = CKEDITOR.getTemplate(templateNamePrefix + 'buttonSVGIcon');
}
}, editor);
var tmplButtonName = (editor.config.language === 'ru' ? 'buttonSVGIconRu' : 'buttonSVGIconEn');
svgButtonsLang.forEach(function(buttonName) {
if (this.ui.items[ buttonName ]) {
this.ui.items[ buttonName ].args[0].icoTmpl = CKEDITOR.getTemplate(templateNamePrefix + tmplButtonName);
}
}, editor);
editor.on('mode', function() {
var button = this.ui.get('SwitchMode');
if (!button) {
return;
}
var iconNode = button.getElementIcon();
if (!iconNode) {
return;
}
var newIconNode = CKEDITOR.dom.element.createFromHtml(CKEDITOR.getTemplate(templateNamePrefix + 'buttonSVGIconState').output({
'id': button._.id,
'iconName': 'switchmode',
'state': (this.mode === 'wysiwyg' ? 'on' : 'off')
}));
newIconNode.replace(iconNode);
});
}
});
}());