/
ez-btn-inlinecustomtag-update.js
55 lines (43 loc) · 1.65 KB
/
ez-btn-inlinecustomtag-update.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
import PropTypes from 'prop-types';
import EzBtnCustomTagUpdate from './ez-btn-customtag-update';
export default class EzBtnInlineCustomTagUpdate extends EzBtnCustomTagUpdate {
/**
* Creates the custom tag in AlloyEditor.
*
* @method saveCustomTag
*/
saveCustomTag() {
const { createNewTag, editor } = this.props;
const nativeEditor = editor.get('nativeEditor');
const selection = nativeEditor.getSelectedHtml();
nativeEditor.unlockSelection(true);
if (createNewTag) {
this.execCommand();
}
const widget = this.getWidget() || this.widget;
const configValues = Object.assign({}, this.state.values);
widget.setFocused(true);
if (createNewTag) {
const firstChild = selection.getFirst();
const isNodeElement = firstChild.type === CKEDITOR.NODE_ELEMENT;
const content = isNodeElement && firstChild.is('table') ? selection.$.textContent : selection.getHtml();
widget.setName(this.customTagName);
widget.setWidgetContent(content);
widget.renderIcon();
}
widget.clearConfig();
Object.keys(this.attributes).forEach((key) => {
widget.setConfig(key, configValues[key].value);
});
}
}
eZ.addConfig('ezAlloyEditor.ezBtnInlineCustomTagUpdate', EzBtnInlineCustomTagUpdate);
EzBtnInlineCustomTagUpdate.defaultProps = {
command: 'ezinlinecustomtag',
modifiesSelection: true,
};
EzBtnInlineCustomTagUpdate.propTypes = {
editor: PropTypes.object.isRequired,
label: PropTypes.string.isRequired,
tabIndex: PropTypes.number.isRequired,
};