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 | 1×
1×
1×
1×
1907×
1907×
1907×
1×
1907×
1907×
1907×
1×
1762×
1762×
1762×
1×
457×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
1×
12×
12×
12×
1×
52×
52×
52×
52×
46×
46×
46×
2×
46×
81×
81×
46×
46×
6×
6×
6×
46×
46×
46×
1×
46×
6×
52×
33×
1×
1762×
1×
1×
| define(["require", "exports", "./../base/constant", "@syncfusion/ej2-base", "./../../common/constant", "../../common/util"], function (require, exports, CONSTANT, ej2_base_1, EVENTS, util_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Alignments = (function () {
function Alignments(parent) {
this.alignments = {
'JustifyLeft': 'left',
'JustifyCenter': 'center',
'JustifyRight': 'right',
'JustifyFull': 'justify'
};
this.parent = parent;
this.addEventListener();
}
Alignments.prototype.addEventListener = function () {
this.parent.observer.on(CONSTANT.ALIGNMENT_TYPE, this.applyAlignment, this);
this.parent.observer.on(EVENTS.KEY_DOWN_HANDLER, this.onKeyDown, this);
this.parent.observer.on(EVENTS.INTERNAL_DESTROY, this.destroy, this);
};
Alignments.prototype.removeEventListener = function () {
this.parent.observer.off(CONSTANT.ALIGNMENT_TYPE, this.applyAlignment);
this.parent.observer.off(EVENTS.KEY_DOWN_HANDLER, this.onKeyDown);
this.parent.observer.off(EVENTS.INTERNAL_DESTROY, this.destroy);
};
Alignments.prototype.onKeyDown = function (e) {
switch (e.event.action) {
case 'justify-center':
this.applyAlignment({ subCommand: 'JustifyCenter', callBack: e.callBack });
e.event.preventDefault();
break;
case 'justify-full':
this.applyAlignment({ subCommand: 'JustifyFull', callBack: e.callBack });
e.event.preventDefault();
break;
case 'justify-left':
this.applyAlignment({ subCommand: 'JustifyLeft', callBack: e.callBack });
e.event.preventDefault();
break;
case 'justify-right':
this.applyAlignment({ subCommand: 'JustifyRight', callBack: e.callBack });
e.event.preventDefault();
break;
}
};
Alignments.prototype.getTableNode = function (range) {
var startNode = range.startContainer.nodeType === Node.ELEMENT_NODE
? range.startContainer : range.startContainer.parentNode;
var cellNode = ej2_base_1.closest(startNode, 'td,th');
return [cellNode];
};
Alignments.prototype.applyAlignment = function (e) {
var isTableAlign = e.value === 'Table' ? true : false;
var range = this.parent.nodeSelection.getRange(this.parent.currentDocument);
var save = this.parent.nodeSelection.save(range, this.parent.currentDocument);
if (!isTableAlign) {
this.parent.domNode.setMarker(save);
var alignmentNodes = this.parent.domNode.blockNodes();
if (e.enterAction === 'BR') {
alignmentNodes = this.parent.domNode.convertToBlockNodes(alignmentNodes, false);
}
for (var i = 0; i < alignmentNodes.length; i++) {
var parentNode = alignmentNodes[i];
ej2_base_1.setStyleAttribute(parentNode, { 'text-align': this.alignments[e.subCommand] });
}
var imageTags = this.parent.domNode.getImageTagInSelection();
for (var i = 0; i < imageTags.length; i++) {
var elementNode = [];
elementNode.push(imageTags[i]);
this.parent.imgObj.imageCommand({
item: {
selectNode: elementNode
},
subCommand: e.subCommand,
value: e.subCommand,
callBack: e.callBack,
selector: e.selector
});
}
this.parent.editableElement.focus({ preventScroll: true });
save = this.parent.domNode.saveMarker(save);
if (util_1.isIDevice()) {
util_1.setEditFrameFocus(this.parent.editableElement, e.selector);
}
save.restore();
}
else {
ej2_base_1.setStyleAttribute(this.getTableNode(range)[0], { 'text-align': this.alignments[e.subCommand] });
}
if (e.callBack) {
e.callBack({
requestType: e.subCommand,
editorMode: 'HTML',
event: e.event,
range: this.parent.nodeSelection.getRange(this.parent.currentDocument),
elements: (isTableAlign ? this.getTableNode(range) : this.parent.domNode.blockNodes())
});
}
};
Alignments.prototype.destroy = function () {
this.removeEventListener();
};
return Alignments;
}());
exports.Alignments = Alignments;
});
|