Improve widget fullscreen style.
This commit is contained in:
parent
c9b1e24e24
commit
520797a1ed
@ -64,7 +64,10 @@
|
|||||||
<div [ngClass]="dashboardClass" id="gridster-background" style="height: auto; min-height: 100%; display: inline;">
|
<div [ngClass]="dashboardClass" id="gridster-background" style="height: auto; min-height: 100%; display: inline;">
|
||||||
<gridster #gridster id="gridster-child" [options]="gridsterOpts">
|
<gridster #gridster id="gridster-child" [options]="gridsterOpts">
|
||||||
<gridster-item [item]="widget" class="tb-noselect" *ngFor="let widget of dashboardWidgets">
|
<gridster-item [item]="widget" class="tb-noselect" *ngFor="let widget of dashboardWidgets">
|
||||||
<div tb-fullscreen [fullscreen]="widget.isFullscreen" (fullscreenChanged)="onWidgetFullscreenChanged($event, widget)"
|
<div tb-fullscreen [fullscreen]="widget.isFullscreen"
|
||||||
|
[fullscreenBackgroundStyle]="dashboardStyle"
|
||||||
|
[fullscreenBackgroundImage]="backgroundImage"
|
||||||
|
(fullscreenChanged)="onWidgetFullscreenChanged($event, widget)"
|
||||||
fxLayout="column"
|
fxLayout="column"
|
||||||
class="tb-widget"
|
class="tb-widget"
|
||||||
[ngClass]="{
|
[ngClass]="{
|
||||||
|
|||||||
@ -19,12 +19,13 @@ import {
|
|||||||
ElementRef,
|
ElementRef,
|
||||||
EventEmitter,
|
EventEmitter,
|
||||||
Input, OnChanges, OnDestroy,
|
Input, OnChanges, OnDestroy,
|
||||||
Output, SimpleChanges,
|
Output, Renderer2, SecurityContext, SimpleChanges,
|
||||||
ViewContainerRef
|
ViewContainerRef
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
|
import { Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
|
||||||
import { ComponentPortal } from '@angular/cdk/portal';
|
import { ComponentPortal } from '@angular/cdk/portal';
|
||||||
import { TbAnchorComponent } from '@shared/components/tb-anchor.component';
|
import { TbAnchorComponent } from '@shared/components/tb-anchor.component';
|
||||||
|
import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[tb-fullscreen]'
|
selector: '[tb-fullscreen]'
|
||||||
@ -42,10 +43,18 @@ export class FullscreenDirective implements OnChanges, OnDestroy {
|
|||||||
@Input()
|
@Input()
|
||||||
fullscreenElement: HTMLElement;
|
fullscreenElement: HTMLElement;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
fullscreenBackgroundStyle: {[klass: string]: any};
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
fullscreenBackgroundImage: SafeStyle | string;
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
fullscreenChanged = new EventEmitter<boolean>();
|
fullscreenChanged = new EventEmitter<boolean>();
|
||||||
|
|
||||||
constructor(public elementRef: ElementRef,
|
constructor(public elementRef: ElementRef,
|
||||||
|
private renderer: Renderer2,
|
||||||
|
private sanitizer: DomSanitizer,
|
||||||
private viewContainerRef: ViewContainerRef,
|
private viewContainerRef: ViewContainerRef,
|
||||||
private overlay: Overlay) {
|
private overlay: Overlay) {
|
||||||
}
|
}
|
||||||
@ -92,10 +101,33 @@ export class FullscreenDirective implements OnChanges, OnDestroy {
|
|||||||
|
|
||||||
this.overlayRef = this.overlay.create(config);
|
this.overlayRef = this.overlay.create(config);
|
||||||
this.overlayRef.attach(new EmptyPortal());
|
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.overlayRef.overlayElement.appendChild( targetElement );
|
||||||
this.fullscreenChanged.emit(true);
|
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() {
|
exitFullscreen() {
|
||||||
const targetElement: HTMLElement = this.fullscreenElement || this.elementRef.nativeElement;
|
const targetElement: HTMLElement = this.fullscreenElement || this.elementRef.nativeElement;
|
||||||
if (this.parentElement) {
|
if (this.parentElement) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user