Commit 520797a1ed892459e17370094fbe51f6fecc1ef7

Authored by Igor Kulikov
1 parent c9b1e24e

Improve widget fullscreen style.

@@ -64,7 +64,10 @@ @@ -64,7 +64,10 @@
64 <div [ngClass]="dashboardClass" id="gridster-background" style="height: auto; min-height: 100%; display: inline;"> 64 <div [ngClass]="dashboardClass" id="gridster-background" style="height: auto; min-height: 100%; display: inline;">
65 <gridster #gridster id="gridster-child" [options]="gridsterOpts"> 65 <gridster #gridster id="gridster-child" [options]="gridsterOpts">
66 <gridster-item [item]="widget" class="tb-noselect" *ngFor="let widget of dashboardWidgets"> 66 <gridster-item [item]="widget" class="tb-noselect" *ngFor="let widget of dashboardWidgets">
67 - <div tb-fullscreen [fullscreen]="widget.isFullscreen" (fullscreenChanged)="onWidgetFullscreenChanged($event, widget)" 67 + <div tb-fullscreen [fullscreen]="widget.isFullscreen"
  68 + [fullscreenBackgroundStyle]="dashboardStyle"
  69 + [fullscreenBackgroundImage]="backgroundImage"
  70 + (fullscreenChanged)="onWidgetFullscreenChanged($event, widget)"
68 fxLayout="column" 71 fxLayout="column"
69 class="tb-widget" 72 class="tb-widget"
70 [ngClass]="{ 73 [ngClass]="{
@@ -19,12 +19,13 @@ import { @@ -19,12 +19,13 @@ import {
19 ElementRef, 19 ElementRef,
20 EventEmitter, 20 EventEmitter,
21 Input, OnChanges, OnDestroy, 21 Input, OnChanges, OnDestroy,
22 - Output, SimpleChanges, 22 + Output, Renderer2, SecurityContext, SimpleChanges,
23 ViewContainerRef 23 ViewContainerRef
24 } from '@angular/core'; 24 } from '@angular/core';
25 import { Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay'; 25 import { Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
26 import { ComponentPortal } from '@angular/cdk/portal'; 26 import { ComponentPortal } from '@angular/cdk/portal';
27 import { TbAnchorComponent } from '@shared/components/tb-anchor.component'; 27 import { TbAnchorComponent } from '@shared/components/tb-anchor.component';
  28 +import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
28 29
29 @Directive({ 30 @Directive({
30 selector: '[tb-fullscreen]' 31 selector: '[tb-fullscreen]'
@@ -42,10 +43,18 @@ export class FullscreenDirective implements OnChanges, OnDestroy { @@ -42,10 +43,18 @@ export class FullscreenDirective implements OnChanges, OnDestroy {
42 @Input() 43 @Input()
43 fullscreenElement: HTMLElement; 44 fullscreenElement: HTMLElement;
44 45
  46 + @Input()
  47 + fullscreenBackgroundStyle: {[klass: string]: any};
  48 +
  49 + @Input()
  50 + fullscreenBackgroundImage: SafeStyle | string;
  51 +
45 @Output() 52 @Output()
46 fullscreenChanged = new EventEmitter<boolean>(); 53 fullscreenChanged = new EventEmitter<boolean>();
47 54
48 constructor(public elementRef: ElementRef, 55 constructor(public elementRef: ElementRef,
  56 + private renderer: Renderer2,
  57 + private sanitizer: DomSanitizer,
49 private viewContainerRef: ViewContainerRef, 58 private viewContainerRef: ViewContainerRef,
50 private overlay: Overlay) { 59 private overlay: Overlay) {
51 } 60 }
@@ -92,10 +101,33 @@ export class FullscreenDirective implements OnChanges, OnDestroy { @@ -92,10 +101,33 @@ export class FullscreenDirective implements OnChanges, OnDestroy {
92 101
93 this.overlayRef = this.overlay.create(config); 102 this.overlayRef = this.overlay.create(config);
94 this.overlayRef.attach(new EmptyPortal()); 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 this.overlayRef.overlayElement.appendChild( targetElement ); 112 this.overlayRef.overlayElement.appendChild( targetElement );
96 this.fullscreenChanged.emit(true); 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 exitFullscreen() { 131 exitFullscreen() {
100 const targetElement: HTMLElement = this.fullscreenElement || this.elementRef.nativeElement; 132 const targetElement: HTMLElement = this.fullscreenElement || this.elementRef.nativeElement;
101 if (this.parentElement) { 133 if (this.parentElement) {