ngx-bootstrap-modal.umd.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('ngx-bootstrap/utils'), require('ngx-bootstrap/component-loader'), require('ngx-bootstrap/positioning')) :
  3. typeof define === 'function' && define.amd ? define('ngx-bootstrap/modal', ['exports', '@angular/core', 'ngx-bootstrap/utils', 'ngx-bootstrap/component-loader', 'ngx-bootstrap/positioning'], factory) :
  4. (global = global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].modal = {}), global.ng.core, global.utils, global.componentLoader, global.positioning));
  5. }(this, function (exports, core, utils, componentLoader, positioning) { 'use strict';
  6. /**
  7. * @fileoverview added by tsickle
  8. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  9. */
  10. var BsModalRef = /** @class */ (function () {
  11. function BsModalRef() {
  12. /**
  13. * Hides the modal
  14. */
  15. this.hide = Function;
  16. /**
  17. * Sets new class to modal window
  18. */
  19. this.setClass = Function;
  20. }
  21. BsModalRef.decorators = [
  22. { type: core.Injectable }
  23. ];
  24. return BsModalRef;
  25. }());
  26. /**
  27. * @fileoverview added by tsickle
  28. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  29. */
  30. var ModalBackdropOptions = /** @class */ (function () {
  31. function ModalBackdropOptions(options) {
  32. this.animate = true;
  33. Object.assign(this, options);
  34. }
  35. return ModalBackdropOptions;
  36. }());
  37. /**
  38. * @fileoverview added by tsickle
  39. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  40. */
  41. var ModalOptions = /** @class */ (function () {
  42. function ModalOptions() {
  43. }
  44. ModalOptions.decorators = [
  45. { type: core.Injectable }
  46. ];
  47. return ModalOptions;
  48. }());
  49. /** @type {?} */
  50. var modalConfigDefaults = {
  51. backdrop: true,
  52. keyboard: true,
  53. focus: true,
  54. show: false,
  55. ignoreBackdropClick: false,
  56. class: '',
  57. animated: true,
  58. initialState: {}
  59. };
  60. /** @type {?} */
  61. var CLASS_NAME = {
  62. SCROLLBAR_MEASURER: 'modal-scrollbar-measure',
  63. BACKDROP: 'modal-backdrop',
  64. OPEN: 'modal-open',
  65. FADE: 'fade',
  66. IN: 'in',
  67. // bs3
  68. SHOW: 'show' // bs4
  69. };
  70. /** @type {?} */
  71. var TRANSITION_DURATIONS = {
  72. MODAL: 300,
  73. BACKDROP: 150
  74. };
  75. /** @type {?} */
  76. var DISMISS_REASONS = {
  77. BACKRDOP: 'backdrop-click',
  78. ESC: 'esc'
  79. };
  80. /**
  81. * @fileoverview added by tsickle
  82. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  83. */
  84. var ModalContainerComponent = /** @class */ (function () {
  85. function ModalContainerComponent(options, _element, _renderer) {
  86. this._element = _element;
  87. this._renderer = _renderer;
  88. this.isShown = false;
  89. this.isModalHiding = false;
  90. this.config = Object.assign({}, options);
  91. }
  92. /**
  93. * @return {?}
  94. */
  95. ModalContainerComponent.prototype.ngOnInit = /**
  96. * @return {?}
  97. */
  98. function () {
  99. var _this = this;
  100. if (this.isAnimated) {
  101. this._renderer.addClass(this._element.nativeElement, CLASS_NAME.FADE);
  102. }
  103. this._renderer.setStyle(this._element.nativeElement, 'display', 'block');
  104. setTimeout((/**
  105. * @return {?}
  106. */
  107. function () {
  108. _this.isShown = true;
  109. _this._renderer.addClass(_this._element.nativeElement, utils.isBs3() ? CLASS_NAME.IN : CLASS_NAME.SHOW);
  110. }), this.isAnimated ? TRANSITION_DURATIONS.BACKDROP : 0);
  111. if (document && document.body) {
  112. if (this.bsModalService.getModalsCount() === 1) {
  113. this.bsModalService.checkScrollbar();
  114. this.bsModalService.setScrollbar();
  115. }
  116. this._renderer.addClass(document.body, CLASS_NAME.OPEN);
  117. }
  118. if (this._element.nativeElement) {
  119. this._element.nativeElement.focus();
  120. }
  121. };
  122. /**
  123. * @param {?} event
  124. * @return {?}
  125. */
  126. ModalContainerComponent.prototype.onClick = /**
  127. * @param {?} event
  128. * @return {?}
  129. */
  130. function (event) {
  131. if (this.config.ignoreBackdropClick ||
  132. this.config.backdrop === 'static' ||
  133. event.target !== this._element.nativeElement) {
  134. return;
  135. }
  136. this.bsModalService.setDismissReason(DISMISS_REASONS.BACKRDOP);
  137. this.hide();
  138. };
  139. /**
  140. * @param {?} event
  141. * @return {?}
  142. */
  143. ModalContainerComponent.prototype.onEsc = /**
  144. * @param {?} event
  145. * @return {?}
  146. */
  147. function (event) {
  148. if (!this.isShown) {
  149. return;
  150. }
  151. // tslint:disable-next-line:deprecation
  152. if (event.keyCode === 27 || event.key === 'Escape') {
  153. event.preventDefault();
  154. }
  155. if (this.config.keyboard &&
  156. this.level === this.bsModalService.getModalsCount()) {
  157. this.bsModalService.setDismissReason(DISMISS_REASONS.ESC);
  158. this.hide();
  159. }
  160. };
  161. /**
  162. * @return {?}
  163. */
  164. ModalContainerComponent.prototype.ngOnDestroy = /**
  165. * @return {?}
  166. */
  167. function () {
  168. if (this.isShown) {
  169. this.hide();
  170. }
  171. };
  172. /**
  173. * @return {?}
  174. */
  175. ModalContainerComponent.prototype.hide = /**
  176. * @return {?}
  177. */
  178. function () {
  179. var _this = this;
  180. if (this.isModalHiding || !this.isShown) {
  181. return;
  182. }
  183. this.isModalHiding = true;
  184. this._renderer.removeClass(this._element.nativeElement, utils.isBs3() ? CLASS_NAME.IN : CLASS_NAME.SHOW);
  185. setTimeout((/**
  186. * @return {?}
  187. */
  188. function () {
  189. _this.isShown = false;
  190. if (document &&
  191. document.body &&
  192. _this.bsModalService.getModalsCount() === 1) {
  193. _this._renderer.removeClass(document.body, CLASS_NAME.OPEN);
  194. }
  195. _this.bsModalService.hide(_this.level);
  196. _this.isModalHiding = false;
  197. }), this.isAnimated ? TRANSITION_DURATIONS.MODAL : 0);
  198. };
  199. ModalContainerComponent.decorators = [
  200. { type: core.Component, args: [{
  201. selector: 'modal-container',
  202. 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 ",
  203. host: {
  204. class: 'modal',
  205. role: 'dialog',
  206. tabindex: '-1',
  207. '[attr.aria-modal]': 'true'
  208. }
  209. }] }
  210. ];
  211. /** @nocollapse */
  212. ModalContainerComponent.ctorParameters = function () { return [
  213. { type: ModalOptions },
  214. { type: core.ElementRef },
  215. { type: core.Renderer2 }
  216. ]; };
  217. ModalContainerComponent.propDecorators = {
  218. onClick: [{ type: core.HostListener, args: ['click', ['$event'],] }],
  219. onEsc: [{ type: core.HostListener, args: ['window:keydown.esc', ['$event'],] }]
  220. };
  221. return ModalContainerComponent;
  222. }());
  223. /**
  224. * @fileoverview added by tsickle
  225. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  226. */
  227. /**
  228. * This component will be added as background layout for modals if enabled
  229. */
  230. var ModalBackdropComponent = /** @class */ (function () {
  231. function ModalBackdropComponent(element, renderer) {
  232. this._isShown = false;
  233. this.element = element;
  234. this.renderer = renderer;
  235. }
  236. Object.defineProperty(ModalBackdropComponent.prototype, "isAnimated", {
  237. get: /**
  238. * @return {?}
  239. */
  240. function () {
  241. return this._isAnimated;
  242. },
  243. set: /**
  244. * @param {?} value
  245. * @return {?}
  246. */
  247. function (value) {
  248. this._isAnimated = value;
  249. // this.renderer.setElementClass(this.element.nativeElement, `${ClassName.FADE}`, value);
  250. },
  251. enumerable: true,
  252. configurable: true
  253. });
  254. Object.defineProperty(ModalBackdropComponent.prototype, "isShown", {
  255. get: /**
  256. * @return {?}
  257. */
  258. function () {
  259. return this._isShown;
  260. },
  261. set: /**
  262. * @param {?} value
  263. * @return {?}
  264. */
  265. function (value) {
  266. this._isShown = value;
  267. if (value) {
  268. this.renderer.addClass(this.element.nativeElement, "" + CLASS_NAME.IN);
  269. }
  270. else {
  271. this.renderer.removeClass(this.element.nativeElement, "" + CLASS_NAME.IN);
  272. }
  273. if (!utils.isBs3()) {
  274. if (value) {
  275. this.renderer.addClass(this.element.nativeElement, "" + CLASS_NAME.SHOW);
  276. }
  277. else {
  278. this.renderer.removeClass(this.element.nativeElement, "" + CLASS_NAME.SHOW);
  279. }
  280. }
  281. },
  282. enumerable: true,
  283. configurable: true
  284. });
  285. /**
  286. * @return {?}
  287. */
  288. ModalBackdropComponent.prototype.ngOnInit = /**
  289. * @return {?}
  290. */
  291. function () {
  292. if (this.isAnimated) {
  293. this.renderer.addClass(this.element.nativeElement, "" + CLASS_NAME.FADE);
  294. utils.Utils.reflow(this.element.nativeElement);
  295. }
  296. this.isShown = true;
  297. };
  298. ModalBackdropComponent.decorators = [
  299. { type: core.Component, args: [{
  300. selector: 'bs-modal-backdrop',
  301. template: ' ',
  302. host: { class: CLASS_NAME.BACKDROP }
  303. }] }
  304. ];
  305. /** @nocollapse */
  306. ModalBackdropComponent.ctorParameters = function () { return [
  307. { type: core.ElementRef },
  308. { type: core.Renderer2 }
  309. ]; };
  310. return ModalBackdropComponent;
  311. }());
  312. /**
  313. * @fileoverview added by tsickle
  314. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  315. */
  316. /** @type {?} */
  317. var TRANSITION_DURATION = 300;
  318. /** @type {?} */
  319. var BACKDROP_TRANSITION_DURATION = 150;
  320. /**
  321. * Mark any code with directive to show it's content in modal
  322. */
  323. var ModalDirective = /** @class */ (function () {
  324. function ModalDirective(_element, _viewContainerRef, _renderer, clf) {
  325. this._element = _element;
  326. this._renderer = _renderer;
  327. /**
  328. * This event fires immediately when the `show` instance method is called.
  329. */
  330. this.onShow = new core.EventEmitter();
  331. /**
  332. * This event is fired when the modal has been made visible to the user
  333. * (will wait for CSS transitions to complete)
  334. */
  335. this.onShown = new core.EventEmitter();
  336. /**
  337. * This event is fired immediately when
  338. * the hide instance method has been called.
  339. */
  340. this.onHide = new core.EventEmitter();
  341. /**
  342. * This event is fired when the modal has finished being
  343. * hidden from the user (will wait for CSS transitions to complete).
  344. */
  345. this.onHidden = new core.EventEmitter();
  346. this._isShown = false;
  347. this.isBodyOverflowing = false;
  348. this.originalBodyPadding = 0;
  349. this.scrollbarWidth = 0;
  350. this.timerHideModal = 0;
  351. this.timerRmBackDrop = 0;
  352. this.isNested = false;
  353. this._backdrop = clf.createLoader(_element, _viewContainerRef, _renderer);
  354. }
  355. Object.defineProperty(ModalDirective.prototype, "config", {
  356. get: /**
  357. * @return {?}
  358. */
  359. function () {
  360. return this._config;
  361. },
  362. /** allows to set modal configuration via element property */
  363. set: /**
  364. * allows to set modal configuration via element property
  365. * @param {?} conf
  366. * @return {?}
  367. */
  368. function (conf) {
  369. this._config = this.getConfig(conf);
  370. },
  371. enumerable: true,
  372. configurable: true
  373. });
  374. Object.defineProperty(ModalDirective.prototype, "isShown", {
  375. get: /**
  376. * @return {?}
  377. */
  378. function () {
  379. return this._isShown;
  380. },
  381. enumerable: true,
  382. configurable: true
  383. });
  384. /**
  385. * @param {?} event
  386. * @return {?}
  387. */
  388. ModalDirective.prototype.onClick = /**
  389. * @param {?} event
  390. * @return {?}
  391. */
  392. function (event) {
  393. if (this.config.ignoreBackdropClick ||
  394. this.config.backdrop === 'static' ||
  395. event.target !== this._element.nativeElement) {
  396. return;
  397. }
  398. this.dismissReason = DISMISS_REASONS.BACKRDOP;
  399. this.hide(event);
  400. };
  401. // todo: consider preventing default and stopping propagation
  402. // todo: consider preventing default and stopping propagation
  403. /**
  404. * @param {?} event
  405. * @return {?}
  406. */
  407. ModalDirective.prototype.onEsc =
  408. // todo: consider preventing default and stopping propagation
  409. /**
  410. * @param {?} event
  411. * @return {?}
  412. */
  413. function (event) {
  414. if (!this._isShown) {
  415. return;
  416. }
  417. // tslint:disable-next-line:deprecation
  418. if (event.keyCode === 27 || event.key === 'Escape') {
  419. event.preventDefault();
  420. }
  421. if (this.config.keyboard) {
  422. this.dismissReason = DISMISS_REASONS.ESC;
  423. this.hide();
  424. }
  425. };
  426. /**
  427. * @return {?}
  428. */
  429. ModalDirective.prototype.ngOnDestroy = /**
  430. * @return {?}
  431. */
  432. function () {
  433. this.config = void 0;
  434. if (this._isShown) {
  435. this._isShown = false;
  436. this.hideModal();
  437. this._backdrop.dispose();
  438. }
  439. };
  440. /**
  441. * @return {?}
  442. */
  443. ModalDirective.prototype.ngOnInit = /**
  444. * @return {?}
  445. */
  446. function () {
  447. var _this = this;
  448. this._config = this._config || this.getConfig();
  449. setTimeout((/**
  450. * @return {?}
  451. */
  452. function () {
  453. if (_this._config.show) {
  454. _this.show();
  455. }
  456. }), 0);
  457. };
  458. /* Public methods */
  459. /** Allows to manually toggle modal visibility */
  460. /* Public methods */
  461. /**
  462. * Allows to manually toggle modal visibility
  463. * @return {?}
  464. */
  465. ModalDirective.prototype.toggle = /* Public methods */
  466. /**
  467. * Allows to manually toggle modal visibility
  468. * @return {?}
  469. */
  470. function () {
  471. return this._isShown ? this.hide() : this.show();
  472. };
  473. /** Allows to manually open modal */
  474. /**
  475. * Allows to manually open modal
  476. * @return {?}
  477. */
  478. ModalDirective.prototype.show = /**
  479. * Allows to manually open modal
  480. * @return {?}
  481. */
  482. function () {
  483. var _this = this;
  484. this.dismissReason = null;
  485. this.onShow.emit(this);
  486. if (this._isShown) {
  487. return;
  488. }
  489. clearTimeout(this.timerHideModal);
  490. clearTimeout(this.timerRmBackDrop);
  491. this._isShown = true;
  492. this.checkScrollbar();
  493. this.setScrollbar();
  494. if (utils.document && utils.document.body) {
  495. if (utils.document.body.classList.contains(CLASS_NAME.OPEN)) {
  496. this.isNested = true;
  497. }
  498. else {
  499. this._renderer.addClass(utils.document.body, CLASS_NAME.OPEN);
  500. }
  501. }
  502. this.showBackdrop((/**
  503. * @return {?}
  504. */
  505. function () {
  506. _this.showElement();
  507. }));
  508. };
  509. /** Allows to manually close modal */
  510. /**
  511. * Allows to manually close modal
  512. * @param {?=} event
  513. * @return {?}
  514. */
  515. ModalDirective.prototype.hide = /**
  516. * Allows to manually close modal
  517. * @param {?=} event
  518. * @return {?}
  519. */
  520. function (event) {
  521. var _this = this;
  522. if (event) {
  523. event.preventDefault();
  524. }
  525. this.onHide.emit(this);
  526. // todo: add an option to prevent hiding
  527. if (!this._isShown) {
  528. return;
  529. }
  530. utils.window.clearTimeout(this.timerHideModal);
  531. utils.window.clearTimeout(this.timerRmBackDrop);
  532. this._isShown = false;
  533. this._renderer.removeClass(this._element.nativeElement, CLASS_NAME.IN);
  534. if (!utils.isBs3()) {
  535. this._renderer.removeClass(this._element.nativeElement, CLASS_NAME.SHOW);
  536. }
  537. // this._addClassIn = false;
  538. if (this._config.animated) {
  539. this.timerHideModal = utils.window.setTimeout((/**
  540. * @return {?}
  541. */
  542. function () { return _this.hideModal(); }), TRANSITION_DURATION);
  543. }
  544. else {
  545. this.hideModal();
  546. }
  547. };
  548. /** Private methods @internal */
  549. /**
  550. * Private methods \@internal
  551. * @protected
  552. * @param {?=} config
  553. * @return {?}
  554. */
  555. ModalDirective.prototype.getConfig = /**
  556. * Private methods \@internal
  557. * @protected
  558. * @param {?=} config
  559. * @return {?}
  560. */
  561. function (config) {
  562. return Object.assign({}, modalConfigDefaults, config);
  563. };
  564. /**
  565. * Show dialog
  566. * @internal
  567. */
  568. /**
  569. * Show dialog
  570. * \@internal
  571. * @protected
  572. * @return {?}
  573. */
  574. ModalDirective.prototype.showElement = /**
  575. * Show dialog
  576. * \@internal
  577. * @protected
  578. * @return {?}
  579. */
  580. function () {
  581. var _this = this;
  582. // todo: replace this with component loader usage
  583. if (!this._element.nativeElement.parentNode ||
  584. this._element.nativeElement.parentNode.nodeType !== Node.ELEMENT_NODE) {
  585. // don't move modals dom position
  586. if (utils.document && utils.document.body) {
  587. utils.document.body.appendChild(this._element.nativeElement);
  588. }
  589. }
  590. this._renderer.setAttribute(this._element.nativeElement, 'aria-hidden', 'false');
  591. this._renderer.setAttribute(this._element.nativeElement, 'aria-modal', 'true');
  592. this._renderer.setStyle(this._element.nativeElement, 'display', 'block');
  593. this._renderer.setProperty(this._element.nativeElement, 'scrollTop', 0);
  594. if (this._config.animated) {
  595. utils.Utils.reflow(this._element.nativeElement);
  596. }
  597. // this._addClassIn = true;
  598. this._renderer.addClass(this._element.nativeElement, CLASS_NAME.IN);
  599. if (!utils.isBs3()) {
  600. this._renderer.addClass(this._element.nativeElement, CLASS_NAME.SHOW);
  601. }
  602. /** @type {?} */
  603. var transitionComplete = (/**
  604. * @return {?}
  605. */
  606. function () {
  607. if (_this._config.focus) {
  608. _this._element.nativeElement.focus();
  609. }
  610. _this.onShown.emit(_this);
  611. });
  612. if (this._config.animated) {
  613. setTimeout(transitionComplete, TRANSITION_DURATION);
  614. }
  615. else {
  616. transitionComplete();
  617. }
  618. };
  619. /** @internal */
  620. /**
  621. * \@internal
  622. * @protected
  623. * @return {?}
  624. */
  625. ModalDirective.prototype.hideModal = /**
  626. * \@internal
  627. * @protected
  628. * @return {?}
  629. */
  630. function () {
  631. var _this = this;
  632. this._renderer.setAttribute(this._element.nativeElement, 'aria-hidden', 'true');
  633. this._renderer.setStyle(this._element.nativeElement, 'display', 'none');
  634. this.showBackdrop((/**
  635. * @return {?}
  636. */
  637. function () {
  638. if (!_this.isNested) {
  639. if (utils.document && utils.document.body) {
  640. _this._renderer.removeClass(utils.document.body, CLASS_NAME.OPEN);
  641. }
  642. _this.resetScrollbar();
  643. }
  644. _this.resetAdjustments();
  645. _this.focusOtherModal();
  646. _this.onHidden.emit(_this);
  647. }));
  648. };
  649. // todo: original show was calling a callback when done, but we can use
  650. // promise
  651. /** @internal */
  652. // todo: original show was calling a callback when done, but we can use
  653. // promise
  654. /**
  655. * \@internal
  656. * @protected
  657. * @param {?=} callback
  658. * @return {?}
  659. */
  660. ModalDirective.prototype.showBackdrop =
  661. // todo: original show was calling a callback when done, but we can use
  662. // promise
  663. /**
  664. * \@internal
  665. * @protected
  666. * @param {?=} callback
  667. * @return {?}
  668. */
  669. function (callback) {
  670. var _this = this;
  671. if (this._isShown &&
  672. this.config.backdrop &&
  673. (!this.backdrop || !this.backdrop.instance.isShown)) {
  674. this.removeBackdrop();
  675. this._backdrop
  676. .attach(ModalBackdropComponent)
  677. .to('body')
  678. .show({ isAnimated: this._config.animated });
  679. this.backdrop = this._backdrop._componentRef;
  680. if (!callback) {
  681. return;
  682. }
  683. if (!this._config.animated) {
  684. callback();
  685. return;
  686. }
  687. setTimeout(callback, BACKDROP_TRANSITION_DURATION);
  688. }
  689. else if (!this._isShown && this.backdrop) {
  690. this.backdrop.instance.isShown = false;
  691. /** @type {?} */
  692. var callbackRemove = (/**
  693. * @return {?}
  694. */
  695. function () {
  696. _this.removeBackdrop();
  697. if (callback) {
  698. callback();
  699. }
  700. });
  701. if (this.backdrop.instance.isAnimated) {
  702. this.timerRmBackDrop = utils.window.setTimeout(callbackRemove, BACKDROP_TRANSITION_DURATION);
  703. }
  704. else {
  705. callbackRemove();
  706. }
  707. }
  708. else if (callback) {
  709. callback();
  710. }
  711. };
  712. /** @internal */
  713. /**
  714. * \@internal
  715. * @protected
  716. * @return {?}
  717. */
  718. ModalDirective.prototype.removeBackdrop = /**
  719. * \@internal
  720. * @protected
  721. * @return {?}
  722. */
  723. function () {
  724. this._backdrop.hide();
  725. };
  726. /** Events tricks */
  727. // no need for it
  728. // protected setEscapeEvent():void {
  729. // if (this._isShown && this._config.keyboard) {
  730. // $(this._element).on(Event.KEYDOWN_DISMISS, (event) => {
  731. // if (event.which === 27) {
  732. // this.hide()
  733. // }
  734. // })
  735. //
  736. // } else if (!this._isShown) {
  737. // $(this._element).off(Event.KEYDOWN_DISMISS)
  738. // }
  739. // }
  740. // protected setResizeEvent():void {
  741. // console.log(this.renderer.listenGlobal('', Event.RESIZE));
  742. // if (this._isShown) {
  743. // $(window).on(Event.RESIZE, $.proxy(this._handleUpdate, this))
  744. // } else {
  745. // $(window).off(Event.RESIZE)
  746. // }
  747. // }
  748. /**
  749. * Events tricks
  750. * @protected
  751. * @return {?}
  752. */
  753. // no need for it
  754. // protected setEscapeEvent():void {
  755. // if (this._isShown && this._config.keyboard) {
  756. // $(this._element).on(Event.KEYDOWN_DISMISS, (event) => {
  757. // if (event.which === 27) {
  758. // this.hide()
  759. // }
  760. // })
  761. //
  762. // } else if (!this._isShown) {
  763. // $(this._element).off(Event.KEYDOWN_DISMISS)
  764. // }
  765. // }
  766. // protected setResizeEvent():void {
  767. // console.log(this.renderer.listenGlobal('', Event.RESIZE));
  768. // if (this._isShown) {
  769. // $(window).on(Event.RESIZE, $.proxy(this._handleUpdate, this))
  770. // } else {
  771. // $(window).off(Event.RESIZE)
  772. // }
  773. // }
  774. ModalDirective.prototype.focusOtherModal = /**
  775. * Events tricks
  776. * @protected
  777. * @return {?}
  778. */
  779. // no need for it
  780. // protected setEscapeEvent():void {
  781. // if (this._isShown && this._config.keyboard) {
  782. // $(this._element).on(Event.KEYDOWN_DISMISS, (event) => {
  783. // if (event.which === 27) {
  784. // this.hide()
  785. // }
  786. // })
  787. //
  788. // } else if (!this._isShown) {
  789. // $(this._element).off(Event.KEYDOWN_DISMISS)
  790. // }
  791. // }
  792. // protected setResizeEvent():void {
  793. // console.log(this.renderer.listenGlobal('', Event.RESIZE));
  794. // if (this._isShown) {
  795. // $(window).on(Event.RESIZE, $.proxy(this._handleUpdate, this))
  796. // } else {
  797. // $(window).off(Event.RESIZE)
  798. // }
  799. // }
  800. function () {
  801. if (this._element.nativeElement.parentElement == null) {
  802. return;
  803. }
  804. /** @type {?} */
  805. var otherOpenedModals = this._element.nativeElement.parentElement.querySelectorAll('.in[bsModal]');
  806. if (!otherOpenedModals.length) {
  807. return;
  808. }
  809. otherOpenedModals[otherOpenedModals.length - 1].focus();
  810. };
  811. /** @internal */
  812. /**
  813. * \@internal
  814. * @protected
  815. * @return {?}
  816. */
  817. ModalDirective.prototype.resetAdjustments = /**
  818. * \@internal
  819. * @protected
  820. * @return {?}
  821. */
  822. function () {
  823. this._renderer.setStyle(this._element.nativeElement, 'paddingLeft', '');
  824. this._renderer.setStyle(this._element.nativeElement, 'paddingRight', '');
  825. };
  826. /** Scroll bar tricks */
  827. /** @internal */
  828. /** Scroll bar tricks */
  829. /**
  830. * \@internal
  831. * @protected
  832. * @return {?}
  833. */
  834. ModalDirective.prototype.checkScrollbar = /** Scroll bar tricks */
  835. /**
  836. * \@internal
  837. * @protected
  838. * @return {?}
  839. */
  840. function () {
  841. this.isBodyOverflowing = utils.document.body.clientWidth < utils.window.innerWidth;
  842. this.scrollbarWidth = this.getScrollbarWidth();
  843. };
  844. /**
  845. * @protected
  846. * @return {?}
  847. */
  848. ModalDirective.prototype.setScrollbar = /**
  849. * @protected
  850. * @return {?}
  851. */
  852. function () {
  853. if (!utils.document) {
  854. return;
  855. }
  856. this.originalBodyPadding = parseInt(utils.window
  857. .getComputedStyle(utils.document.body)
  858. .getPropertyValue('padding-right') || 0, 10);
  859. if (this.isBodyOverflowing) {
  860. utils.document.body.style.paddingRight = this.originalBodyPadding +
  861. this.scrollbarWidth + "px";
  862. }
  863. };
  864. /**
  865. * @protected
  866. * @return {?}
  867. */
  868. ModalDirective.prototype.resetScrollbar = /**
  869. * @protected
  870. * @return {?}
  871. */
  872. function () {
  873. utils.document.body.style.paddingRight = this.originalBodyPadding + "px";
  874. };
  875. // thx d.walsh
  876. // thx d.walsh
  877. /**
  878. * @protected
  879. * @return {?}
  880. */
  881. ModalDirective.prototype.getScrollbarWidth =
  882. // thx d.walsh
  883. /**
  884. * @protected
  885. * @return {?}
  886. */
  887. function () {
  888. /** @type {?} */
  889. var scrollDiv = this._renderer.createElement('div');
  890. this._renderer.addClass(scrollDiv, CLASS_NAME.SCROLLBAR_MEASURER);
  891. this._renderer.appendChild(utils.document.body, scrollDiv);
  892. /** @type {?} */
  893. var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
  894. this._renderer.removeChild(utils.document.body, scrollDiv);
  895. return scrollbarWidth;
  896. };
  897. ModalDirective.decorators = [
  898. { type: core.Directive, args: [{
  899. selector: '[bsModal]',
  900. exportAs: 'bs-modal'
  901. },] }
  902. ];
  903. /** @nocollapse */
  904. ModalDirective.ctorParameters = function () { return [
  905. { type: core.ElementRef },
  906. { type: core.ViewContainerRef },
  907. { type: core.Renderer2 },
  908. { type: componentLoader.ComponentLoaderFactory }
  909. ]; };
  910. ModalDirective.propDecorators = {
  911. config: [{ type: core.Input }],
  912. onShow: [{ type: core.Output }],
  913. onShown: [{ type: core.Output }],
  914. onHide: [{ type: core.Output }],
  915. onHidden: [{ type: core.Output }],
  916. onClick: [{ type: core.HostListener, args: ['click', ['$event'],] }],
  917. onEsc: [{ type: core.HostListener, args: ['keydown.esc', ['$event'],] }]
  918. };
  919. return ModalDirective;
  920. }());
  921. /**
  922. * @fileoverview added by tsickle
  923. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  924. */
  925. var BsModalService = /** @class */ (function () {
  926. function BsModalService(rendererFactory, clf) {
  927. this.clf = clf;
  928. // constructor props
  929. this.config = modalConfigDefaults;
  930. // tslint:disable-next-line:no-any
  931. this.onShow = new core.EventEmitter();
  932. // tslint:disable-next-line:no-any
  933. this.onShown = new core.EventEmitter();
  934. // tslint:disable-next-line:no-any
  935. this.onHide = new core.EventEmitter();
  936. // tslint:disable-next-line:no-any
  937. this.onHidden = new core.EventEmitter();
  938. this.isBodyOverflowing = false;
  939. this.originalBodyPadding = 0;
  940. this.scrollbarWidth = 0;
  941. this.modalsCount = 0;
  942. this.lastDismissReason = '';
  943. this.loaders = [];
  944. this._backdropLoader = this.clf.createLoader(null, null, null);
  945. this._renderer = rendererFactory.createRenderer(null, null);
  946. }
  947. /** Shows a modal */
  948. // tslint:disable-next-line:no-any
  949. /**
  950. * Shows a modal
  951. * @param {?} content
  952. * @param {?=} config
  953. * @return {?}
  954. */
  955. // tslint:disable-next-line:no-any
  956. BsModalService.prototype.show = /**
  957. * Shows a modal
  958. * @param {?} content
  959. * @param {?=} config
  960. * @return {?}
  961. */
  962. // tslint:disable-next-line:no-any
  963. function (content, config) {
  964. this.modalsCount++;
  965. this._createLoaders();
  966. this.config = Object.assign({}, modalConfigDefaults, config);
  967. this._showBackdrop();
  968. this.lastDismissReason = null;
  969. return this._showModal(content);
  970. };
  971. /**
  972. * @param {?} level
  973. * @return {?}
  974. */
  975. BsModalService.prototype.hide = /**
  976. * @param {?} level
  977. * @return {?}
  978. */
  979. function (level) {
  980. var _this = this;
  981. if (this.modalsCount === 1) {
  982. this._hideBackdrop();
  983. this.resetScrollbar();
  984. }
  985. this.modalsCount = this.modalsCount >= 1 ? this.modalsCount - 1 : 0;
  986. setTimeout((/**
  987. * @return {?}
  988. */
  989. function () {
  990. _this._hideModal(level);
  991. _this.removeLoaders(level);
  992. }), this.config.animated ? TRANSITION_DURATIONS.BACKDROP : 0);
  993. };
  994. /**
  995. * @return {?}
  996. */
  997. BsModalService.prototype._showBackdrop = /**
  998. * @return {?}
  999. */
  1000. function () {
  1001. /** @type {?} */
  1002. var isBackdropEnabled = this.config.backdrop || this.config.backdrop === 'static';
  1003. /** @type {?} */
  1004. var isBackdropInDOM = !this.backdropRef || !this.backdropRef.instance.isShown;
  1005. if (this.modalsCount === 1) {
  1006. this.removeBackdrop();
  1007. if (isBackdropEnabled && isBackdropInDOM) {
  1008. this._backdropLoader
  1009. .attach(ModalBackdropComponent)
  1010. .to('body')
  1011. .show({ isAnimated: this.config.animated });
  1012. this.backdropRef = this._backdropLoader._componentRef;
  1013. }
  1014. }
  1015. };
  1016. /**
  1017. * @return {?}
  1018. */
  1019. BsModalService.prototype._hideBackdrop = /**
  1020. * @return {?}
  1021. */
  1022. function () {
  1023. var _this = this;
  1024. if (!this.backdropRef) {
  1025. return;
  1026. }
  1027. this.backdropRef.instance.isShown = false;
  1028. /** @type {?} */
  1029. var duration = this.config.animated ? TRANSITION_DURATIONS.BACKDROP : 0;
  1030. setTimeout((/**
  1031. * @return {?}
  1032. */
  1033. function () { return _this.removeBackdrop(); }), duration);
  1034. };
  1035. // tslint:disable-next-line:no-any
  1036. // tslint:disable-next-line:no-any
  1037. /**
  1038. * @param {?} content
  1039. * @return {?}
  1040. */
  1041. BsModalService.prototype._showModal =
  1042. // tslint:disable-next-line:no-any
  1043. /**
  1044. * @param {?} content
  1045. * @return {?}
  1046. */
  1047. function (content) {
  1048. /** @type {?} */
  1049. var modalLoader = this.loaders[this.loaders.length - 1];
  1050. /** @type {?} */
  1051. var bsModalRef = new BsModalRef();
  1052. /** @type {?} */
  1053. var modalContainerRef = modalLoader
  1054. .provide({ provide: ModalOptions, useValue: this.config })
  1055. .provide({ provide: BsModalRef, useValue: bsModalRef })
  1056. .attach(ModalContainerComponent)
  1057. .to('body')
  1058. .show({ content: content, isAnimated: this.config.animated, initialState: this.config.initialState, bsModalService: this });
  1059. modalContainerRef.instance.level = this.getModalsCount();
  1060. bsModalRef.hide = (/**
  1061. * @return {?}
  1062. */
  1063. function () {
  1064. modalContainerRef.instance.hide();
  1065. });
  1066. bsModalRef.content = modalLoader.getInnerComponent() || null;
  1067. bsModalRef.setClass = (/**
  1068. * @param {?} newClass
  1069. * @return {?}
  1070. */
  1071. function (newClass) {
  1072. modalContainerRef.instance.config.class = newClass;
  1073. });
  1074. return bsModalRef;
  1075. };
  1076. /**
  1077. * @param {?} level
  1078. * @return {?}
  1079. */
  1080. BsModalService.prototype._hideModal = /**
  1081. * @param {?} level
  1082. * @return {?}
  1083. */
  1084. function (level) {
  1085. /** @type {?} */
  1086. var modalLoader = this.loaders[level - 1];
  1087. if (modalLoader) {
  1088. modalLoader.hide();
  1089. }
  1090. };
  1091. /**
  1092. * @return {?}
  1093. */
  1094. BsModalService.prototype.getModalsCount = /**
  1095. * @return {?}
  1096. */
  1097. function () {
  1098. return this.modalsCount;
  1099. };
  1100. /**
  1101. * @param {?} reason
  1102. * @return {?}
  1103. */
  1104. BsModalService.prototype.setDismissReason = /**
  1105. * @param {?} reason
  1106. * @return {?}
  1107. */
  1108. function (reason) {
  1109. this.lastDismissReason = reason;
  1110. };
  1111. /**
  1112. * @return {?}
  1113. */
  1114. BsModalService.prototype.removeBackdrop = /**
  1115. * @return {?}
  1116. */
  1117. function () {
  1118. this._backdropLoader.hide();
  1119. this.backdropRef = null;
  1120. };
  1121. /** AFTER PR MERGE MODAL.COMPONENT WILL BE USING THIS CODE */
  1122. /** Scroll bar tricks */
  1123. /** @internal */
  1124. /** AFTER PR MERGE MODAL.COMPONENT WILL BE USING THIS CODE */
  1125. /** Scroll bar tricks */
  1126. /**
  1127. * \@internal
  1128. * @return {?}
  1129. */
  1130. BsModalService.prototype.checkScrollbar = /** AFTER PR MERGE MODAL.COMPONENT WILL BE USING THIS CODE */
  1131. /** Scroll bar tricks */
  1132. /**
  1133. * \@internal
  1134. * @return {?}
  1135. */
  1136. function () {
  1137. this.isBodyOverflowing = document.body.clientWidth < window.innerWidth;
  1138. this.scrollbarWidth = this.getScrollbarWidth();
  1139. };
  1140. /**
  1141. * @return {?}
  1142. */
  1143. BsModalService.prototype.setScrollbar = /**
  1144. * @return {?}
  1145. */
  1146. function () {
  1147. if (!document) {
  1148. return;
  1149. }
  1150. this.originalBodyPadding = parseInt(window
  1151. .getComputedStyle(document.body)
  1152. .getPropertyValue('padding-right') || '0', 10);
  1153. if (this.isBodyOverflowing) {
  1154. document.body.style.paddingRight = this.originalBodyPadding +
  1155. this.scrollbarWidth + "px";
  1156. }
  1157. };
  1158. /**
  1159. * @private
  1160. * @return {?}
  1161. */
  1162. BsModalService.prototype.resetScrollbar = /**
  1163. * @private
  1164. * @return {?}
  1165. */
  1166. function () {
  1167. document.body.style.paddingRight = this.originalBodyPadding + "px";
  1168. };
  1169. // thx d.walsh
  1170. // thx d.walsh
  1171. /**
  1172. * @private
  1173. * @return {?}
  1174. */
  1175. BsModalService.prototype.getScrollbarWidth =
  1176. // thx d.walsh
  1177. /**
  1178. * @private
  1179. * @return {?}
  1180. */
  1181. function () {
  1182. /** @type {?} */
  1183. var scrollDiv = this._renderer.createElement('div');
  1184. this._renderer.addClass(scrollDiv, CLASS_NAME.SCROLLBAR_MEASURER);
  1185. this._renderer.appendChild(document.body, scrollDiv);
  1186. /** @type {?} */
  1187. var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
  1188. this._renderer.removeChild(document.body, scrollDiv);
  1189. return scrollbarWidth;
  1190. };
  1191. /**
  1192. * @private
  1193. * @return {?}
  1194. */
  1195. BsModalService.prototype._createLoaders = /**
  1196. * @private
  1197. * @return {?}
  1198. */
  1199. function () {
  1200. /** @type {?} */
  1201. var loader = this.clf.createLoader(null, null, null);
  1202. this.copyEvent(loader.onBeforeShow, this.onShow);
  1203. this.copyEvent(loader.onShown, this.onShown);
  1204. this.copyEvent(loader.onBeforeHide, this.onHide);
  1205. this.copyEvent(loader.onHidden, this.onHidden);
  1206. this.loaders.push(loader);
  1207. };
  1208. /**
  1209. * @private
  1210. * @param {?} level
  1211. * @return {?}
  1212. */
  1213. BsModalService.prototype.removeLoaders = /**
  1214. * @private
  1215. * @param {?} level
  1216. * @return {?}
  1217. */
  1218. function (level) {
  1219. this.loaders.splice(level - 1, 1);
  1220. this.loaders.forEach((/**
  1221. * @param {?} loader
  1222. * @param {?} i
  1223. * @return {?}
  1224. */
  1225. function (loader, i) {
  1226. loader.instance.level = i + 1;
  1227. }));
  1228. };
  1229. // tslint:disable-next-line:no-any
  1230. // tslint:disable-next-line:no-any
  1231. /**
  1232. * @private
  1233. * @param {?} from
  1234. * @param {?} to
  1235. * @return {?}
  1236. */
  1237. BsModalService.prototype.copyEvent =
  1238. // tslint:disable-next-line:no-any
  1239. /**
  1240. * @private
  1241. * @param {?} from
  1242. * @param {?} to
  1243. * @return {?}
  1244. */
  1245. function (from, to) {
  1246. var _this = this;
  1247. from.subscribe((/**
  1248. * @return {?}
  1249. */
  1250. function () {
  1251. to.emit(_this.lastDismissReason);
  1252. }));
  1253. };
  1254. BsModalService.decorators = [
  1255. { type: core.Injectable }
  1256. ];
  1257. /** @nocollapse */
  1258. BsModalService.ctorParameters = function () { return [
  1259. { type: core.RendererFactory2 },
  1260. { type: componentLoader.ComponentLoaderFactory }
  1261. ]; };
  1262. return BsModalService;
  1263. }());
  1264. /**
  1265. * @fileoverview added by tsickle
  1266. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1267. */
  1268. var ModalModule = /** @class */ (function () {
  1269. function ModalModule() {
  1270. }
  1271. /**
  1272. * @return {?}
  1273. */
  1274. ModalModule.forRoot = /**
  1275. * @return {?}
  1276. */
  1277. function () {
  1278. return {
  1279. ngModule: ModalModule,
  1280. providers: [BsModalService, componentLoader.ComponentLoaderFactory, positioning.PositioningService]
  1281. };
  1282. };
  1283. ModalModule.decorators = [
  1284. { type: core.NgModule, args: [{
  1285. declarations: [
  1286. ModalBackdropComponent,
  1287. ModalDirective,
  1288. ModalContainerComponent
  1289. ],
  1290. exports: [ModalBackdropComponent, ModalDirective],
  1291. entryComponents: [ModalBackdropComponent, ModalContainerComponent]
  1292. },] }
  1293. ];
  1294. return ModalModule;
  1295. }());
  1296. exports.BsModalRef = BsModalRef;
  1297. exports.BsModalService = BsModalService;
  1298. exports.ModalBackdropComponent = ModalBackdropComponent;
  1299. exports.ModalBackdropOptions = ModalBackdropOptions;
  1300. exports.ModalContainerComponent = ModalContainerComponent;
  1301. exports.ModalDirective = ModalDirective;
  1302. exports.ModalModule = ModalModule;
  1303. exports.ModalOptions = ModalOptions;
  1304. exports.ɵa = CLASS_NAME;
  1305. Object.defineProperty(exports, '__esModule', { value: true });
  1306. }));
  1307. //# sourceMappingURL=ngx-bootstrap-modal.umd.js.map