| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318 |
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('ngx-bootstrap/utils'), require('ngx-bootstrap/component-loader'), require('ngx-bootstrap/positioning')) :
- typeof define === 'function' && define.amd ? define('ngx-bootstrap/modal', ['exports', '@angular/core', 'ngx-bootstrap/utils', 'ngx-bootstrap/component-loader', 'ngx-bootstrap/positioning'], factory) :
- (global = global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].modal = {}), global.ng.core, global.utils, global.componentLoader, global.positioning));
- }(this, function (exports, core, utils, componentLoader, positioning) { 'use strict';
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var BsModalRef = /** @class */ (function () {
- function BsModalRef() {
- /**
- * Hides the modal
- */
- this.hide = Function;
- /**
- * Sets new class to modal window
- */
- this.setClass = Function;
- }
- BsModalRef.decorators = [
- { type: core.Injectable }
- ];
- return BsModalRef;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var ModalBackdropOptions = /** @class */ (function () {
- function ModalBackdropOptions(options) {
- this.animate = true;
- Object.assign(this, options);
- }
- return ModalBackdropOptions;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var ModalOptions = /** @class */ (function () {
- function ModalOptions() {
- }
- ModalOptions.decorators = [
- { type: core.Injectable }
- ];
- return ModalOptions;
- }());
- /** @type {?} */
- var modalConfigDefaults = {
- backdrop: true,
- keyboard: true,
- focus: true,
- show: false,
- ignoreBackdropClick: false,
- class: '',
- animated: true,
- initialState: {}
- };
- /** @type {?} */
- var CLASS_NAME = {
- SCROLLBAR_MEASURER: 'modal-scrollbar-measure',
- BACKDROP: 'modal-backdrop',
- OPEN: 'modal-open',
- FADE: 'fade',
- IN: 'in',
- // bs3
- SHOW: 'show' // bs4
- };
- /** @type {?} */
- var TRANSITION_DURATIONS = {
- MODAL: 300,
- BACKDROP: 150
- };
- /** @type {?} */
- var DISMISS_REASONS = {
- BACKRDOP: 'backdrop-click',
- ESC: 'esc'
- };
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var ModalContainerComponent = /** @class */ (function () {
- function ModalContainerComponent(options, _element, _renderer) {
- this._element = _element;
- this._renderer = _renderer;
- this.isShown = false;
- this.isModalHiding = false;
- this.config = Object.assign({}, options);
- }
- /**
- * @return {?}
- */
- ModalContainerComponent.prototype.ngOnInit = /**
- * @return {?}
- */
- function () {
- var _this = this;
- if (this.isAnimated) {
- this._renderer.addClass(this._element.nativeElement, CLASS_NAME.FADE);
- }
- this._renderer.setStyle(this._element.nativeElement, 'display', 'block');
- setTimeout((/**
- * @return {?}
- */
- function () {
- _this.isShown = true;
- _this._renderer.addClass(_this._element.nativeElement, utils.isBs3() ? CLASS_NAME.IN : CLASS_NAME.SHOW);
- }), this.isAnimated ? TRANSITION_DURATIONS.BACKDROP : 0);
- if (document && document.body) {
- if (this.bsModalService.getModalsCount() === 1) {
- this.bsModalService.checkScrollbar();
- this.bsModalService.setScrollbar();
- }
- this._renderer.addClass(document.body, CLASS_NAME.OPEN);
- }
- if (this._element.nativeElement) {
- this._element.nativeElement.focus();
- }
- };
- /**
- * @param {?} event
- * @return {?}
- */
- ModalContainerComponent.prototype.onClick = /**
- * @param {?} event
- * @return {?}
- */
- function (event) {
- if (this.config.ignoreBackdropClick ||
- this.config.backdrop === 'static' ||
- event.target !== this._element.nativeElement) {
- return;
- }
- this.bsModalService.setDismissReason(DISMISS_REASONS.BACKRDOP);
- this.hide();
- };
- /**
- * @param {?} event
- * @return {?}
- */
- ModalContainerComponent.prototype.onEsc = /**
- * @param {?} event
- * @return {?}
- */
- function (event) {
- if (!this.isShown) {
- return;
- }
- // tslint:disable-next-line:deprecation
- if (event.keyCode === 27 || event.key === 'Escape') {
- event.preventDefault();
- }
- if (this.config.keyboard &&
- this.level === this.bsModalService.getModalsCount()) {
- this.bsModalService.setDismissReason(DISMISS_REASONS.ESC);
- this.hide();
- }
- };
- /**
- * @return {?}
- */
- ModalContainerComponent.prototype.ngOnDestroy = /**
- * @return {?}
- */
- function () {
- if (this.isShown) {
- this.hide();
- }
- };
- /**
- * @return {?}
- */
- ModalContainerComponent.prototype.hide = /**
- * @return {?}
- */
- function () {
- var _this = this;
- if (this.isModalHiding || !this.isShown) {
- return;
- }
- this.isModalHiding = true;
- this._renderer.removeClass(this._element.nativeElement, utils.isBs3() ? CLASS_NAME.IN : CLASS_NAME.SHOW);
- setTimeout((/**
- * @return {?}
- */
- function () {
- _this.isShown = false;
- if (document &&
- document.body &&
- _this.bsModalService.getModalsCount() === 1) {
- _this._renderer.removeClass(document.body, CLASS_NAME.OPEN);
- }
- _this.bsModalService.hide(_this.level);
- _this.isModalHiding = false;
- }), this.isAnimated ? TRANSITION_DURATIONS.MODAL : 0);
- };
- ModalContainerComponent.decorators = [
- { type: core.Component, args: [{
- selector: 'modal-container',
- template: "\n <div [class]=\"'modal-dialog' + (config.class ? ' ' + config.class : '')\" role=\"document\">\n <div class=\"modal-content\">\n <ng-content></ng-content>\n </div>\n </div>\n ",
- host: {
- class: 'modal',
- role: 'dialog',
- tabindex: '-1',
- '[attr.aria-modal]': 'true'
- }
- }] }
- ];
- /** @nocollapse */
- ModalContainerComponent.ctorParameters = function () { return [
- { type: ModalOptions },
- { type: core.ElementRef },
- { type: core.Renderer2 }
- ]; };
- ModalContainerComponent.propDecorators = {
- onClick: [{ type: core.HostListener, args: ['click', ['$event'],] }],
- onEsc: [{ type: core.HostListener, args: ['window:keydown.esc', ['$event'],] }]
- };
- return ModalContainerComponent;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /**
- * This component will be added as background layout for modals if enabled
- */
- var ModalBackdropComponent = /** @class */ (function () {
- function ModalBackdropComponent(element, renderer) {
- this._isShown = false;
- this.element = element;
- this.renderer = renderer;
- }
- Object.defineProperty(ModalBackdropComponent.prototype, "isAnimated", {
- get: /**
- * @return {?}
- */
- function () {
- return this._isAnimated;
- },
- set: /**
- * @param {?} value
- * @return {?}
- */
- function (value) {
- this._isAnimated = value;
- // this.renderer.setElementClass(this.element.nativeElement, `${ClassName.FADE}`, value);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(ModalBackdropComponent.prototype, "isShown", {
- get: /**
- * @return {?}
- */
- function () {
- return this._isShown;
- },
- set: /**
- * @param {?} value
- * @return {?}
- */
- function (value) {
- this._isShown = value;
- if (value) {
- this.renderer.addClass(this.element.nativeElement, "" + CLASS_NAME.IN);
- }
- else {
- this.renderer.removeClass(this.element.nativeElement, "" + CLASS_NAME.IN);
- }
- if (!utils.isBs3()) {
- if (value) {
- this.renderer.addClass(this.element.nativeElement, "" + CLASS_NAME.SHOW);
- }
- else {
- this.renderer.removeClass(this.element.nativeElement, "" + CLASS_NAME.SHOW);
- }
- }
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @return {?}
- */
- ModalBackdropComponent.prototype.ngOnInit = /**
- * @return {?}
- */
- function () {
- if (this.isAnimated) {
- this.renderer.addClass(this.element.nativeElement, "" + CLASS_NAME.FADE);
- utils.Utils.reflow(this.element.nativeElement);
- }
- this.isShown = true;
- };
- ModalBackdropComponent.decorators = [
- { type: core.Component, args: [{
- selector: 'bs-modal-backdrop',
- template: ' ',
- host: { class: CLASS_NAME.BACKDROP }
- }] }
- ];
- /** @nocollapse */
- ModalBackdropComponent.ctorParameters = function () { return [
- { type: core.ElementRef },
- { type: core.Renderer2 }
- ]; };
- return ModalBackdropComponent;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /** @type {?} */
- var TRANSITION_DURATION = 300;
- /** @type {?} */
- var BACKDROP_TRANSITION_DURATION = 150;
- /**
- * Mark any code with directive to show it's content in modal
- */
- var ModalDirective = /** @class */ (function () {
- function ModalDirective(_element, _viewContainerRef, _renderer, clf) {
- this._element = _element;
- this._renderer = _renderer;
- /**
- * This event fires immediately when the `show` instance method is called.
- */
- this.onShow = new core.EventEmitter();
- /**
- * This event is fired when the modal has been made visible to the user
- * (will wait for CSS transitions to complete)
- */
- this.onShown = new core.EventEmitter();
- /**
- * This event is fired immediately when
- * the hide instance method has been called.
- */
- this.onHide = new core.EventEmitter();
- /**
- * This event is fired when the modal has finished being
- * hidden from the user (will wait for CSS transitions to complete).
- */
- this.onHidden = new core.EventEmitter();
- this._isShown = false;
- this.isBodyOverflowing = false;
- this.originalBodyPadding = 0;
- this.scrollbarWidth = 0;
- this.timerHideModal = 0;
- this.timerRmBackDrop = 0;
- this.isNested = false;
- this._backdrop = clf.createLoader(_element, _viewContainerRef, _renderer);
- }
- Object.defineProperty(ModalDirective.prototype, "config", {
- get: /**
- * @return {?}
- */
- function () {
- return this._config;
- },
- /** allows to set modal configuration via element property */
- set: /**
- * allows to set modal configuration via element property
- * @param {?} conf
- * @return {?}
- */
- function (conf) {
- this._config = this.getConfig(conf);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(ModalDirective.prototype, "isShown", {
- get: /**
- * @return {?}
- */
- function () {
- return this._isShown;
- },
- enumerable: true,
- configurable: true
- });
- /**
- * @param {?} event
- * @return {?}
- */
- ModalDirective.prototype.onClick = /**
- * @param {?} event
- * @return {?}
- */
- function (event) {
- if (this.config.ignoreBackdropClick ||
- this.config.backdrop === 'static' ||
- event.target !== this._element.nativeElement) {
- return;
- }
- this.dismissReason = DISMISS_REASONS.BACKRDOP;
- this.hide(event);
- };
- // todo: consider preventing default and stopping propagation
- // todo: consider preventing default and stopping propagation
- /**
- * @param {?} event
- * @return {?}
- */
- ModalDirective.prototype.onEsc =
- // todo: consider preventing default and stopping propagation
- /**
- * @param {?} event
- * @return {?}
- */
- function (event) {
- if (!this._isShown) {
- return;
- }
- // tslint:disable-next-line:deprecation
- if (event.keyCode === 27 || event.key === 'Escape') {
- event.preventDefault();
- }
- if (this.config.keyboard) {
- this.dismissReason = DISMISS_REASONS.ESC;
- this.hide();
- }
- };
- /**
- * @return {?}
- */
- ModalDirective.prototype.ngOnDestroy = /**
- * @return {?}
- */
- function () {
- this.config = void 0;
- if (this._isShown) {
- this._isShown = false;
- this.hideModal();
- this._backdrop.dispose();
- }
- };
- /**
- * @return {?}
- */
- ModalDirective.prototype.ngOnInit = /**
- * @return {?}
- */
- function () {
- var _this = this;
- this._config = this._config || this.getConfig();
- setTimeout((/**
- * @return {?}
- */
- function () {
- if (_this._config.show) {
- _this.show();
- }
- }), 0);
- };
- /* Public methods */
- /** Allows to manually toggle modal visibility */
- /* Public methods */
- /**
- * Allows to manually toggle modal visibility
- * @return {?}
- */
- ModalDirective.prototype.toggle = /* Public methods */
- /**
- * Allows to manually toggle modal visibility
- * @return {?}
- */
- function () {
- return this._isShown ? this.hide() : this.show();
- };
- /** Allows to manually open modal */
- /**
- * Allows to manually open modal
- * @return {?}
- */
- ModalDirective.prototype.show = /**
- * Allows to manually open modal
- * @return {?}
- */
- function () {
- var _this = this;
- this.dismissReason = null;
- this.onShow.emit(this);
- if (this._isShown) {
- return;
- }
- clearTimeout(this.timerHideModal);
- clearTimeout(this.timerRmBackDrop);
- this._isShown = true;
- this.checkScrollbar();
- this.setScrollbar();
- if (utils.document && utils.document.body) {
- if (utils.document.body.classList.contains(CLASS_NAME.OPEN)) {
- this.isNested = true;
- }
- else {
- this._renderer.addClass(utils.document.body, CLASS_NAME.OPEN);
- }
- }
- this.showBackdrop((/**
- * @return {?}
- */
- function () {
- _this.showElement();
- }));
- };
- /** Allows to manually close modal */
- /**
- * Allows to manually close modal
- * @param {?=} event
- * @return {?}
- */
- ModalDirective.prototype.hide = /**
- * Allows to manually close modal
- * @param {?=} event
- * @return {?}
- */
- function (event) {
- var _this = this;
- if (event) {
- event.preventDefault();
- }
- this.onHide.emit(this);
- // todo: add an option to prevent hiding
- if (!this._isShown) {
- return;
- }
- utils.window.clearTimeout(this.timerHideModal);
- utils.window.clearTimeout(this.timerRmBackDrop);
- this._isShown = false;
- this._renderer.removeClass(this._element.nativeElement, CLASS_NAME.IN);
- if (!utils.isBs3()) {
- this._renderer.removeClass(this._element.nativeElement, CLASS_NAME.SHOW);
- }
- // this._addClassIn = false;
- if (this._config.animated) {
- this.timerHideModal = utils.window.setTimeout((/**
- * @return {?}
- */
- function () { return _this.hideModal(); }), TRANSITION_DURATION);
- }
- else {
- this.hideModal();
- }
- };
- /** Private methods @internal */
- /**
- * Private methods \@internal
- * @protected
- * @param {?=} config
- * @return {?}
- */
- ModalDirective.prototype.getConfig = /**
- * Private methods \@internal
- * @protected
- * @param {?=} config
- * @return {?}
- */
- function (config) {
- return Object.assign({}, modalConfigDefaults, config);
- };
- /**
- * Show dialog
- * @internal
- */
- /**
- * Show dialog
- * \@internal
- * @protected
- * @return {?}
- */
- ModalDirective.prototype.showElement = /**
- * Show dialog
- * \@internal
- * @protected
- * @return {?}
- */
- function () {
- var _this = this;
- // todo: replace this with component loader usage
- if (!this._element.nativeElement.parentNode ||
- this._element.nativeElement.parentNode.nodeType !== Node.ELEMENT_NODE) {
- // don't move modals dom position
- if (utils.document && utils.document.body) {
- utils.document.body.appendChild(this._element.nativeElement);
- }
- }
- this._renderer.setAttribute(this._element.nativeElement, 'aria-hidden', 'false');
- this._renderer.setAttribute(this._element.nativeElement, 'aria-modal', 'true');
- this._renderer.setStyle(this._element.nativeElement, 'display', 'block');
- this._renderer.setProperty(this._element.nativeElement, 'scrollTop', 0);
- if (this._config.animated) {
- utils.Utils.reflow(this._element.nativeElement);
- }
- // this._addClassIn = true;
- this._renderer.addClass(this._element.nativeElement, CLASS_NAME.IN);
- if (!utils.isBs3()) {
- this._renderer.addClass(this._element.nativeElement, CLASS_NAME.SHOW);
- }
- /** @type {?} */
- var transitionComplete = (/**
- * @return {?}
- */
- function () {
- if (_this._config.focus) {
- _this._element.nativeElement.focus();
- }
- _this.onShown.emit(_this);
- });
- if (this._config.animated) {
- setTimeout(transitionComplete, TRANSITION_DURATION);
- }
- else {
- transitionComplete();
- }
- };
- /** @internal */
- /**
- * \@internal
- * @protected
- * @return {?}
- */
- ModalDirective.prototype.hideModal = /**
- * \@internal
- * @protected
- * @return {?}
- */
- function () {
- var _this = this;
- this._renderer.setAttribute(this._element.nativeElement, 'aria-hidden', 'true');
- this._renderer.setStyle(this._element.nativeElement, 'display', 'none');
- this.showBackdrop((/**
- * @return {?}
- */
- function () {
- if (!_this.isNested) {
- if (utils.document && utils.document.body) {
- _this._renderer.removeClass(utils.document.body, CLASS_NAME.OPEN);
- }
- _this.resetScrollbar();
- }
- _this.resetAdjustments();
- _this.focusOtherModal();
- _this.onHidden.emit(_this);
- }));
- };
- // todo: original show was calling a callback when done, but we can use
- // promise
- /** @internal */
- // todo: original show was calling a callback when done, but we can use
- // promise
- /**
- * \@internal
- * @protected
- * @param {?=} callback
- * @return {?}
- */
- ModalDirective.prototype.showBackdrop =
- // todo: original show was calling a callback when done, but we can use
- // promise
- /**
- * \@internal
- * @protected
- * @param {?=} callback
- * @return {?}
- */
- function (callback) {
- var _this = this;
- if (this._isShown &&
- this.config.backdrop &&
- (!this.backdrop || !this.backdrop.instance.isShown)) {
- this.removeBackdrop();
- this._backdrop
- .attach(ModalBackdropComponent)
- .to('body')
- .show({ isAnimated: this._config.animated });
- this.backdrop = this._backdrop._componentRef;
- if (!callback) {
- return;
- }
- if (!this._config.animated) {
- callback();
- return;
- }
- setTimeout(callback, BACKDROP_TRANSITION_DURATION);
- }
- else if (!this._isShown && this.backdrop) {
- this.backdrop.instance.isShown = false;
- /** @type {?} */
- var callbackRemove = (/**
- * @return {?}
- */
- function () {
- _this.removeBackdrop();
- if (callback) {
- callback();
- }
- });
- if (this.backdrop.instance.isAnimated) {
- this.timerRmBackDrop = utils.window.setTimeout(callbackRemove, BACKDROP_TRANSITION_DURATION);
- }
- else {
- callbackRemove();
- }
- }
- else if (callback) {
- callback();
- }
- };
- /** @internal */
- /**
- * \@internal
- * @protected
- * @return {?}
- */
- ModalDirective.prototype.removeBackdrop = /**
- * \@internal
- * @protected
- * @return {?}
- */
- function () {
- this._backdrop.hide();
- };
- /** Events tricks */
- // no need for it
- // protected setEscapeEvent():void {
- // if (this._isShown && this._config.keyboard) {
- // $(this._element).on(Event.KEYDOWN_DISMISS, (event) => {
- // if (event.which === 27) {
- // this.hide()
- // }
- // })
- //
- // } else if (!this._isShown) {
- // $(this._element).off(Event.KEYDOWN_DISMISS)
- // }
- // }
- // protected setResizeEvent():void {
- // console.log(this.renderer.listenGlobal('', Event.RESIZE));
- // if (this._isShown) {
- // $(window).on(Event.RESIZE, $.proxy(this._handleUpdate, this))
- // } else {
- // $(window).off(Event.RESIZE)
- // }
- // }
- /**
- * Events tricks
- * @protected
- * @return {?}
- */
- // no need for it
- // protected setEscapeEvent():void {
- // if (this._isShown && this._config.keyboard) {
- // $(this._element).on(Event.KEYDOWN_DISMISS, (event) => {
- // if (event.which === 27) {
- // this.hide()
- // }
- // })
- //
- // } else if (!this._isShown) {
- // $(this._element).off(Event.KEYDOWN_DISMISS)
- // }
- // }
- // protected setResizeEvent():void {
- // console.log(this.renderer.listenGlobal('', Event.RESIZE));
- // if (this._isShown) {
- // $(window).on(Event.RESIZE, $.proxy(this._handleUpdate, this))
- // } else {
- // $(window).off(Event.RESIZE)
- // }
- // }
- ModalDirective.prototype.focusOtherModal = /**
- * Events tricks
- * @protected
- * @return {?}
- */
- // no need for it
- // protected setEscapeEvent():void {
- // if (this._isShown && this._config.keyboard) {
- // $(this._element).on(Event.KEYDOWN_DISMISS, (event) => {
- // if (event.which === 27) {
- // this.hide()
- // }
- // })
- //
- // } else if (!this._isShown) {
- // $(this._element).off(Event.KEYDOWN_DISMISS)
- // }
- // }
- // protected setResizeEvent():void {
- // console.log(this.renderer.listenGlobal('', Event.RESIZE));
- // if (this._isShown) {
- // $(window).on(Event.RESIZE, $.proxy(this._handleUpdate, this))
- // } else {
- // $(window).off(Event.RESIZE)
- // }
- // }
- function () {
- if (this._element.nativeElement.parentElement == null) {
- return;
- }
- /** @type {?} */
- var otherOpenedModals = this._element.nativeElement.parentElement.querySelectorAll('.in[bsModal]');
- if (!otherOpenedModals.length) {
- return;
- }
- otherOpenedModals[otherOpenedModals.length - 1].focus();
- };
- /** @internal */
- /**
- * \@internal
- * @protected
- * @return {?}
- */
- ModalDirective.prototype.resetAdjustments = /**
- * \@internal
- * @protected
- * @return {?}
- */
- function () {
- this._renderer.setStyle(this._element.nativeElement, 'paddingLeft', '');
- this._renderer.setStyle(this._element.nativeElement, 'paddingRight', '');
- };
- /** Scroll bar tricks */
- /** @internal */
- /** Scroll bar tricks */
- /**
- * \@internal
- * @protected
- * @return {?}
- */
- ModalDirective.prototype.checkScrollbar = /** Scroll bar tricks */
- /**
- * \@internal
- * @protected
- * @return {?}
- */
- function () {
- this.isBodyOverflowing = utils.document.body.clientWidth < utils.window.innerWidth;
- this.scrollbarWidth = this.getScrollbarWidth();
- };
- /**
- * @protected
- * @return {?}
- */
- ModalDirective.prototype.setScrollbar = /**
- * @protected
- * @return {?}
- */
- function () {
- if (!utils.document) {
- return;
- }
- this.originalBodyPadding = parseInt(utils.window
- .getComputedStyle(utils.document.body)
- .getPropertyValue('padding-right') || 0, 10);
- if (this.isBodyOverflowing) {
- utils.document.body.style.paddingRight = this.originalBodyPadding +
- this.scrollbarWidth + "px";
- }
- };
- /**
- * @protected
- * @return {?}
- */
- ModalDirective.prototype.resetScrollbar = /**
- * @protected
- * @return {?}
- */
- function () {
- utils.document.body.style.paddingRight = this.originalBodyPadding + "px";
- };
- // thx d.walsh
- // thx d.walsh
- /**
- * @protected
- * @return {?}
- */
- ModalDirective.prototype.getScrollbarWidth =
- // thx d.walsh
- /**
- * @protected
- * @return {?}
- */
- function () {
- /** @type {?} */
- var scrollDiv = this._renderer.createElement('div');
- this._renderer.addClass(scrollDiv, CLASS_NAME.SCROLLBAR_MEASURER);
- this._renderer.appendChild(utils.document.body, scrollDiv);
- /** @type {?} */
- var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
- this._renderer.removeChild(utils.document.body, scrollDiv);
- return scrollbarWidth;
- };
- ModalDirective.decorators = [
- { type: core.Directive, args: [{
- selector: '[bsModal]',
- exportAs: 'bs-modal'
- },] }
- ];
- /** @nocollapse */
- ModalDirective.ctorParameters = function () { return [
- { type: core.ElementRef },
- { type: core.ViewContainerRef },
- { type: core.Renderer2 },
- { type: componentLoader.ComponentLoaderFactory }
- ]; };
- ModalDirective.propDecorators = {
- config: [{ type: core.Input }],
- onShow: [{ type: core.Output }],
- onShown: [{ type: core.Output }],
- onHide: [{ type: core.Output }],
- onHidden: [{ type: core.Output }],
- onClick: [{ type: core.HostListener, args: ['click', ['$event'],] }],
- onEsc: [{ type: core.HostListener, args: ['keydown.esc', ['$event'],] }]
- };
- return ModalDirective;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var BsModalService = /** @class */ (function () {
- function BsModalService(rendererFactory, clf) {
- this.clf = clf;
- // constructor props
- this.config = modalConfigDefaults;
- // tslint:disable-next-line:no-any
- this.onShow = new core.EventEmitter();
- // tslint:disable-next-line:no-any
- this.onShown = new core.EventEmitter();
- // tslint:disable-next-line:no-any
- this.onHide = new core.EventEmitter();
- // tslint:disable-next-line:no-any
- this.onHidden = new core.EventEmitter();
- this.isBodyOverflowing = false;
- this.originalBodyPadding = 0;
- this.scrollbarWidth = 0;
- this.modalsCount = 0;
- this.lastDismissReason = '';
- this.loaders = [];
- this._backdropLoader = this.clf.createLoader(null, null, null);
- this._renderer = rendererFactory.createRenderer(null, null);
- }
- /** Shows a modal */
- // tslint:disable-next-line:no-any
- /**
- * Shows a modal
- * @param {?} content
- * @param {?=} config
- * @return {?}
- */
- // tslint:disable-next-line:no-any
- BsModalService.prototype.show = /**
- * Shows a modal
- * @param {?} content
- * @param {?=} config
- * @return {?}
- */
- // tslint:disable-next-line:no-any
- function (content, config) {
- this.modalsCount++;
- this._createLoaders();
- this.config = Object.assign({}, modalConfigDefaults, config);
- this._showBackdrop();
- this.lastDismissReason = null;
- return this._showModal(content);
- };
- /**
- * @param {?} level
- * @return {?}
- */
- BsModalService.prototype.hide = /**
- * @param {?} level
- * @return {?}
- */
- function (level) {
- var _this = this;
- if (this.modalsCount === 1) {
- this._hideBackdrop();
- this.resetScrollbar();
- }
- this.modalsCount = this.modalsCount >= 1 ? this.modalsCount - 1 : 0;
- setTimeout((/**
- * @return {?}
- */
- function () {
- _this._hideModal(level);
- _this.removeLoaders(level);
- }), this.config.animated ? TRANSITION_DURATIONS.BACKDROP : 0);
- };
- /**
- * @return {?}
- */
- BsModalService.prototype._showBackdrop = /**
- * @return {?}
- */
- function () {
- /** @type {?} */
- var isBackdropEnabled = this.config.backdrop || this.config.backdrop === 'static';
- /** @type {?} */
- var isBackdropInDOM = !this.backdropRef || !this.backdropRef.instance.isShown;
- if (this.modalsCount === 1) {
- this.removeBackdrop();
- if (isBackdropEnabled && isBackdropInDOM) {
- this._backdropLoader
- .attach(ModalBackdropComponent)
- .to('body')
- .show({ isAnimated: this.config.animated });
- this.backdropRef = this._backdropLoader._componentRef;
- }
- }
- };
- /**
- * @return {?}
- */
- BsModalService.prototype._hideBackdrop = /**
- * @return {?}
- */
- function () {
- var _this = this;
- if (!this.backdropRef) {
- return;
- }
- this.backdropRef.instance.isShown = false;
- /** @type {?} */
- var duration = this.config.animated ? TRANSITION_DURATIONS.BACKDROP : 0;
- setTimeout((/**
- * @return {?}
- */
- function () { return _this.removeBackdrop(); }), duration);
- };
- // tslint:disable-next-line:no-any
- // tslint:disable-next-line:no-any
- /**
- * @param {?} content
- * @return {?}
- */
- BsModalService.prototype._showModal =
- // tslint:disable-next-line:no-any
- /**
- * @param {?} content
- * @return {?}
- */
- function (content) {
- /** @type {?} */
- var modalLoader = this.loaders[this.loaders.length - 1];
- /** @type {?} */
- var bsModalRef = new BsModalRef();
- /** @type {?} */
- var modalContainerRef = modalLoader
- .provide({ provide: ModalOptions, useValue: this.config })
- .provide({ provide: BsModalRef, useValue: bsModalRef })
- .attach(ModalContainerComponent)
- .to('body')
- .show({ content: content, isAnimated: this.config.animated, initialState: this.config.initialState, bsModalService: this });
- modalContainerRef.instance.level = this.getModalsCount();
- bsModalRef.hide = (/**
- * @return {?}
- */
- function () {
- modalContainerRef.instance.hide();
- });
- bsModalRef.content = modalLoader.getInnerComponent() || null;
- bsModalRef.setClass = (/**
- * @param {?} newClass
- * @return {?}
- */
- function (newClass) {
- modalContainerRef.instance.config.class = newClass;
- });
- return bsModalRef;
- };
- /**
- * @param {?} level
- * @return {?}
- */
- BsModalService.prototype._hideModal = /**
- * @param {?} level
- * @return {?}
- */
- function (level) {
- /** @type {?} */
- var modalLoader = this.loaders[level - 1];
- if (modalLoader) {
- modalLoader.hide();
- }
- };
- /**
- * @return {?}
- */
- BsModalService.prototype.getModalsCount = /**
- * @return {?}
- */
- function () {
- return this.modalsCount;
- };
- /**
- * @param {?} reason
- * @return {?}
- */
- BsModalService.prototype.setDismissReason = /**
- * @param {?} reason
- * @return {?}
- */
- function (reason) {
- this.lastDismissReason = reason;
- };
- /**
- * @return {?}
- */
- BsModalService.prototype.removeBackdrop = /**
- * @return {?}
- */
- function () {
- this._backdropLoader.hide();
- this.backdropRef = null;
- };
- /** AFTER PR MERGE MODAL.COMPONENT WILL BE USING THIS CODE */
- /** Scroll bar tricks */
- /** @internal */
- /** AFTER PR MERGE MODAL.COMPONENT WILL BE USING THIS CODE */
- /** Scroll bar tricks */
- /**
- * \@internal
- * @return {?}
- */
- BsModalService.prototype.checkScrollbar = /** AFTER PR MERGE MODAL.COMPONENT WILL BE USING THIS CODE */
- /** Scroll bar tricks */
- /**
- * \@internal
- * @return {?}
- */
- function () {
- this.isBodyOverflowing = document.body.clientWidth < window.innerWidth;
- this.scrollbarWidth = this.getScrollbarWidth();
- };
- /**
- * @return {?}
- */
- BsModalService.prototype.setScrollbar = /**
- * @return {?}
- */
- function () {
- if (!document) {
- return;
- }
- this.originalBodyPadding = parseInt(window
- .getComputedStyle(document.body)
- .getPropertyValue('padding-right') || '0', 10);
- if (this.isBodyOverflowing) {
- document.body.style.paddingRight = this.originalBodyPadding +
- this.scrollbarWidth + "px";
- }
- };
- /**
- * @private
- * @return {?}
- */
- BsModalService.prototype.resetScrollbar = /**
- * @private
- * @return {?}
- */
- function () {
- document.body.style.paddingRight = this.originalBodyPadding + "px";
- };
- // thx d.walsh
- // thx d.walsh
- /**
- * @private
- * @return {?}
- */
- BsModalService.prototype.getScrollbarWidth =
- // thx d.walsh
- /**
- * @private
- * @return {?}
- */
- function () {
- /** @type {?} */
- var scrollDiv = this._renderer.createElement('div');
- this._renderer.addClass(scrollDiv, CLASS_NAME.SCROLLBAR_MEASURER);
- this._renderer.appendChild(document.body, scrollDiv);
- /** @type {?} */
- var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
- this._renderer.removeChild(document.body, scrollDiv);
- return scrollbarWidth;
- };
- /**
- * @private
- * @return {?}
- */
- BsModalService.prototype._createLoaders = /**
- * @private
- * @return {?}
- */
- function () {
- /** @type {?} */
- var loader = this.clf.createLoader(null, null, null);
- this.copyEvent(loader.onBeforeShow, this.onShow);
- this.copyEvent(loader.onShown, this.onShown);
- this.copyEvent(loader.onBeforeHide, this.onHide);
- this.copyEvent(loader.onHidden, this.onHidden);
- this.loaders.push(loader);
- };
- /**
- * @private
- * @param {?} level
- * @return {?}
- */
- BsModalService.prototype.removeLoaders = /**
- * @private
- * @param {?} level
- * @return {?}
- */
- function (level) {
- this.loaders.splice(level - 1, 1);
- this.loaders.forEach((/**
- * @param {?} loader
- * @param {?} i
- * @return {?}
- */
- function (loader, i) {
- loader.instance.level = i + 1;
- }));
- };
- // tslint:disable-next-line:no-any
- // tslint:disable-next-line:no-any
- /**
- * @private
- * @param {?} from
- * @param {?} to
- * @return {?}
- */
- BsModalService.prototype.copyEvent =
- // tslint:disable-next-line:no-any
- /**
- * @private
- * @param {?} from
- * @param {?} to
- * @return {?}
- */
- function (from, to) {
- var _this = this;
- from.subscribe((/**
- * @return {?}
- */
- function () {
- to.emit(_this.lastDismissReason);
- }));
- };
- BsModalService.decorators = [
- { type: core.Injectable }
- ];
- /** @nocollapse */
- BsModalService.ctorParameters = function () { return [
- { type: core.RendererFactory2 },
- { type: componentLoader.ComponentLoaderFactory }
- ]; };
- return BsModalService;
- }());
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var ModalModule = /** @class */ (function () {
- function ModalModule() {
- }
- /**
- * @return {?}
- */
- ModalModule.forRoot = /**
- * @return {?}
- */
- function () {
- return {
- ngModule: ModalModule,
- providers: [BsModalService, componentLoader.ComponentLoaderFactory, positioning.PositioningService]
- };
- };
- ModalModule.decorators = [
- { type: core.NgModule, args: [{
- declarations: [
- ModalBackdropComponent,
- ModalDirective,
- ModalContainerComponent
- ],
- exports: [ModalBackdropComponent, ModalDirective],
- entryComponents: [ModalBackdropComponent, ModalContainerComponent]
- },] }
- ];
- return ModalModule;
- }());
- exports.BsModalRef = BsModalRef;
- exports.BsModalService = BsModalService;
- exports.ModalBackdropComponent = ModalBackdropComponent;
- exports.ModalBackdropOptions = ModalBackdropOptions;
- exports.ModalContainerComponent = ModalContainerComponent;
- exports.ModalDirective = ModalDirective;
- exports.ModalModule = ModalModule;
- exports.ModalOptions = ModalOptions;
- exports.ɵa = CLASS_NAME;
- Object.defineProperty(exports, '__esModule', { value: true });
- }));
- //# sourceMappingURL=ngx-bootstrap-modal.umd.js.map
|