ngx-bootstrap
Version:
Native Angular Bootstrap Components
104 lines • 4.66 kB
JavaScript
import { Component, ElementRef, HostListener, Renderer } from '@angular/core';
import { ClassName, DISMISS_REASONS, ModalOptions, TransitionDurations } from './modal-options.class';
import { BsModalService } from './bs-modal.service';
import { isBs3 } from '../utils/ng2-bootstrap-config';
var ModalContainerComponent = (function () {
// @HostListener('window:focusin', ['$event'])
// public enforceFocus($event:any): void {
// if (!(this._element.nativeElement === $event.target || this._element.nativeElement.contains($event.target))) {
// this._element.nativeElement.focus();
// }
// }
// @HostListener('focusout', ['$event'])
// public preventFocusOut($event:any): void {
// if (!$event.relatedTarget) {
// this._element.nativeElement.focus();
// }
// }
function ModalContainerComponent(options, _element, bsModalService, _renderer) {
this.bsModalService = bsModalService;
this._renderer = _renderer;
this.isShown = false;
this.isModalHiding = false;
this._element = _element;
this.config = Object.assign({}, options);
}
ModalContainerComponent.prototype.onClick = function (event) {
if (this.config.ignoreBackdropClick || this.config.backdrop === 'static' || event.target !== this._element.nativeElement) {
return;
}
this.bsModalService.setDismissReason(DISMISS_REASONS.BACKRDOP);
this.hide();
};
ModalContainerComponent.prototype.onEsc = function () {
if (this.config.keyboard && this.level === this.bsModalService.getModalsCount()) {
this.bsModalService.setDismissReason(DISMISS_REASONS.ESC);
this.hide();
}
};
ModalContainerComponent.prototype.ngOnInit = function () {
var _this = this;
if (this.isAnimated) {
this._renderer.setElementClass(this._element.nativeElement, ClassName.FADE, true);
}
this._renderer.setElementStyle(this._element.nativeElement, 'display', 'block');
setTimeout(function () {
_this.isShown = true;
_this._renderer.setElementClass(_this._element.nativeElement, isBs3() ? ClassName.IN : ClassName.SHOW, true);
}, this.isAnimated ? TransitionDurations.BACKDROP : 0);
if (document && document.body) {
if (this.bsModalService.getModalsCount() === 1) {
this.bsModalService.checkScrollbar();
this.bsModalService.setScrollbar();
}
this._renderer.setElementClass(document.body, ClassName.OPEN, true);
}
};
ModalContainerComponent.prototype.ngOnDestroy = function () {
if (this.isShown) {
this.hide();
}
};
ModalContainerComponent.prototype.hide = function () {
var _this = this;
if (this.isModalHiding || !this.isShown) {
return;
}
this.isModalHiding = true;
this._renderer.setElementClass(this._element.nativeElement, isBs3() ? ClassName.IN : ClassName.SHOW, false);
setTimeout(function () {
_this.isShown = false;
if (document && document.body && _this.bsModalService.getModalsCount() === 1) {
_this._renderer.setElementClass(document.body, ClassName.OPEN, false);
}
_this.bsModalService.hide(_this.level);
_this.isModalHiding = false;
}, this.isAnimated ? TransitionDurations.MODAL : 0);
};
ModalContainerComponent.decorators = [
{ type: Component, args: [{
selector: 'modal-container',
template: "\n <div [class]=\"'modal-dialog' + (config.class ? ' ' + config.class : '')\" role=\"document\">\n <div class=\"modal-content\"><ng-content></ng-content></div>\n </div>\n ",
// tslint:disable-next-line
host: {
class: 'modal',
role: 'dialog',
tabindex: '-1'
}
},] },
];
/** @nocollapse */
ModalContainerComponent.ctorParameters = function () { return [
{ type: ModalOptions, },
{ type: ElementRef, },
{ type: BsModalService, },
{ type: Renderer, },
]; };
ModalContainerComponent.propDecorators = {
'onClick': [{ type: HostListener, args: ['click', ['$event'],] },],
'onEsc': [{ type: HostListener, args: ['window:keydown.esc',] },],
};
return ModalContainerComponent;
}());
export { ModalContainerComponent };
//# sourceMappingURL=modal-container.component.js.map