source: trip-planner-front/node_modules/primeng/fesm2015/primeng-dom.mjs@ b738035

Last change on this file since b738035 was 59329aa, checked in by Ema <ema_spirova@…>, 3 years ago

adding photos

  • Property mode set to 100644
File size: 21.2 KB
RevLine 
[59329aa]1/**
2 * @dynamic is for runtime initializing DomHandler.browser
3 *
4 * If delete below comment, we can see this error message:
5 * Metadata collected contains an error that will be reported at runtime:
6 * Only initialized variables and constants can be referenced
7 * because the value of this variable is needed by the template compiler.
8 */
9// @dynamic
10class DomHandler {
11 static addClass(element, className) {
12 if (element.classList)
13 element.classList.add(className);
14 else
15 element.className += ' ' + className;
16 }
17 static addMultipleClasses(element, className) {
18 if (element.classList) {
19 let styles = className.trim().split(' ');
20 for (let i = 0; i < styles.length; i++) {
21 element.classList.add(styles[i]);
22 }
23 }
24 else {
25 let styles = className.split(' ');
26 for (let i = 0; i < styles.length; i++) {
27 element.className += ' ' + styles[i];
28 }
29 }
30 }
31 static removeClass(element, className) {
32 if (element.classList)
33 element.classList.remove(className);
34 else
35 element.className = element.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
36 }
37 static hasClass(element, className) {
38 if (element.classList)
39 return element.classList.contains(className);
40 else
41 return new RegExp('(^| )' + className + '( |$)', 'gi').test(element.className);
42 }
43 static siblings(element) {
44 return Array.prototype.filter.call(element.parentNode.children, function (child) {
45 return child !== element;
46 });
47 }
48 static find(element, selector) {
49 return Array.from(element.querySelectorAll(selector));
50 }
51 static findSingle(element, selector) {
52 if (element) {
53 return element.querySelector(selector);
54 }
55 return null;
56 }
57 static index(element) {
58 let children = element.parentNode.childNodes;
59 let num = 0;
60 for (var i = 0; i < children.length; i++) {
61 if (children[i] == element)
62 return num;
63 if (children[i].nodeType == 1)
64 num++;
65 }
66 return -1;
67 }
68 static indexWithinGroup(element, attributeName) {
69 let children = element.parentNode ? element.parentNode.childNodes : [];
70 let num = 0;
71 for (var i = 0; i < children.length; i++) {
72 if (children[i] == element)
73 return num;
74 if (children[i].attributes && children[i].attributes[attributeName] && children[i].nodeType == 1)
75 num++;
76 }
77 return -1;
78 }
79 static relativePosition(element, target) {
80 let elementDimensions = element.offsetParent ? { width: element.offsetWidth, height: element.offsetHeight } : this.getHiddenElementDimensions(element);
81 const targetHeight = target.offsetHeight;
82 const targetOffset = target.getBoundingClientRect();
83 const viewport = this.getViewport();
84 let top, left;
85 if ((targetOffset.top + targetHeight + elementDimensions.height) > viewport.height) {
86 top = -1 * (elementDimensions.height);
87 element.style.transformOrigin = 'bottom';
88 if (targetOffset.top + top < 0) {
89 top = -1 * targetOffset.top;
90 }
91 }
92 else {
93 top = targetHeight;
94 element.style.transformOrigin = 'top';
95 }
96 if (elementDimensions.width > viewport.width) {
97 // element wider then viewport and cannot fit on screen (align at left side of viewport)
98 left = targetOffset.left * -1;
99 }
100 else if ((targetOffset.left + elementDimensions.width) > viewport.width) {
101 // element wider then viewport but can be fit on screen (align at right side of viewport)
102 left = (targetOffset.left + elementDimensions.width - viewport.width) * -1;
103 }
104 else {
105 // element fits on screen (align with target)
106 left = 0;
107 }
108 element.style.top = top + 'px';
109 element.style.left = left + 'px';
110 }
111 static absolutePosition(element, target) {
112 let elementDimensions = element.offsetParent ? { width: element.offsetWidth, height: element.offsetHeight } : this.getHiddenElementDimensions(element);
113 let elementOuterHeight = elementDimensions.height;
114 let elementOuterWidth = elementDimensions.width;
115 let targetOuterHeight = target.offsetHeight;
116 let targetOuterWidth = target.offsetWidth;
117 let targetOffset = target.getBoundingClientRect();
118 let windowScrollTop = this.getWindowScrollTop();
119 let windowScrollLeft = this.getWindowScrollLeft();
120 let viewport = this.getViewport();
121 let top, left;
122 if (targetOffset.top + targetOuterHeight + elementOuterHeight > viewport.height) {
123 top = targetOffset.top + windowScrollTop - elementOuterHeight;
124 element.style.transformOrigin = 'bottom';
125 if (top < 0) {
126 top = windowScrollTop;
127 }
128 }
129 else {
130 top = targetOuterHeight + targetOffset.top + windowScrollTop;
131 element.style.transformOrigin = 'top';
132 }
133 if (targetOffset.left + elementOuterWidth > viewport.width)
134 left = Math.max(0, targetOffset.left + windowScrollLeft + targetOuterWidth - elementOuterWidth);
135 else
136 left = targetOffset.left + windowScrollLeft;
137 element.style.top = top + 'px';
138 element.style.left = left + 'px';
139 }
140 static getParents(element, parents = []) {
141 return element['parentNode'] === null ? parents : this.getParents(element.parentNode, parents.concat([element.parentNode]));
142 }
143 static getScrollableParents(element) {
144 let scrollableParents = [];
145 if (element) {
146 let parents = this.getParents(element);
147 const overflowRegex = /(auto|scroll)/;
148 const overflowCheck = (node) => {
149 let styleDeclaration = window['getComputedStyle'](node, null);
150 return overflowRegex.test(styleDeclaration.getPropertyValue('overflow')) || overflowRegex.test(styleDeclaration.getPropertyValue('overflowX')) || overflowRegex.test(styleDeclaration.getPropertyValue('overflowY'));
151 };
152 for (let parent of parents) {
153 let scrollSelectors = parent.nodeType === 1 && parent.dataset['scrollselectors'];
154 if (scrollSelectors) {
155 let selectors = scrollSelectors.split(',');
156 for (let selector of selectors) {
157 let el = this.findSingle(parent, selector);
158 if (el && overflowCheck(el)) {
159 scrollableParents.push(el);
160 }
161 }
162 }
163 if (parent.nodeType !== 9 && overflowCheck(parent)) {
164 scrollableParents.push(parent);
165 }
166 }
167 }
168 return scrollableParents;
169 }
170 static getHiddenElementOuterHeight(element) {
171 element.style.visibility = 'hidden';
172 element.style.display = 'block';
173 let elementHeight = element.offsetHeight;
174 element.style.display = 'none';
175 element.style.visibility = 'visible';
176 return elementHeight;
177 }
178 static getHiddenElementOuterWidth(element) {
179 element.style.visibility = 'hidden';
180 element.style.display = 'block';
181 let elementWidth = element.offsetWidth;
182 element.style.display = 'none';
183 element.style.visibility = 'visible';
184 return elementWidth;
185 }
186 static getHiddenElementDimensions(element) {
187 let dimensions = {};
188 element.style.visibility = 'hidden';
189 element.style.display = 'block';
190 dimensions.width = element.offsetWidth;
191 dimensions.height = element.offsetHeight;
192 element.style.display = 'none';
193 element.style.visibility = 'visible';
194 return dimensions;
195 }
196 static scrollInView(container, item) {
197 let borderTopValue = getComputedStyle(container).getPropertyValue('borderTopWidth');
198 let borderTop = borderTopValue ? parseFloat(borderTopValue) : 0;
199 let paddingTopValue = getComputedStyle(container).getPropertyValue('paddingTop');
200 let paddingTop = paddingTopValue ? parseFloat(paddingTopValue) : 0;
201 let containerRect = container.getBoundingClientRect();
202 let itemRect = item.getBoundingClientRect();
203 let offset = (itemRect.top + document.body.scrollTop) - (containerRect.top + document.body.scrollTop) - borderTop - paddingTop;
204 let scroll = container.scrollTop;
205 let elementHeight = container.clientHeight;
206 let itemHeight = this.getOuterHeight(item);
207 if (offset < 0) {
208 container.scrollTop = scroll + offset;
209 }
210 else if ((offset + itemHeight) > elementHeight) {
211 container.scrollTop = scroll + offset - elementHeight + itemHeight;
212 }
213 }
214 static fadeIn(element, duration) {
215 element.style.opacity = 0;
216 let last = +new Date();
217 let opacity = 0;
218 let tick = function () {
219 opacity = +element.style.opacity.replace(",", ".") + (new Date().getTime() - last) / duration;
220 element.style.opacity = opacity;
221 last = +new Date();
222 if (+opacity < 1) {
223 (window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16);
224 }
225 };
226 tick();
227 }
228 static fadeOut(element, ms) {
229 var opacity = 1, interval = 50, duration = ms, gap = interval / duration;
230 let fading = setInterval(() => {
231 opacity = opacity - gap;
232 if (opacity <= 0) {
233 opacity = 0;
234 clearInterval(fading);
235 }
236 element.style.opacity = opacity;
237 }, interval);
238 }
239 static getWindowScrollTop() {
240 let doc = document.documentElement;
241 return (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
242 }
243 static getWindowScrollLeft() {
244 let doc = document.documentElement;
245 return (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
246 }
247 static matches(element, selector) {
248 var p = Element.prototype;
249 var f = p['matches'] || p.webkitMatchesSelector || p['mozMatchesSelector'] || p['msMatchesSelector'] || function (s) {
250 return [].indexOf.call(document.querySelectorAll(s), this) !== -1;
251 };
252 return f.call(element, selector);
253 }
254 static getOuterWidth(el, margin) {
255 let width = el.offsetWidth;
256 if (margin) {
257 let style = getComputedStyle(el);
258 width += parseFloat(style.marginLeft) + parseFloat(style.marginRight);
259 }
260 return width;
261 }
262 static getHorizontalPadding(el) {
263 let style = getComputedStyle(el);
264 return parseFloat(style.paddingLeft) + parseFloat(style.paddingRight);
265 }
266 static getHorizontalMargin(el) {
267 let style = getComputedStyle(el);
268 return parseFloat(style.marginLeft) + parseFloat(style.marginRight);
269 }
270 static innerWidth(el) {
271 let width = el.offsetWidth;
272 let style = getComputedStyle(el);
273 width += parseFloat(style.paddingLeft) + parseFloat(style.paddingRight);
274 return width;
275 }
276 static width(el) {
277 let width = el.offsetWidth;
278 let style = getComputedStyle(el);
279 width -= parseFloat(style.paddingLeft) + parseFloat(style.paddingRight);
280 return width;
281 }
282 static getInnerHeight(el) {
283 let height = el.offsetHeight;
284 let style = getComputedStyle(el);
285 height += parseFloat(style.paddingTop) + parseFloat(style.paddingBottom);
286 return height;
287 }
288 static getOuterHeight(el, margin) {
289 let height = el.offsetHeight;
290 if (margin) {
291 let style = getComputedStyle(el);
292 height += parseFloat(style.marginTop) + parseFloat(style.marginBottom);
293 }
294 return height;
295 }
296 static getHeight(el) {
297 let height = el.offsetHeight;
298 let style = getComputedStyle(el);
299 height -= parseFloat(style.paddingTop) + parseFloat(style.paddingBottom) + parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
300 return height;
301 }
302 static getWidth(el) {
303 let width = el.offsetWidth;
304 let style = getComputedStyle(el);
305 width -= parseFloat(style.paddingLeft) + parseFloat(style.paddingRight) + parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth);
306 return width;
307 }
308 static getViewport() {
309 let win = window, d = document, e = d.documentElement, g = d.getElementsByTagName('body')[0], w = win.innerWidth || e.clientWidth || g.clientWidth, h = win.innerHeight || e.clientHeight || g.clientHeight;
310 return { width: w, height: h };
311 }
312 static getOffset(el) {
313 var rect = el.getBoundingClientRect();
314 return {
315 top: rect.top + (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0),
316 left: rect.left + (window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0),
317 };
318 }
319 static replaceElementWith(element, replacementElement) {
320 let parentNode = element.parentNode;
321 if (!parentNode)
322 throw `Can't replace element`;
323 return parentNode.replaceChild(replacementElement, element);
324 }
325 static getUserAgent() {
326 return navigator.userAgent;
327 }
328 static isIE() {
329 var ua = window.navigator.userAgent;
330 var msie = ua.indexOf('MSIE ');
331 if (msie > 0) {
332 // IE 10 or older => return version number
333 return true;
334 }
335 var trident = ua.indexOf('Trident/');
336 if (trident > 0) {
337 // IE 11 => return version number
338 var rv = ua.indexOf('rv:');
339 return true;
340 }
341 var edge = ua.indexOf('Edge/');
342 if (edge > 0) {
343 // Edge (IE 12+) => return version number
344 return true;
345 }
346 // other browser
347 return false;
348 }
349 static isIOS() {
350 return /iPad|iPhone|iPod/.test(navigator.userAgent) && !window['MSStream'];
351 }
352 static isAndroid() {
353 return /(android)/i.test(navigator.userAgent);
354 }
355 static isTouchDevice() {
356 return (('ontouchstart' in window) || (navigator.maxTouchPoints > 0));
357 }
358 static appendChild(element, target) {
359 if (this.isElement(target))
360 target.appendChild(element);
361 else if (target.el && target.el.nativeElement)
362 target.el.nativeElement.appendChild(element);
363 else
364 throw 'Cannot append ' + target + ' to ' + element;
365 }
366 static removeChild(element, target) {
367 if (this.isElement(target))
368 target.removeChild(element);
369 else if (target.el && target.el.nativeElement)
370 target.el.nativeElement.removeChild(element);
371 else
372 throw 'Cannot remove ' + element + ' from ' + target;
373 }
374 static removeElement(element) {
375 if (!('remove' in Element.prototype))
376 element.parentNode.removeChild(element);
377 else
378 element.remove();
379 }
380 static isElement(obj) {
381 return (typeof HTMLElement === "object" ? obj instanceof HTMLElement :
382 obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string");
383 }
384 static calculateScrollbarWidth(el) {
385 if (el) {
386 let style = getComputedStyle(el);
387 return (el.offsetWidth - el.clientWidth - parseFloat(style.borderLeftWidth) - parseFloat(style.borderRightWidth));
388 }
389 else {
390 if (this.calculatedScrollbarWidth !== null)
391 return this.calculatedScrollbarWidth;
392 let scrollDiv = document.createElement("div");
393 scrollDiv.className = "p-scrollbar-measure";
394 document.body.appendChild(scrollDiv);
395 let scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
396 document.body.removeChild(scrollDiv);
397 this.calculatedScrollbarWidth = scrollbarWidth;
398 return scrollbarWidth;
399 }
400 }
401 static calculateScrollbarHeight() {
402 if (this.calculatedScrollbarHeight !== null)
403 return this.calculatedScrollbarHeight;
404 let scrollDiv = document.createElement("div");
405 scrollDiv.className = "p-scrollbar-measure";
406 document.body.appendChild(scrollDiv);
407 let scrollbarHeight = scrollDiv.offsetHeight - scrollDiv.clientHeight;
408 document.body.removeChild(scrollDiv);
409 this.calculatedScrollbarWidth = scrollbarHeight;
410 return scrollbarHeight;
411 }
412 static invokeElementMethod(element, methodName, args) {
413 element[methodName].apply(element, args);
414 }
415 static clearSelection() {
416 if (window.getSelection) {
417 if (window.getSelection().empty) {
418 window.getSelection().empty();
419 }
420 else if (window.getSelection().removeAllRanges && window.getSelection().rangeCount > 0 && window.getSelection().getRangeAt(0).getClientRects().length > 0) {
421 window.getSelection().removeAllRanges();
422 }
423 }
424 else if (document['selection'] && document['selection'].empty) {
425 try {
426 document['selection'].empty();
427 }
428 catch (error) {
429 //ignore IE bug
430 }
431 }
432 }
433 static getBrowser() {
434 if (!this.browser) {
435 let matched = this.resolveUserAgent();
436 this.browser = {};
437 if (matched.browser) {
438 this.browser[matched.browser] = true;
439 this.browser['version'] = matched.version;
440 }
441 if (this.browser['chrome']) {
442 this.browser['webkit'] = true;
443 }
444 else if (this.browser['webkit']) {
445 this.browser['safari'] = true;
446 }
447 }
448 return this.browser;
449 }
450 static resolveUserAgent() {
451 let ua = navigator.userAgent.toLowerCase();
452 let match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
453 /(webkit)[ \/]([\w.]+)/.exec(ua) ||
454 /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
455 /(msie) ([\w.]+)/.exec(ua) ||
456 ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
457 [];
458 return {
459 browser: match[1] || "",
460 version: match[2] || "0"
461 };
462 }
463 static isInteger(value) {
464 if (Number.isInteger) {
465 return Number.isInteger(value);
466 }
467 else {
468 return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
469 }
470 }
471 static isHidden(element) {
472 return element.offsetParent === null;
473 }
474 static getFocusableElements(element) {
475 let focusableElements = DomHandler.find(element, `button:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),
476 [href][clientHeight][clientWidth]:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),
477 input:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]), select:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),
478 textarea:not([tabindex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]), [tabIndex]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]),
479 [contenteditable]:not([tabIndex = "-1"]):not([disabled]):not([style*="display:none"]):not([hidden]:not(.p-disabled))`);
480 let visibleFocusableElements = [];
481 for (let focusableElement of focusableElements) {
482 if (getComputedStyle(focusableElement).display != "none" && getComputedStyle(focusableElement).visibility != "hidden")
483 visibleFocusableElements.push(focusableElement);
484 }
485 return visibleFocusableElements;
486 }
487 static generateZIndex() {
488 this.zindex = this.zindex || 999;
489 return ++this.zindex;
490 }
491}
492DomHandler.zindex = 1000;
493DomHandler.calculatedScrollbarWidth = null;
494DomHandler.calculatedScrollbarHeight = null;
495
496class ConnectedOverlayScrollHandler {
497 constructor(element, listener = () => { }) {
498 this.element = element;
499 this.listener = listener;
500 }
501 bindScrollListener() {
502 this.scrollableParents = DomHandler.getScrollableParents(this.element);
503 for (let i = 0; i < this.scrollableParents.length; i++) {
504 this.scrollableParents[i].addEventListener('scroll', this.listener);
505 }
506 }
507 unbindScrollListener() {
508 if (this.scrollableParents) {
509 for (let i = 0; i < this.scrollableParents.length; i++) {
510 this.scrollableParents[i].removeEventListener('scroll', this.listener);
511 }
512 }
513 }
514 destroy() {
515 this.unbindScrollListener();
516 this.element = null;
517 this.listener = null;
518 this.scrollableParents = null;
519 }
520}
521
522/**
523 * Generated bundle index. Do not edit.
524 */
525
526export { ConnectedOverlayScrollHandler, DomHandler };
Note: See TracBrowser for help on using the repository browser.