Skip to content

Commit

Permalink
code refactoring for more readability and maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaritossa authored and themyth92 committed Feb 5, 2018
1 parent 6de57a0 commit 1a8e7b1
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/lightbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,20 @@ export class LightboxComponent implements AfterViewInit, OnDestroy {
this._sizeContainer(imageWidth, imageHeight);

if (this.options.centerVertically) {
var scrollOffset = this._documentRef.documentElement.scrollTop;
var viewOffset = windowHeight / 2 - imageHeight / 2;
var topDistance = scrollOffset + viewOffset;

this._rendererRef.setElementStyle(this._lightboxElem.nativeElement, 'top', `${topDistance}px`);
this._centerVertically(imageWidth, imageHeight);
}
}

private _centerVertically(imageWidth: number, imageHeight: number): void {
const scrollOffset = this._documentRef.documentElement.scrollTop;
const windowHeight = this._windowRef.innerHeight;

const viewOffset = windowHeight / 2 - imageHeight / 2;
const topDistance = scrollOffset + viewOffset;

this._rendererRef.setElementStyle(this._lightboxElem.nativeElement, 'top', `${topDistance}px`);
}

private _sizeContainer(imageWidth: number, imageHeight: number): void {
const oldWidth = this._outerContainerElem.nativeElement.offsetWidth;
const oldHeight = this._outerContainerElem.nativeElement.offsetHeight;
Expand Down

0 comments on commit 1a8e7b1

Please sign in to comment.