source: trip-planner-front/node_modules/@angular/cdk/esm2015/overlay/overlay-container.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 11.2 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { DOCUMENT } from '@angular/common';
9import { Inject, Injectable } from '@angular/core';
10import { Platform, _isTestEnvironment } from '@angular/cdk/platform';
11import * as i0 from "@angular/core";
12import * as i1 from "@angular/common";
13import * as i2 from "@angular/cdk/platform";
14/** Container inside which all overlays will render. */
15export class OverlayContainer {
16 constructor(document, _platform) {
17 this._platform = _platform;
18 this._document = document;
19 }
20 ngOnDestroy() {
21 const container = this._containerElement;
22 if (container && container.parentNode) {
23 container.parentNode.removeChild(container);
24 }
25 }
26 /**
27 * This method returns the overlay container element. It will lazily
28 * create the element the first time it is called to facilitate using
29 * the container in non-browser environments.
30 * @returns the container element
31 */
32 getContainerElement() {
33 if (!this._containerElement) {
34 this._createContainer();
35 }
36 return this._containerElement;
37 }
38 /**
39 * Create the overlay container element, which is simply a div
40 * with the 'cdk-overlay-container' class on the document body.
41 */
42 _createContainer() {
43 const containerClass = 'cdk-overlay-container';
44 // TODO(crisbeto): remove the testing check once we have an overlay testing
45 // module or Angular starts tearing down the testing `NgModule`. See:
46 // https://github.com/angular/angular/issues/18831
47 if (this._platform.isBrowser || _isTestEnvironment()) {
48 const oppositePlatformContainers = this._document.querySelectorAll(`.${containerClass}[platform="server"], ` +
49 `.${containerClass}[platform="test"]`);
50 // Remove any old containers from the opposite platform.
51 // This can happen when transitioning from the server to the client.
52 for (let i = 0; i < oppositePlatformContainers.length; i++) {
53 oppositePlatformContainers[i].parentNode.removeChild(oppositePlatformContainers[i]);
54 }
55 }
56 const container = this._document.createElement('div');
57 container.classList.add(containerClass);
58 // A long time ago we kept adding new overlay containers whenever a new app was instantiated,
59 // but at some point we added logic which clears the duplicate ones in order to avoid leaks.
60 // The new logic was a little too aggressive since it was breaking some legitimate use cases.
61 // To mitigate the problem we made it so that only containers from a different platform are
62 // cleared, but the side-effect was that people started depending on the overly-aggressive
63 // logic to clean up their tests for them. Until we can introduce an overlay-specific testing
64 // module which does the cleanup, we try to detect that we're in a test environment and we
65 // always clear the container. See #17006.
66 // TODO(crisbeto): remove the test environment check once we have an overlay testing module.
67 if (_isTestEnvironment()) {
68 container.setAttribute('platform', 'test');
69 }
70 else if (!this._platform.isBrowser) {
71 container.setAttribute('platform', 'server');
72 }
73 this._document.body.appendChild(container);
74 this._containerElement = container;
75 }
76}
77OverlayContainer.ɵprov = i0.ɵɵdefineInjectable({ factory: function OverlayContainer_Factory() { return new OverlayContainer(i0.ɵɵinject(i1.DOCUMENT), i0.ɵɵinject(i2.Platform)); }, token: OverlayContainer, providedIn: "root" });
78OverlayContainer.decorators = [
79 { type: Injectable, args: [{ providedIn: 'root' },] }
80];
81OverlayContainer.ctorParameters = () => [
82 { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
83 { type: Platform }
84];
85//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3ZlcmxheS1jb250YWluZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL292ZXJsYXkvb3ZlcmxheS1jb250YWluZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFDLFFBQVEsRUFBQyxNQUFNLGlCQUFpQixDQUFDO0FBQ3pDLE9BQU8sRUFBQyxNQUFNLEVBQUUsVUFBVSxFQUFZLE1BQU0sZUFBZSxDQUFDO0FBQzVELE9BQU8sRUFBQyxRQUFRLEVBQUUsa0JBQWtCLEVBQUMsTUFBTSx1QkFBdUIsQ0FBQzs7OztBQUVuRSx1REF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