...
|
...
|
@@ -19,12 +19,13 @@ import { |
19
|
19
|
ElementRef,
|
20
|
20
|
EventEmitter,
|
21
|
21
|
Input, OnChanges, OnDestroy,
|
22
|
|
- Output, SimpleChanges,
|
|
22
|
+ Output, Renderer2, SecurityContext, SimpleChanges,
|
23
|
23
|
ViewContainerRef
|
24
|
24
|
} from '@angular/core';
|
25
|
25
|
import { Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
|
26
|
26
|
import { ComponentPortal } from '@angular/cdk/portal';
|
27
|
27
|
import { TbAnchorComponent } from '@shared/components/tb-anchor.component';
|
|
28
|
+import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
|
28
|
29
|
|
29
|
30
|
@Directive({
|
30
|
31
|
selector: '[tb-fullscreen]'
|
...
|
...
|
@@ -42,10 +43,18 @@ export class FullscreenDirective implements OnChanges, OnDestroy { |
42
|
43
|
@Input()
|
43
|
44
|
fullscreenElement: HTMLElement;
|
44
|
45
|
|
|
46
|
+ @Input()
|
|
47
|
+ fullscreenBackgroundStyle: {[klass: string]: any};
|
|
48
|
+
|
|
49
|
+ @Input()
|
|
50
|
+ fullscreenBackgroundImage: SafeStyle | string;
|
|
51
|
+
|
45
|
52
|
@Output()
|
46
|
53
|
fullscreenChanged = new EventEmitter<boolean>();
|
47
|
54
|
|
48
|
55
|
constructor(public elementRef: ElementRef,
|
|
56
|
+ private renderer: Renderer2,
|
|
57
|
+ private sanitizer: DomSanitizer,
|
49
|
58
|
private viewContainerRef: ViewContainerRef,
|
50
|
59
|
private overlay: Overlay) {
|
51
|
60
|
}
|
...
|
...
|
@@ -92,10 +101,33 @@ export class FullscreenDirective implements OnChanges, OnDestroy { |
92
|
101
|
|
93
|
102
|
this.overlayRef = this.overlay.create(config);
|
94
|
103
|
this.overlayRef.attach(new EmptyPortal());
|
|
104
|
+ if (this.fullscreenBackgroundStyle) {
|
|
105
|
+ for (const key of Object.keys(this.fullscreenBackgroundStyle)) {
|
|
106
|
+ this.setStyle(this.overlayRef.overlayElement, key, this.fullscreenBackgroundStyle[key]);
|
|
107
|
+ }
|
|
108
|
+ }
|
|
109
|
+ if (this.fullscreenBackgroundImage) {
|
|
110
|
+ this.setStyle(this.overlayRef.overlayElement, 'backgroundImage', this.fullscreenBackgroundImage);
|
|
111
|
+ }
|
95
|
112
|
this.overlayRef.overlayElement.appendChild( targetElement );
|
96
|
113
|
this.fullscreenChanged.emit(true);
|
97
|
114
|
}
|
98
|
115
|
|
|
116
|
+ private setStyle(el: any, nameAndUnit: string, value: any): void {
|
|
117
|
+ const [name, unit] = nameAndUnit.split('.');
|
|
118
|
+ let renderValue: string|null =
|
|
119
|
+ this.sanitizer.sanitize(SecurityContext.STYLE, value as{} | string);
|
|
120
|
+ if (renderValue != null) {
|
|
121
|
+ renderValue = renderValue.toString();
|
|
122
|
+ }
|
|
123
|
+ renderValue = renderValue != null && unit ? `${renderValue}${unit}` : renderValue;
|
|
124
|
+ if (renderValue != null) {
|
|
125
|
+ this.renderer.setStyle(this.overlayRef.overlayElement, name, renderValue);
|
|
126
|
+ } else {
|
|
127
|
+ this.renderer.removeStyle(this.overlayRef.overlayElement, name);
|
|
128
|
+ }
|
|
129
|
+ }
|
|
130
|
+
|
99
|
131
|
exitFullscreen() {
|
100
|
132
|
const targetElement: HTMLElement = this.fullscreenElement || this.elementRef.nativeElement;
|
101
|
133
|
if (this.parentElement) {
|
...
|
...
|
|