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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187 | 1×
1×
1×
1×
1×
1×
1×
1×
135×
135×
135×
135×
1×
134×
5×
134×
99×
99×
99×
134×
134×
175×
175×
175×
134×
1×
1×
1931×
1931×
1931×
1931×
1×
1930×
471×
1930×
471×
1930×
1930×
1930×
1930×
1×
1×
1930×
1×
1930×
1×
1930×
1930×
210×
210×
210×
159×
159×
159×
1×
1×
1×
19×
19×
19×
11×
11×
11×
176×
176×
176×
105×
105×
105×
154×
154×
154×
1095×
1095×
1095×
1930×
1930×
1×
1877×
1×
1930×
1×
435×
1×
31×
1×
1495×
1×
1647×
1×
283×
283×
1×
387×
| define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var elementRect;
var popupRect;
var element;
var parentDocument;
var fixedParent = false;
/**
*
* @param {HTMLElement} anchor - specifies the element
* @param {HTMLElement} element - specifies the element
* @returns {OffsetPosition} - returns the value
*/
function calculateRelativeBasedPosition(anchor, element) {
var fixedElement = false;
var anchorPos = { left: 0, top: 0 };
var tempAnchor = anchor;
if (!anchor || !element) {
return anchorPos;
}
if (ej2_base_1.isNullOrUndefined(element.offsetParent) && element.style.position === 'fixed') {
fixedElement = true;
}
while ((element.offsetParent || fixedElement) && anchor && element.offsetParent !== anchor) {
anchorPos.left += anchor.offsetLeft;
anchorPos.top += anchor.offsetTop;
anchor = anchor.offsetParent;
}
anchor = tempAnchor;
while ((element.offsetParent || fixedElement) && anchor && element.offsetParent !== anchor) {
anchorPos.left -= anchor.scrollLeft;
anchorPos.top -= anchor.scrollTop;
anchor = anchor.parentElement;
}
return anchorPos;
}
exports.calculateRelativeBasedPosition = calculateRelativeBasedPosition;
/**
*
* @param {Element} currentElement - specifies the element
* @param {string} positionX - specifies the position
* @param {string} positionY - specifies the position
* @param {boolean} parentElement - specifies the boolean
* @param {ClientRect} targetValues - specifies the client
* @returns {OffsetPosition} - returns the position
*/
function calculatePosition(currentElement, positionX, positionY, parentElement, targetValues) {
popupRect = undefined;
popupRect = targetValues;
fixedParent = parentElement ? true : false;
if (!currentElement) {
return { left: 0, top: 0 };
}
if (!positionX) {
positionX = 'left';
}
if (!positionY) {
positionY = 'top';
}
parentDocument = currentElement.ownerDocument;
element = currentElement;
var pos = { left: 0, top: 0 };
return updatePosition(positionX.toLowerCase(), positionY.toLowerCase(), pos);
}
exports.calculatePosition = calculatePosition;
/**
*
* @param {number} value - specifies the number
* @param {OffsetPosition} pos - specifies the position
* @returns {void}
*/
function setPosx(value, pos) {
pos.left = value;
}
/**
*
* @param {number} value - specifies the number
* @param {OffsetPosition} pos - specifies the position
* @returns {void}
*/
function setPosy(value, pos) {
pos.top = value;
}
/**
*
* @param {string} posX - specifies the position
* @param {string} posY - specifies the position
* @param {OffsetPosition} pos - specifies the position
* @returns {OffsetPosition} - returns the postion
*/
function updatePosition(posX, posY, pos) {
elementRect = element.getBoundingClientRect();
switch (posY + posX) {
case 'topcenter':
setPosx(getElementHCenter(), pos);
setPosy(getElementTop(), pos);
break;
case 'topright':
setPosx(getElementRight(), pos);
setPosy(getElementTop(), pos);
break;
case 'centercenter':
setPosx(getElementHCenter(), pos);
setPosy(getElementVCenter(), pos);
break;
case 'centerright':
setPosx(getElementRight(), pos);
setPosy(getElementVCenter(), pos);
break;
case 'centerleft':
setPosx(getElementLeft(), pos);
setPosy(getElementVCenter(), pos);
break;
case 'bottomcenter':
setPosx(getElementHCenter(), pos);
setPosy(getElementBottom(), pos);
break;
case 'bottomright':
setPosx(getElementRight(), pos);
setPosy(getElementBottom(), pos);
break;
case 'bottomleft':
setPosx(getElementLeft(), pos);
setPosy(getElementBottom(), pos);
break;
default:
case 'topleft':
setPosx(getElementLeft(), pos);
setPosy(getElementTop(), pos);
break;
}
element = null;
return pos;
}
/**
* @returns {number} - specifies the number value
*/
function getBodyScrollTop() {
return parentDocument.documentElement.scrollTop || parentDocument.body.scrollTop;
}
/**
* @returns {number} - specifies the number value
*/
function getBodyScrollLeft() {
return parentDocument.documentElement.scrollLeft || parentDocument.body.scrollLeft;
}
/**
* @returns {number} - specifies the number value
*/
function getElementBottom() {
return fixedParent ? elementRect.bottom : elementRect.bottom + getBodyScrollTop();
}
/**
* @returns {number} - specifies the number value
*/
function getElementVCenter() {
return getElementTop() + (elementRect.height / 2);
}
/**
* @returns {number} - specifies the number value
*/
function getElementTop() {
return fixedParent ? elementRect.top : elementRect.top + getBodyScrollTop();
}
/**
* @returns {number} - specifies the number value
*/
function getElementLeft() {
return elementRect.left + getBodyScrollLeft();
}
/**
* @returns {number} - specifies the number value
*/
function getElementRight() {
var popupWidth = (element && (element.classList.contains('e-date-wrapper') || element.classList.contains('e-datetime-wrapper') || (element.classList.contains('e-ddl') && element.classList.contains('e-rtl')) || element.classList.contains('e-date-range-wrapper'))) ? (popupRect ? popupRect.width : 0) :
(popupRect && (elementRect.width >= popupRect.width) ? popupRect.width : 0);
return elementRect.right + getBodyScrollLeft() - popupWidth;
}
/**
* @returns {number} - specifies the number value
*/
function getElementHCenter() {
return getElementLeft() + (elementRect.width / 2);
}
});
|