| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305 |
- import { Injectable, Component, ElementRef, Renderer2, HostListener, Directive, ViewContainerRef, Input, Output, EventEmitter, RendererFactory2, NgModule } from '@angular/core';
- import { isBs3, Utils, document as document$1, window as window$1 } from 'ngx-bootstrap/utils';
- import { ComponentLoaderFactory } from 'ngx-bootstrap/component-loader';
- import { PositioningService } from 'ngx-bootstrap/positioning';
- /**
- * @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: 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: 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, 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, 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: 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: ElementRef },
- { type: Renderer2 }
- ]; };
- ModalContainerComponent.propDecorators = {
- onClick: [{ type: HostListener, args: ['click', ['$event'],] }],
- onEsc: [{ type: 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 (!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.reflow(this.element.nativeElement);
- }
- this.isShown = true;
- };
- ModalBackdropComponent.decorators = [
- { type: Component, args: [{
- selector: 'bs-modal-backdrop',
- template: ' ',
- host: { class: CLASS_NAME.BACKDROP }
- }] }
- ];
- /** @nocollapse */
- ModalBackdropComponent.ctorParameters = function () { return [
- { type: ElementRef },
- { type: 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 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 EventEmitter();
- /**
- * This event is fired immediately when
- * the hide instance method has been called.
- */
- this.onHide = new 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 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 (document$1 && document$1.body) {
- if (document$1.body.classList.contains(CLASS_NAME.OPEN)) {
- this.isNested = true;
- }
- else {
- this._renderer.addClass(document$1.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;
- }
- window$1.clearTimeout(this.timerHideModal);
- window$1.clearTimeout(this.timerRmBackDrop);
- this._isShown = false;
- this._renderer.removeClass(this._element.nativeElement, CLASS_NAME.IN);
- if (!isBs3()) {
- this._renderer.removeClass(this._element.nativeElement, CLASS_NAME.SHOW);
- }
- // this._addClassIn = false;
- if (this._config.animated) {
- this.timerHideModal = window$1.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 (document$1 && document$1.body) {
- document$1.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.reflow(this._element.nativeElement);
- }
- // this._addClassIn = true;
- this._renderer.addClass(this._element.nativeElement, CLASS_NAME.IN);
- if (!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 (document$1 && document$1.body) {
- _this._renderer.removeClass(document$1.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 = window$1.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 = document$1.body.clientWidth < window$1.innerWidth;
- this.scrollbarWidth = this.getScrollbarWidth();
- };
- /**
- * @protected
- * @return {?}
- */
- ModalDirective.prototype.setScrollbar = /**
- * @protected
- * @return {?}
- */
- function () {
- if (!document$1) {
- return;
- }
- this.originalBodyPadding = parseInt(window$1
- .getComputedStyle(document$1.body)
- .getPropertyValue('padding-right') || 0, 10);
- if (this.isBodyOverflowing) {
- document$1.body.style.paddingRight = this.originalBodyPadding +
- this.scrollbarWidth + "px";
- }
- };
- /**
- * @protected
- * @return {?}
- */
- ModalDirective.prototype.resetScrollbar = /**
- * @protected
- * @return {?}
- */
- function () {
- document$1.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(document$1.body, scrollDiv);
- /** @type {?} */
- var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
- this._renderer.removeChild(document$1.body, scrollDiv);
- return scrollbarWidth;
- };
- ModalDirective.decorators = [
- { type: Directive, args: [{
- selector: '[bsModal]',
- exportAs: 'bs-modal'
- },] }
- ];
- /** @nocollapse */
- ModalDirective.ctorParameters = function () { return [
- { type: ElementRef },
- { type: ViewContainerRef },
- { type: Renderer2 },
- { type: ComponentLoaderFactory }
- ]; };
- ModalDirective.propDecorators = {
- config: [{ type: Input }],
- onShow: [{ type: Output }],
- onShown: [{ type: Output }],
- onHide: [{ type: Output }],
- onHidden: [{ type: Output }],
- onClick: [{ type: HostListener, args: ['click', ['$event'],] }],
- onEsc: [{ type: 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 EventEmitter();
- // tslint:disable-next-line:no-any
- this.onShown = new EventEmitter();
- // tslint:disable-next-line:no-any
- this.onHide = new EventEmitter();
- // tslint:disable-next-line:no-any
- this.onHidden = new 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: Injectable }
- ];
- /** @nocollapse */
- BsModalService.ctorParameters = function () { return [
- { type: RendererFactory2 },
- { type: 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, ComponentLoaderFactory, PositioningService]
- };
- };
- ModalModule.decorators = [
- { type: NgModule, args: [{
- declarations: [
- ModalBackdropComponent,
- ModalDirective,
- ModalContainerComponent
- ],
- exports: [ModalBackdropComponent, ModalDirective],
- entryComponents: [ModalBackdropComponent, ModalContainerComponent]
- },] }
- ];
- return ModalModule;
- }());
- export { BsModalRef, BsModalService, ModalBackdropComponent, ModalBackdropOptions, ModalContainerComponent, ModalDirective, ModalModule, ModalOptions, CLASS_NAME as ɵa };
- //# sourceMappingURL=ngx-bootstrap-modal.js.map
|