Skip to content

Commit

Permalink
Add window resize event
Browse files Browse the repository at this point in the history
See #15
  • Loading branch information
themyth92 committed Jun 15, 2017
1 parent beefeee commit d26b4f6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/lightbox-overlay.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AfterViewInit,
Component,
ElementRef,
HostListener,
Inject,
Input,
OnDestroy,
Expand Down Expand Up @@ -35,27 +36,37 @@ export class LightboxOverlayComponent implements AfterViewInit, OnDestroy {
}

public ngAfterViewInit(): void {
const width = this._getOverlayWidth();
const height = this._getOverlayHeight();
const fadeDuration = this.options.fadeDuration;

this._rendererRef.setElementStyle(this._elemRef.nativeElement, 'width', `${width}px`);
this._rendererRef.setElementStyle(this._elemRef.nativeElement, 'height', `${height}px`);
this._rendererRef.setElementStyle(this._elemRef.nativeElement,
'-webkit-animation-duration', `${fadeDuration}s`);
this._rendererRef.setElementStyle(this._elemRef.nativeElement,
'-animation-duration', `${fadeDuration}s`);
this._sizeOverlay();
}

public close(): void {
// broadcast to itself and all others subscriber including the components
this._lightboxEvent.broadcastLightboxEvent({ id: LIGHTBOX_EVENT.CLOSE, data: null });
}

@HostListener('window:resize')
public onResize(): void {
this._sizeOverlay();
}

public ngOnDestroy(): void {
this._subscription.unsubscribe();
}

private _sizeOverlay(): void {
const width = this._getOverlayWidth();
const height = this._getOverlayHeight();

this._rendererRef.setElementStyle(this._elemRef.nativeElement, 'width', `${width}px`);
this._rendererRef.setElementStyle(this._elemRef.nativeElement, 'height', `${height}px`);
}

private _onReceivedEvent(event: IEvent): void {
switch (event.id) {
case LIGHTBOX_EVENT.CLOSE:
Expand Down

0 comments on commit d26b4f6

Please sign in to comment.