|
|
|
@ -19,12 +19,13 @@ import { |
|
|
|
ElementRef, |
|
|
|
EventEmitter, |
|
|
|
Input, OnChanges, OnDestroy, |
|
|
|
Output, SimpleChanges, |
|
|
|
Output, Renderer2, SecurityContext, SimpleChanges, |
|
|
|
ViewContainerRef |
|
|
|
} from '@angular/core'; |
|
|
|
import { Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; |
|
|
|
import { ComponentPortal } from '@angular/cdk/portal'; |
|
|
|
import { TbAnchorComponent } from '@shared/components/tb-anchor.component'; |
|
|
|
import { DomSanitizer, SafeStyle } from '@angular/platform-browser'; |
|
|
|
|
|
|
|
@Directive({ |
|
|
|
selector: '[tb-fullscreen]' |
|
|
|
@ -42,10 +43,18 @@ export class FullscreenDirective implements OnChanges, OnDestroy { |
|
|
|
@Input() |
|
|
|
fullscreenElement: HTMLElement; |
|
|
|
|
|
|
|
@Input() |
|
|
|
fullscreenBackgroundStyle: {[klass: string]: any}; |
|
|
|
|
|
|
|
@Input() |
|
|
|
fullscreenBackgroundImage: SafeStyle | string; |
|
|
|
|
|
|
|
@Output() |
|
|
|
fullscreenChanged = new EventEmitter<boolean>(); |
|
|
|
|
|
|
|
constructor(public elementRef: ElementRef, |
|
|
|
private renderer: Renderer2, |
|
|
|
private sanitizer: DomSanitizer, |
|
|
|
private viewContainerRef: ViewContainerRef, |
|
|
|
private overlay: Overlay) { |
|
|
|
} |
|
|
|
@ -92,10 +101,33 @@ export class FullscreenDirective implements OnChanges, OnDestroy { |
|
|
|
|
|
|
|
this.overlayRef = this.overlay.create(config); |
|
|
|
this.overlayRef.attach(new EmptyPortal()); |
|
|
|
if (this.fullscreenBackgroundStyle) { |
|
|
|
for (const key of Object.keys(this.fullscreenBackgroundStyle)) { |
|
|
|
this.setStyle(this.overlayRef.overlayElement, key, this.fullscreenBackgroundStyle[key]); |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.fullscreenBackgroundImage) { |
|
|
|
this.setStyle(this.overlayRef.overlayElement, 'backgroundImage', this.fullscreenBackgroundImage); |
|
|
|
} |
|
|
|
this.overlayRef.overlayElement.appendChild( targetElement ); |
|
|
|
this.fullscreenChanged.emit(true); |
|
|
|
} |
|
|
|
|
|
|
|
private setStyle(el: any, nameAndUnit: string, value: any): void { |
|
|
|
const [name, unit] = nameAndUnit.split('.'); |
|
|
|
let renderValue: string|null = |
|
|
|
this.sanitizer.sanitize(SecurityContext.STYLE, value as{} | string); |
|
|
|
if (renderValue != null) { |
|
|
|
renderValue = renderValue.toString(); |
|
|
|
} |
|
|
|
renderValue = renderValue != null && unit ? `${renderValue}${unit}` : renderValue; |
|
|
|
if (renderValue != null) { |
|
|
|
this.renderer.setStyle(this.overlayRef.overlayElement, name, renderValue); |
|
|
|
} else { |
|
|
|
this.renderer.removeStyle(this.overlayRef.overlayElement, name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
exitFullscreen() { |
|
|
|
const targetElement: HTMLElement = this.fullscreenElement || this.elementRef.nativeElement; |
|
|
|
if (this.parentElement) { |
|
|
|
|