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 | 1×
1×
1×
1×
1994×
1994×
1×
1994×
1994×
1×
1846×
1846×
1×
11×
11×
11×
11×
11×
123×
123×
123×
3×
3×
11×
11×
11×
11×
1×
11×
11×
11×
2×
1×
1×
1×
1×
1×
9×
11×
11×
1×
4×
4×
4×
4×
4×
3×
6×
4×
4×
11×
11×
4×
4×
4×
1×
1846×
1×
1×
| define(["require", "exports", "./../../selection/index", "./../../common/constant", "./inserthtml", "@syncfusion/ej2-base"], function (require, exports, index_1, EVENTS, inserthtml_1, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var EmojiPickerAction = (function () {
function EmojiPickerAction(parent) {
this.parent = parent;
this.addEventListener();
}
EmojiPickerAction.prototype.addEventListener = function () {
this.parent.observer.on(EVENTS.EMOJI_PICKER_ACTIONS, this.emojiInsert, this);
this.parent.observer.on(EVENTS.INTERNAL_DESTROY, this.destroy, this);
};
EmojiPickerAction.prototype.removeEventListener = function () {
this.parent.observer.off(EVENTS.EMOJI_PICKER_ACTIONS, this.emojiInsert);
this.parent.observer.off(EVENTS.INTERNAL_DESTROY, this.destroy);
};
EmojiPickerAction.prototype.emojiInsert = function (args) {
var node = document.createTextNode(args.value);
var selection = this.parent.currentDocument.getSelection();
var range = selection.getRangeAt(0);
var cursorPos = range.startOffset;
for (var i = cursorPos - 1; i >= cursorPos - 15; i--) {
var prevChar_1 = selection.focusNode.textContent.substring(i - 1, i);
var isPrevSpace_1 = /:$/.test(prevChar_1);
if (isPrevSpace_1) {
this.beforeApplyFormat(true);
break;
}
}
var colon = /:$/.test(selection.focusNode.textContent.charAt(cursorPos - 1));
var prevChar = selection.focusNode.textContent.charAt(cursorPos - 2);
var isPrevSpace = /\s/.test(prevChar);
if (colon && (isPrevSpace || selection.focusOffset === 1)) {
this.beforeApplyFormat(true);
}
var focusNode = selection.focusNode;
var anchorParent = ej2_base_1.closest(focusNode.nodeName === '#text' ? focusNode.parentNode : focusNode, 'a');
if (anchorParent) {
if (cursorPos === 0) {
anchorParent.parentNode.insertBefore(node, anchorParent);
}
else Eif (cursorPos === focusNode.textContent.length) {
anchorParent.parentNode.insertBefore(node, anchorParent.nextSibling);
var nodeSelection = new index_1.NodeSelection(anchorParent);
nodeSelection.setCursorPoint(this.parent.currentDocument, anchorParent.nextSibling, anchorParent.nextSibling.textContent.length);
}
}
else {
inserthtml_1.InsertHtml.Insert(this.parent.currentDocument, node, this.parent.editableElement);
}
Eif (args.callBack) {
args.callBack({
requestType: args.subCommand,
editorMode: 'HTML',
event: args.event,
range: this.parent.nodeSelection.getRange(this.parent.currentDocument),
elements: this.parent.nodeSelection.getSelectedNodes(this.parent.currentDocument)
});
}
};
EmojiPickerAction.prototype.beforeApplyFormat = function (isBlockFormat) {
var range1 = this.parent.nodeSelection.getRange(this.parent.currentDocument);
var node = this.parent.nodeSelection.getNodeCollection(range1)[0];
var blockNewLine = !(node.parentElement.innerHTML.replace(/ |<br>/g, '').trim() === ':' || node.textContent.trim().indexOf('/') === 0);
var startNode = node;
if (blockNewLine && isBlockFormat) {
while (startNode !== this.parent.editableElement) {
startNode = startNode.parentElement;
}
}
var startPoint = range1.startOffset;
while (this.parent.nodeSelection.getRange(this.parent.editableElement.ownerDocument).toString().indexOf(':') === -1) {
this.parent.nodeSelection.setSelectionText(this.parent.editableElement.ownerDocument, node, node, startPoint, range1.endOffset);
startPoint--;
}
var range2 = this.parent.nodeSelection.getRange(this.parent.currentDocument);
var node2 = this.parent.nodeCutter.GetSpliceNode(range2, node);
node2.parentNode.removeChild(node2);
};
EmojiPickerAction.prototype.destroy = function () {
this.removeEventListener();
};
return EmojiPickerAction;
}());
exports.EmojiPickerAction = EmojiPickerAction;
});
|