| 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237 | 1×
1×
1×
1×
1390×
1390×
1390×
1390×
1390×
1×
1390×
1390×
1390×
1390×
1390×
1390×
1×
1390×
1390×
1390×
1390×
1390×
1390×
1×
1390×
1390×
1390×
1390×
1390×
1390×
1×
1390×
1×
1390×
1×
1392×
1388×
1392×
1388×
1×
11×
48×
11×
1×
11×
1×
1×
10×
1×
4×
1×
2777×
2777×
1×
2776×
2776×
2776×
2776×
2776×
2776×
1388×
1388×
1388×
1388×
1388×
1388×
1×
2776×
2776×
2776×
2776×
1×
2776×
2776×
1×
2776×
2776×
2776×
2776×
2776×
2776×
2776×
2776×
2776×
1×
1×
1×
1×
1×
7×
7×
1×
17×
1×
1390×
1390×
1390×
1390×
1390×
1390×
1386×
1386×
1390×
1386×
1386×
1390×
1386×
1386×
1386×
1390×
1386×
1386×
1386×
1390×
1390×
1390×
1390×
1×
17×
10×
7×
7×
7×
7×
7×
7×
1×
1×
6×
6×
6×
1×
4180×
4180×
25030×
24980×
120734×
24980×
50×
4180×
1×
2784×
2784×
15300×
15300×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-splitbuttons", "@syncfusion/ej2-inputs", "./common/index", "../../common/utils/index", "../../common/constant", "../../common/constant"], function (require, exports, ej2_base_1, ej2_splitbuttons_1, ej2_inputs_1, index_1, index_2, constant_1, constants) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var InlineToolbarModule = (function () {
function InlineToolbarModule(editor) {
this.editor = editor;
this.toolbarRenderer = new index_1.ToolbarRenderer(this.editor);
this.addEventListeners();
this.init();
this.bindTooltip();
}
InlineToolbarModule.prototype.addEventListeners = function () {
this.editor.blockManager.observer.on('enableDisableTbarItems', this.enableDisableTbarItems, this);
this.editor.on(constant_1.events.inlineToolbarCreated, this.handleInlineToolbarCreated, this);
this.editor.on(constant_1.events.inlineToolbarItemClick, this.handleInlineToolbarItemClick, this);
this.editor.on(constant_1.events.moduleChanged, this.onPropertyChanged, this);
this.editor.on(constant_1.events.rtlChanged, this.applyRtlSettings, this);
this.editor.on(constant_1.events.destroy, this.destroy, this);
};
InlineToolbarModule.prototype.removeEventListeners = function () {
this.editor.blockManager.observer.off('enableDisableTbarItems', this.enableDisableTbarItems);
this.editor.off(constant_1.events.inlineToolbarCreated, this.handleInlineToolbarCreated);
this.editor.off(constant_1.events.inlineToolbarItemClick, this.handleInlineToolbarItemClick);
this.editor.off(constant_1.events.moduleChanged, this.onPropertyChanged);
this.editor.off(constant_1.events.rtlChanged, this.applyRtlSettings);
this.editor.off(constant_1.events.destroy, this.destroy);
};
InlineToolbarModule.prototype.init = function () {
this.toolbarEle = this.editor.createElement('div', {
id: (this.editor.element.id + constants.BLOCKEDITOR_INLINETBAR_ID),
className: constants.BLOCKEDITOR_INLINETBAR_CLS
});
this.editor.element.appendChild(this.toolbarEle);
this.toolbarObj = this.renderToolbar({
element: this.toolbarEle,
items: this.getToolbarItems(this.editor.inlineToolbarSettings.items),
width: this.editor.inlineToolbarSettings.popupWidth,
overflowMode: 'MultiRow'
});
var popupElement = this.editor.createElement('div', {
id: (this.editor.element.id + constants.INLINE_TBAR_POPUP_ID),
className: constants.INLINE_TBAR_POPUP_CLS
});
this.editor.element.appendChild(popupElement);
this.editor.blockManager.observer.notify('toolbarCreated');
};
InlineToolbarModule.prototype.bindTooltip = function () {
this.inlineToolbarTooltip = this.editor.tooltipRenderer.renderTooltip({
cssClass: constants.INLINE_TBAR_TOOLTIP_CLS,
position: 'TopCenter',
target: '.' + constants.TBAR_ITEM_CLS,
windowCollision: true,
element: document.querySelector('#' + this.editor.element.id + constants.INLINE_TBAR_POPUP_ID)
});
};
InlineToolbarModule.prototype.renderToolbar = function (args) {
return this.toolbarRenderer.renderToolbar(args);
};
InlineToolbarModule.prototype.handleInlineToolbarCreated = function () {
if (this.hasToolbarItemId('color')) {
this.initializeColorPickerAndDropdown('color');
}
if (this.hasToolbarItemId('bgColor')) {
this.initializeColorPickerAndDropdown('bgColor');
}
};
InlineToolbarModule.prototype.handleInlineToolbarItemClick = function (args) {
var itemClickArgs = {
item: index_2.getInlineToolbarItems().find(function (item) { return item.id === args.item.id; }),
event: args.originalEvent,
isInteracted: Object.keys(args.originalEvent).length > 0,
cancel: false
};
if (this.editor.inlineToolbarSettings.itemClick) {
this.editor.inlineToolbarSettings.itemClick.call(this.editor, itemClickArgs);
}
if (itemClickArgs.cancel) {
args.cancel = true;
return;
}
this.editor.blockManager.observer.notify('inlineToolbarItemClick', args);
};
InlineToolbarModule.prototype.enableDisableTbarItems = function (args) {
this.toolbarObj.enableItems(args.items, args.isEnable);
};
InlineToolbarModule.prototype.initializeColorPickerAndDropdown = function (type) {
var toolbarElement = document.querySelector('#' + this.editor.element.id + constants.BLOCKEDITOR_INLINETBAR_ID);
if (!toolbarElement) {
return;
}
var pickerElement = this.editor.createElement('input', { attrs: { type: 'color' } });
var colorPicker = this.createColorPicker(type, pickerElement);
var colorBtn = toolbarElement.querySelector("#toolbar-" + type.toLowerCase() + "-dropdown");
Eif (colorBtn) {
var dropDown = this.createDropDown({
instance: { target: colorPicker.element.closest('.e-colorpicker-wrapper') },
element: colorBtn,
inlineClass: "e-inline-" + type + "-icon",
type: type
});
if (type === 'color') {
this.textPickerElement = pickerElement;
this.textColorPicker = colorPicker;
this.textColorDDB = dropDown;
}
else {
this.bgPickerElement = pickerElement;
this.bgColorPicker = colorPicker;
this.bgColorDDB = dropDown;
}
}
};
InlineToolbarModule.prototype.createColorPicker = function (type, element) {
var _this = this;
element.id = type === 'color' ? 'be-colorPicker' : 'be-bgColorPicker';
document.body.appendChild(element);
var colorPicker = new ej2_inputs_1.ColorPicker({
mode: 'Palette',
inline: true,
modeSwitcher: false,
showButtons: false,
noColor: true,
value: '#000000',
cssClass: 'e-be-color-picker',
change: function (args) {
_this.handleColorChange(type, args);
}
});
colorPicker.appendTo(element);
return colorPicker;
};
InlineToolbarModule.prototype.createDropDown = function (args) {
var dropDown = new ej2_splitbuttons_1.DropDownButton({
target: args.instance.target,
cssClass: args.instance.cssClass,
createPopupOnClick: args.instance.createPopupOnClick
});
dropDown.appendTo(args.element);
var iconWrapper = this.editor.createElement('span', { className: 'e-be-color-icon-wrapper' });
var iconElement = this.editor.createElement('span', { className: args.inlineClass });
var cssText = 'border-bottom: 3px solid #000000;';
ej2_base_1.updateCSSText(iconElement, cssText);
iconWrapper.appendChild(iconElement);
dropDown.element.insertBefore(iconWrapper, dropDown.element.querySelector('.e-caret'));
return dropDown;
};
InlineToolbarModule.prototype.handleColorChange = function (type, args) {
this.editor.blockManager.observer.notify('handleColorpickerChange', { type: type, value: args.currentValue.rgba });
var dropdownButton = type === 'color' ? this.textColorDDB : this.bgColorDDB;
dropdownButton.toggle();
};
InlineToolbarModule.prototype.applyRtlSettings = function () {
Eif (this.toolbarObj) {
this.toolbarObj.enableRtl = this.editor.enableRtl;
}
};
InlineToolbarModule.prototype.getModuleName = function () {
return 'inlineToolbarSettings';
};
InlineToolbarModule.prototype.destroy = function () {
this.removeEventListeners();
Eif (this.toolbarObj) {
this.toolbarObj.destroy();
ej2_base_1.detach(this.toolbarEle);
this.toolbarObj = null;
}
if (this.textColorDDB) {
this.textColorDDB.destroy();
this.textColorDDB = null;
}
if (this.bgColorDDB) {
this.bgColorDDB.destroy();
this.bgColorDDB = null;
}
if (this.textColorPicker) {
this.textColorPicker.destroy();
ej2_base_1.detach(this.textPickerElement);
this.textColorPicker = null;
}
if (this.bgColorPicker) {
this.bgColorPicker.destroy();
ej2_base_1.detach(this.bgPickerElement);
this.bgColorPicker = null;
}
Eif (this.inlineToolbarTooltip) {
this.inlineToolbarTooltip.destroy();
}
this.toolbarRenderer = null;
this.inlineToolbarTooltip = null;
};
InlineToolbarModule.prototype.onPropertyChanged = function (e) {
if (e.module !== this.getModuleName()) {
return;
}
var newProp = e.newProp.inlineToolbarSettings;
var oldProp = e.oldProp.inlineToolbarSettings;
Eif (!ej2_base_1.isNullOrUndefined(newProp)) {
for (var _i = 0, _a = Object.keys(newProp); _i < _a.length; _i++) {
var prop = _a[_i];
switch (prop) {
case 'popupWidth':
this.editor.blockManager.observer.notify('popupWidthChanged', { value: newProp.popupWidth });
break;
case 'items': {
var flattenedToolbarItems = this.getToolbarItems(newProp.items);
this.toolbarObj.items = flattenedToolbarItems;
break;
}
}
}
}
};
InlineToolbarModule.prototype.getToolbarItems = function (items) {
var defaults = index_2.getInlineToolbarItems();
var resolved = items.map(function (item) {
if (typeof item === 'string') {
var match = defaults.find(function (d) {
return d.command && d.command.toLowerCase() === item.toLowerCase();
});
return match ? match : item;
}
return item;
});
return index_2.transformIntoToolbarItem(resolved);
};
InlineToolbarModule.prototype.hasToolbarItemId = function (targetId) {
var items = this.getToolbarItems(this.editor.inlineToolbarSettings.items);
return items.some(function (item) {
var id = item.id;
return id && id.toLowerCase() === targetId.toLowerCase();
});
};
return InlineToolbarModule;
}());
exports.InlineToolbarModule = InlineToolbarModule;
});
|