dynamicdialog.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. var animations_1 = require("@angular/animations");
  14. var dynamicdialogcontent_1 = require("./dynamicdialogcontent");
  15. var dynamicdialog_config_1 = require("./dynamicdialog-config");
  16. var common_1 = require("@angular/common");
  17. var domhandler_1 = require("../dom/domhandler");
  18. var dynamicdialog_ref_1 = require("./dynamicdialog-ref");
  19. var DynamicDialogComponent = /** @class */ (function () {
  20. function DynamicDialogComponent(componentFactoryResolver, cd, renderer, config, dialogRef, zone) {
  21. this.componentFactoryResolver = componentFactoryResolver;
  22. this.cd = cd;
  23. this.renderer = renderer;
  24. this.config = config;
  25. this.dialogRef = dialogRef;
  26. this.zone = zone;
  27. this.visible = true;
  28. }
  29. DynamicDialogComponent.prototype.ngAfterViewInit = function () {
  30. this.loadChildComponent(this.childComponentType);
  31. this.cd.detectChanges();
  32. };
  33. DynamicDialogComponent.prototype.onOverlayClicked = function (evt) {
  34. this.dialogRef.close();
  35. };
  36. DynamicDialogComponent.prototype.onDialogClicked = function (evt) {
  37. evt.stopPropagation();
  38. };
  39. DynamicDialogComponent.prototype.loadChildComponent = function (componentType) {
  40. var componentFactory = this.componentFactoryResolver.resolveComponentFactory(componentType);
  41. var viewContainerRef = this.insertionPoint.viewContainerRef;
  42. viewContainerRef.clear();
  43. this.componentRef = viewContainerRef.createComponent(componentFactory);
  44. };
  45. DynamicDialogComponent.prototype.moveOnTop = function () {
  46. if (this.config.autoZIndex !== false) {
  47. var zIndex = this.config.baseZIndex || 0 + (++domhandler_1.DomHandler.zindex);
  48. this.container.style.zIndex = String(zIndex);
  49. this.maskViewChild.nativeElement.style.zIndex = String(zIndex - 1);
  50. }
  51. };
  52. DynamicDialogComponent.prototype.onAnimationStart = function (event) {
  53. switch (event.toState) {
  54. case 'visible':
  55. this.container = event.element;
  56. this.moveOnTop();
  57. this.bindGlobalListeners();
  58. domhandler_1.DomHandler.addClass(document.body, 'ui-overflow-hidden');
  59. break;
  60. case 'void':
  61. this.onContainerDestroy();
  62. break;
  63. }
  64. };
  65. DynamicDialogComponent.prototype.onAnimationEnd = function (event) {
  66. if (event.toState === 'void') {
  67. this.dialogRef.close();
  68. }
  69. };
  70. DynamicDialogComponent.prototype.onContainerDestroy = function () {
  71. domhandler_1.DomHandler.removeClass(document.body, 'ui-overflow-hidden');
  72. this.unbindGlobalListeners();
  73. this.container = null;
  74. };
  75. DynamicDialogComponent.prototype.close = function () {
  76. this.visible = false;
  77. };
  78. DynamicDialogComponent.prototype.onMaskClick = function () {
  79. if (this.config.dismissableMask) {
  80. this.close();
  81. }
  82. };
  83. DynamicDialogComponent.prototype.bindGlobalListeners = function () {
  84. if (this.config.closeOnEscape !== false && this.config.closable !== false) {
  85. this.bindDocumentEscapeListener();
  86. }
  87. };
  88. DynamicDialogComponent.prototype.unbindGlobalListeners = function () {
  89. this.unbindDocumentEscapeListener();
  90. };
  91. DynamicDialogComponent.prototype.bindDocumentEscapeListener = function () {
  92. var _this = this;
  93. this.documentEscapeListener = this.renderer.listen('document', 'keydown', function (event) {
  94. if (event.which == 27) {
  95. if (parseInt(_this.container.style.zIndex) == domhandler_1.DomHandler.zindex) {
  96. _this.close();
  97. }
  98. }
  99. });
  100. };
  101. DynamicDialogComponent.prototype.unbindDocumentEscapeListener = function () {
  102. if (this.documentEscapeListener) {
  103. this.documentEscapeListener();
  104. this.documentEscapeListener = null;
  105. }
  106. };
  107. DynamicDialogComponent.prototype.ngOnDestroy = function () {
  108. this.onContainerDestroy();
  109. if (this.componentRef) {
  110. this.componentRef.destroy();
  111. }
  112. };
  113. __decorate([
  114. core_1.ViewChild(dynamicdialogcontent_1.DynamicDialogContent, { static: false }),
  115. __metadata("design:type", dynamicdialogcontent_1.DynamicDialogContent)
  116. ], DynamicDialogComponent.prototype, "insertionPoint", void 0);
  117. __decorate([
  118. core_1.ViewChild('mask', { static: false }),
  119. __metadata("design:type", core_1.ElementRef)
  120. ], DynamicDialogComponent.prototype, "maskViewChild", void 0);
  121. DynamicDialogComponent = __decorate([
  122. core_1.Component({
  123. selector: 'p-dynamicDialog',
  124. template: "\n\t\t<div #mask class=\"ui-widget-overlay ui-dialog-mask ui-dialog-mask-scrollblocker\" *ngIf=\"visible\" (click)=\"onMaskClick()\"></div>\n\t\t<div [ngClass]=\"{'ui-dialog ui-dynamicdialog ui-widget ui-widget-content ui-corner-all ui-shadow':true, 'ui-dialog-rtl': config.rtl}\" [ngStyle]=\"config.style\" [class]=\"config.styleClass\"\n\t\t\t[@animation]=\"{value: 'visible', params: {transitionParams: config.transitionOptions || '150ms cubic-bezier(0, 0, 0.2, 1)'}}\" \n\t\t\t(@animation.start)=\"onAnimationStart($event)\" (@animation.done)=\"onAnimationEnd($event)\" role=\"dialog\" *ngIf=\"visible\"\n\t\t\t[style.width]=\"config.width\" [style.height]=\"config.height\">\n <div class=\"ui-dialog-titlebar ui-widget-header ui-helper-clearfix ui-corner-top\" *ngIf=\"config.showHeader === false ? false: true\">\n <span class=\"ui-dialog-title\">{{config.header}}</span>\n <a [ngClass]=\"'ui-dialog-titlebar-icon ui-dialog-titlebar-close ui-corner-all'\" tabindex=\"0\" role=\"button\" (click)=\"close()\" (keydown.enter)=\"close()\" *ngIf=\"config.closable === false ? false : true\">\n <span class=\"pi pi-times\"></span>\n </a>\n </div>\n <div class=\"ui-dialog-content ui-widget-content\" [ngStyle]=\"config.contentStyle\">\n\t\t\t\t<ng-template pDynamicDialogContent></ng-template>\n\t\t\t</div>\n\t\t\t<div class=\"ui-dialog-footer ui-widget-content\" *ngIf=\"config.footer\">\n\t\t\t\t{{config.footer}}\n </div>\n\t\t</div>\n\t",
  125. animations: [
  126. animations_1.trigger('animation', [
  127. animations_1.state('void', animations_1.style({
  128. transform: 'translateX(-50%) translateY(-50%) scale(0.7)',
  129. opacity: 0
  130. })),
  131. animations_1.state('visible', animations_1.style({
  132. transform: 'translateX(-50%) translateY(-50%) scale(1)',
  133. opacity: 1
  134. })),
  135. animations_1.transition('* => *', animations_1.animate('{{transitionParams}}'))
  136. ])
  137. ]
  138. }),
  139. __metadata("design:paramtypes", [core_1.ComponentFactoryResolver, core_1.ChangeDetectorRef, core_1.Renderer2,
  140. dynamicdialog_config_1.DynamicDialogConfig, dynamicdialog_ref_1.DynamicDialogRef, core_1.NgZone])
  141. ], DynamicDialogComponent);
  142. return DynamicDialogComponent;
  143. }());
  144. exports.DynamicDialogComponent = DynamicDialogComponent;
  145. var DynamicDialogModule = /** @class */ (function () {
  146. function DynamicDialogModule() {
  147. }
  148. DynamicDialogModule = __decorate([
  149. core_1.NgModule({
  150. imports: [common_1.CommonModule],
  151. declarations: [DynamicDialogComponent, dynamicdialogcontent_1.DynamicDialogContent],
  152. entryComponents: [DynamicDialogComponent]
  153. })
  154. ], DynamicDialogModule);
  155. return DynamicDialogModule;
  156. }());
  157. exports.DynamicDialogModule = DynamicDialogModule;
  158. //# sourceMappingURL=dynamicdialog.js.map