UNPKG

custom-lightbox

Version:

custom-lightbox

105 lines 5.38 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var lightbox_event_service_1 = require("./lightbox-event.service"); var LightboxOverlayComponent = /** @class */ (function () { function LightboxOverlayComponent(_elemRef, _rendererRef, _lightboxEvent) { var _this = this; this._elemRef = _elemRef; this._rendererRef = _rendererRef; this._lightboxEvent = _lightboxEvent; this.classList = 'lightboxOverlay animation fadeInOverlay'; this._subscription = this._lightboxEvent.lightboxEvent$.subscribe(function (event) { return _this._onReceivedEvent(event); }); this._documentRef = window.document; } LightboxOverlayComponent.prototype.close = function () { // broadcast to itself and all others subscriber including the components this._lightboxEvent.broadcastLightboxEvent({ id: lightbox_event_service_1.LIGHTBOX_EVENT.CLOSE, data: null }); }; LightboxOverlayComponent.prototype.ngAfterViewInit = function () { var fadeDuration = this.options.fadeDuration; this._rendererRef.setStyle(this._elemRef.nativeElement, '-webkit-animation-duration', fadeDuration + "s"); this._rendererRef.setStyle(this._elemRef.nativeElement, 'animation-duration', fadeDuration + "s"); this._sizeOverlay(); }; LightboxOverlayComponent.prototype.onResize = function () { this._sizeOverlay(); }; LightboxOverlayComponent.prototype.ngOnDestroy = function () { this._subscription.unsubscribe(); }; LightboxOverlayComponent.prototype._sizeOverlay = function () { var width = this._getOverlayWidth(); var height = this._getOverlayHeight(); this._rendererRef.setStyle(this._elemRef.nativeElement, 'width', width + "px"); this._rendererRef.setStyle(this._elemRef.nativeElement, 'height', height + "px"); }; LightboxOverlayComponent.prototype._onReceivedEvent = function (event) { switch (event.id) { case lightbox_event_service_1.LIGHTBOX_EVENT.CLOSE: this._end(); break; default: break; } }; LightboxOverlayComponent.prototype._end = function () { var _this = this; this.classList = 'lightboxOverlay animation fadeOutOverlay'; // queue self destruction after the animation has finished // FIXME: not sure if there is any way better than this setTimeout(function () { _this.cmpRef.destroy(); }, this.options.fadeDuration * 1000); }; LightboxOverlayComponent.prototype._getOverlayWidth = function () { return Math.max(this._documentRef.body.scrollWidth, this._documentRef.body.offsetWidth, this._documentRef.documentElement.clientWidth, this._documentRef.documentElement.scrollWidth, this._documentRef.documentElement.offsetWidth); }; LightboxOverlayComponent.prototype._getOverlayHeight = function () { return Math.max(this._documentRef.body.scrollHeight, this._documentRef.body.offsetHeight, this._documentRef.documentElement.clientHeight, this._documentRef.documentElement.scrollHeight, this._documentRef.documentElement.offsetHeight); }; __decorate([ core_1.Input(), __metadata("design:type", Object) ], LightboxOverlayComponent.prototype, "options", void 0); __decorate([ core_1.Input(), __metadata("design:type", Object) ], LightboxOverlayComponent.prototype, "cmpRef", void 0); __decorate([ core_1.HostListener('click'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], LightboxOverlayComponent.prototype, "close", null); __decorate([ core_1.HostListener('window:resize'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], LightboxOverlayComponent.prototype, "onResize", null); LightboxOverlayComponent = __decorate([ core_1.Component({ selector: '[lb-overlay]', template: '', host: { '[class]': 'classList' } }), __metadata("design:paramtypes", [core_1.ElementRef, core_1.Renderer2, lightbox_event_service_1.LightboxEvent]) ], LightboxOverlayComponent); return LightboxOverlayComponent; }()); exports.LightboxOverlayComponent = LightboxOverlayComponent; //# sourceMappingURL=lightbox-overlay.component.js.map