blob: fbb37c7ec886cdd73a5863ba4fb79ff84a84850b (
plain)
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
|
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/* tslint:disable:array-type member-access variable-name typedef
only-arrow-functions directive-class-suffix component-class-suffix
component-selector*/
import {Injectable, Optional, SkipSelf} from '@angular/core';
/**
* The OverlayContainer is the container in which all overlays will load.
* It should be provided in the root component to ensure it is properly shared.
*/
@Injectable()
export class OverlayContainer {
protected _containerElement: HTMLElement;
private _themeClass: string;
/**
* Base theme to be applied to all overlay-based components.
*/
get themeClass(): string {
return this._themeClass;
}
set themeClass(value: string) {
if (this._containerElement) {
this._containerElement.classList.remove(this._themeClass);
if (value) {
this._containerElement.classList.add(value);
}
}
this._themeClass = value;
}
/**
* This method returns the overlay container element. It will lazily
* create the element the first time it is called to facilitate using
* the container in non-browser environments.
* @returns the container element
*/
getContainerElement(): HTMLElement {
if (!this._containerElement) {
this._createContainer();
}
return this._containerElement;
}
/**
* Create the overlay container element, which is simply a div
* with the 'cdk-overlay-container' class on the document body.
*/
protected _createContainer(): void {
const container = document.createElement('div');
container.classList.add('nz-overlay-container');
if (this._themeClass) {
container.classList.add(this._themeClass);
}
document.body.appendChild(container);
this._containerElement = container;
}
}
export function OVERLAY_CONTAINER_PROVIDER_FACTORY(
parentContainer: OverlayContainer) {
return parentContainer || new OverlayContainer();
}
export const OVERLAY_CONTAINER_PROVIDER = {
// If there is already an OverlayContainer available, use that. Otherwise,
// provide a new one.
provide: OverlayContainer,
deps: [[new Optional(), new SkipSelf(), OverlayContainer]],
useFactory: OVERLAY_CONTAINER_PROVIDER_FACTORY
};
|