| 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 | 1×
1×
1×
1×
3419×
3419×
3419×
1×
3419×
3419×
3419×
1×
3252×
3252×
3252×
1×
121×
68×
53×
53×
53×
53×
53×
8×
1×
44×
1×
524×
2×
2×
2×
2×
2×
2×
1×
128×
128×
128×
128×
43×
43×
4×
4×
124×
124×
124×
124×
2×
124×
124×
124×
228×
58×
58×
170×
48×
48×
124×
54×
54×
54×
124×
122×
122×
4×
118×
122×
122×
122×
121×
68×
68×
68×
68×
53×
53×
53×
53×
124×
124×
124×
121×
121×
124×
38×
1×
3252×
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 Indents = (function () {
function Indents(parent) {
this.indentValue = 20;
this.parent = parent;
this.addEventListener();
}
Indents.prototype.addEventListener = function () {
this.parent.observer.on(CONSTANT.INDENT_TYPE, this.applyIndents, this);
this.parent.observer.on(EVENTS.KEY_DOWN_HANDLER, this.onKeyDown, this);
this.parent.observer.on(EVENTS.INTERNAL_DESTROY, this.destroy, this);
};
Indents.prototype.removeEventListener = function () {
this.parent.observer.off(CONSTANT.INDENT_TYPE, this.applyIndents);
this.parent.observer.off(EVENTS.KEY_DOWN_HANDLER, this.onKeyDown);
this.parent.observer.off(EVENTS.INTERNAL_DESTROY, this.destroy);
};
Indents.prototype.convertMarginToPixels = function (marginValue) {
if (!marginValue || marginValue === '') {
return 0;
}
var match = marginValue.match(/^([\d.]+)(.*)$/);
Iif (!match) {
return 0;
}
var numValue = parseFloat(match[1]);
var unit = match[2].trim().toLowerCase();
switch (unit) {
case 'in':
return numValue * 96;
case 'cm':
return numValue * 37.8;
case 'mm':
return numValue * 3.78;
case 'pt':
return numValue * 1.333;
case 'em':
return numValue * 16;
case 'px':
default:
return numValue;
}
};
Indents.prototype.onKeyDown = function (e) {
switch (e.event.action) {
case 'indents':
this.applyIndents({ subCommand: 'Indent', callBack: e.callBack });
e.event.preventDefault();
break;
case 'outdents':
this.applyIndents({ subCommand: 'Outdent', callBack: e.callBack });
e.event.preventDefault();
break;
}
};
Indents.prototype.applyIndents = function (e) {
var editEle = this.parent.editableElement;
var isRtl = editEle.classList.contains('e-rtl');
var range = this.parent.nodeSelection.getRange(this.parent.currentDocument);
if (!ej2_base_1.isNullOrUndefined(this.parent.codeBlockObj)) {
var isWithinCodeBlock = this.parent.codeBlockObj.
isSelectionWithinCodeBlock(range, range.startContainer, range.endContainer);
if (isWithinCodeBlock) {
this.parent.observer.
notify(EVENTS.CODEBLOCK_INDENTATION, { e: e, event: e.event, subCommand: e.subCommand, callBack: e.callBack });
return;
}
}
var save = this.parent.nodeSelection.save(range, this.parent.currentDocument);
this.parent.domNode.setMarker(save);
var indentsNodes = this.parent.domNode.blockNodes();
if (e.enterAction === 'BR') {
indentsNodes = this.parent.domNode.convertToBlockNodes(indentsNodes, false);
}
var parentNodes = indentsNodes.slice();
var listsNodes = [];
for (var i = 0; i < parentNodes.length; i++) {
if (parentNodes[i].tagName !== 'LI' && 'LI' === parentNodes[i].parentNode.tagName) {
indentsNodes.splice(indentsNodes.indexOf(parentNodes[i]), 1);
listsNodes.push(parentNodes[i].parentNode);
}
else if (parentNodes[i].tagName === 'LI') {
indentsNodes.splice(indentsNodes.indexOf(parentNodes[i]), 1);
listsNodes.push(parentNodes[i]);
}
}
if (listsNodes.length > 0) {
this.parent.observer.notify(EVENTS.KEY_DOWN_HANDLER, {
event: {
preventDefault: function () {
return;
},
stopPropagation: function () {
return;
},
shiftKey: (e.subCommand === 'Indent' ? false : true),
which: 9,
action: 'indent'
}
});
}
for (var i = 0; i < indentsNodes.length; i++) {
var parentNode = void 0;
if (indentsNodes[i] && indentsNodes[i].classList.contains('e-table-fake-selection') &&
editEle.querySelector('table.e-cell-select')) {
parentNode = editEle.querySelector('table.e-cell-select');
}
else {
parentNode = indentsNodes[i];
}
var marginLeftOrRight = isRtl ? parentNode.style.marginRight : parentNode.style.marginLeft;
var indentsValue = void 0;
if (parentNode.tagName !== 'HR') {
if (e.subCommand === 'Indent') {
var currentMarginInPixels = this.convertMarginToPixels(marginLeftOrRight);
var newMarginInPixels = currentMarginInPixels + this.indentValue;
indentsValue = newMarginInPixels + 'px';
isRtl ? (parentNode.style.marginRight = indentsValue) : (parentNode.style.marginLeft = indentsValue);
}
else {
var currentMarginInPixels = this.convertMarginToPixels(marginLeftOrRight);
var newMarginInPixels = currentMarginInPixels - this.indentValue;
indentsValue = (marginLeftOrRight === '' || marginLeftOrRight === '0px' || marginLeftOrRight === '0in') ? '' : (newMarginInPixels < 0) ? '0px' : newMarginInPixels + 'px';
isRtl ? (parentNode.style.marginRight = indentsValue) : (parentNode.style.marginLeft = indentsValue);
}
}
}
editEle.focus({ preventScroll: true });
Iif (util_1.isIDevice()) {
util_1.setEditFrameFocus(editEle, e.selector);
}
if (indentsNodes.length === 0 || indentsNodes[0] && indentsNodes[0].nodeName !== 'TABLE') {
save = this.parent.domNode.saveMarker(save);
save.restore();
}
if (e.callBack) {
e.callBack({
requestType: e.subCommand,
editorMode: 'HTML',
event: e.event,
range: this.parent.nodeSelection.getRange(this.parent.currentDocument),
elements: this.parent.domNode.blockNodes()
});
}
};
Indents.prototype.destroy = function () {
this.removeEventListener();
};
return Indents;
}());
exports.Indents = Indents;
});
|