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 | 1×
1×
1×
1×
2619×
2619×
1×
2619×
2619×
1×
2448×
2448×
1×
256×
256×
256×
256×
9×
9×
9×
9×
247×
256×
216×
216×
216×
216×
216×
40×
3×
1×
9×
9×
9×
9×
9×
9×
9×
1×
1×
1×
8×
9×
1×
274×
1×
9×
10×
10×
10×
1×
8×
1×
2448×
1×
1×
| define(["require", "exports", "./../base/constant", "./inserthtml", "./../../common/constant", "@syncfusion/ej2-base"], function (require, exports, CONSTANT, inserthtml_1, EVENTS, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var InsertHtmlExec = (function () {
function InsertHtmlExec(parent) {
this.parent = parent;
this.addEventListener();
}
InsertHtmlExec.prototype.addEventListener = function () {
this.parent.observer.on(CONSTANT.INSERTHTML_TYPE, this.applyHtml, this);
this.parent.observer.on(EVENTS.INTERNAL_DESTROY, this.destroy, this);
};
InsertHtmlExec.prototype.removeEventListener = function () {
this.parent.observer.off(CONSTANT.INSERTHTML_TYPE, this.applyHtml);
this.parent.observer.off(EVENTS.INTERNAL_DESTROY, this.destroy);
};
InsertHtmlExec.prototype.applyHtml = function (e) {
var selectionRange = this.getSelectionRange();
var element = e.value;
var firstChild = element.firstChild;
if (firstChild && firstChild.nodeName === 'A' && selectionRange.startOffset !== selectionRange.endOffset) {
var isTextNode = selectionRange.startContainer.nodeName === '#text';
var notifyType = isTextNode ? CONSTANT.LINK : CONSTANT.IMAGE;
var actionType = isTextNode ? 'CreateLink' : 'InsertLink';
this.parent.observer.notify(notifyType, {
value: actionType,
item: this.extractHyperlinkDetails(e),
callBack: e.callBack
});
}
else {
inserthtml_1.InsertHtml.Insert(this.parent.currentDocument, e.value, this.parent.editableElement, true, e.enterAction, this.parent);
}
if (e.subCommand === 'pasteCleanup') {
var pastedElements = this.parent.editableElement.querySelectorAll('.pasteContent_RTE');
var allPastedElements = [].slice.call(pastedElements);
var imgElements = this.parent.editableElement.querySelectorAll('.pasteContent_Img');
var allImgElm = [].slice.call(imgElements);
e.callBack({
requestType: e.subCommand,
editorMode: 'HTML',
elements: allPastedElements,
imgElem: allImgElm
});
}
else {
if (e.callBack) {
e.callBack({
requestType: e.subCommand,
editorMode: 'HTML',
event: e.event,
range: this.parent.nodeSelection.getRange(this.parent.currentDocument),
elements: this.parent.nodeSelection.getSelectedNodes(this.parent.currentDocument)
});
}
}
};
InsertHtmlExec.prototype.extractHyperlinkDetails = function (e) {
var selectedText;
var selectionRange = this.getSelectionRange();
var selection = this.parent.nodeSelection;
var parentNodes = selection.getParentNodeCollection(selectionRange);
var anchor = e.value.querySelector('a');
var anchorElement = this.findAnchorElement(parentNodes);
if (anchorElement && anchorElement.nodeName === 'A') {
var rangeText = selectionRange.toString();
var anchorText = anchorElement.innerText;
selectedText = (rangeText.length < anchorText.length) ? anchorText : rangeText;
}
else {
selectedText = selectionRange.toString();
}
return {
url: anchor.href || '',
text: selectedText,
title: anchor.title || '',
target: anchor.target || '',
ariaLabel: anchor.ariaLabel || '',
selection: this.parent.nodeSelection,
selectNode: Array.from(this.getSelectionRange().startContainer.childNodes),
selectParent: parentNodes
};
};
InsertHtmlExec.prototype.getSelectionRange = function () {
return this.parent.nodeSelection.getRange(this.parent.currentDocument);
};
InsertHtmlExec.prototype.findAnchorElement = function (nodes) {
for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
var node = nodes_1[_i];
var anchor = ej2_base_1.closest(node, 'a');
if (anchor) {
return anchor;
}
}
return nodes[0];
};
InsertHtmlExec.prototype.destroy = function () {
this.removeEventListener();
};
return InsertHtmlExec;
}());
exports.InsertHtmlExec = InsertHtmlExec;
});
|