| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- "use strict";
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
- 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;
- return c > 3 && r && Object.defineProperty(target, key, r), r;
- };
- var __metadata = (this && this.__metadata) || function (k, v) {
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- var core_1 = require("@angular/core");
- var common_1 = require("@angular/common");
- var domhandler_1 = require("../dom/domhandler");
- var shared_1 = require("../common/shared");
- var messageservice_1 = require("../common/messageservice");
- var animations_1 = require("@angular/animations");
- var ToastItem = /** @class */ (function () {
- function ToastItem() {
- this.onClose = new core_1.EventEmitter();
- }
- ToastItem.prototype.ngAfterViewInit = function () {
- this.initTimeout();
- };
- ToastItem.prototype.initTimeout = function () {
- var _this = this;
- if (!this.message.sticky) {
- this.timeout = setTimeout(function () {
- _this.onClose.emit({
- index: _this.index,
- message: _this.message
- });
- }, this.message.life || 3000);
- }
- };
- ToastItem.prototype.clearTimeout = function () {
- if (this.timeout) {
- clearTimeout(this.timeout);
- this.timeout = null;
- }
- };
- ToastItem.prototype.onMouseEnter = function () {
- this.clearTimeout();
- };
- ToastItem.prototype.onMouseLeave = function () {
- this.initTimeout();
- };
- ToastItem.prototype.onCloseIconClick = function (event) {
- this.clearTimeout();
- this.onClose.emit({
- index: this.index,
- message: this.message
- });
- event.preventDefault();
- };
- ToastItem.prototype.ngOnDestroy = function () {
- this.clearTimeout();
- };
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], ToastItem.prototype, "message", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], ToastItem.prototype, "index", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", core_1.TemplateRef)
- ], ToastItem.prototype, "template", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], ToastItem.prototype, "showTransitionOptions", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], ToastItem.prototype, "hideTransitionOptions", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], ToastItem.prototype, "onClose", void 0);
- __decorate([
- core_1.ViewChild('container', { static: false }),
- __metadata("design:type", core_1.ElementRef)
- ], ToastItem.prototype, "containerViewChild", void 0);
- ToastItem = __decorate([
- core_1.Component({
- selector: 'p-toastItem',
- template: "\n <div #container class=\"ui-toast-message ui-shadow\" [@messageState]=\"{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}\"\n [ngClass]=\"{'ui-toast-message-info': message.severity == 'info','ui-toast-message-warn': message.severity == 'warn',\n 'ui-toast-message-error': message.severity == 'error','ui-toast-message-success': message.severity == 'success'}\"\n (mouseenter)=\"onMouseEnter()\" (mouseleave)=\"onMouseLeave()\">\n <div class=\"ui-toast-message-content\">\n <a tabindex=\"0\" class=\"ui-toast-close-icon pi pi-times\" (click)=\"onCloseIconClick($event)\" (keydown.enter)=\"onCloseIconClick($event)\" *ngIf=\"message.closable !== false\"></a>\n <ng-container *ngIf=\"!template\">\n <span class=\"ui-toast-icon pi\"\n [ngClass]=\"{'pi-info-circle': message.severity == 'info', 'pi-exclamation-triangle': message.severity == 'warn',\n 'pi-times': message.severity == 'error', 'pi-check' :message.severity == 'success'}\"></span>\n <div class=\"ui-toast-message-text-content\">\n <div class=\"ui-toast-summary\">{{message.summary}}</div>\n <div class=\"ui-toast-detail\">{{message.detail}}</div>\n </div>\n </ng-container>\n <ng-container *ngTemplateOutlet=\"template; context: {$implicit: message}\"></ng-container>\n </div>\n </div>\n ",
- animations: [
- animations_1.trigger('messageState', [
- animations_1.state('visible', animations_1.style({
- transform: 'translateY(0)',
- opacity: 1
- })),
- animations_1.transition('void => *', [
- animations_1.style({ transform: 'translateY(100%)', opacity: 0 }),
- animations_1.animate('{{showTransitionParams}}')
- ]),
- animations_1.transition('* => void', [
- animations_1.animate(('{{hideTransitionParams}}'), animations_1.style({
- height: 0,
- opacity: 0,
- transform: 'translateY(-100%)'
- }))
- ])
- ])
- ]
- })
- ], ToastItem);
- return ToastItem;
- }());
- exports.ToastItem = ToastItem;
- var Toast = /** @class */ (function () {
- function Toast(messageService) {
- this.messageService = messageService;
- this.autoZIndex = true;
- this.baseZIndex = 0;
- this.position = 'top-right';
- this.showTransitionOptions = '300ms ease-out';
- this.hideTransitionOptions = '250ms ease-in';
- this.onClose = new core_1.EventEmitter();
- }
- Toast.prototype.ngOnInit = function () {
- var _this = this;
- this.messageSubscription = this.messageService.messageObserver.subscribe(function (messages) {
- if (messages) {
- if (messages instanceof Array) {
- var filteredMessages = messages.filter(function (m) { return _this.key === m.key; });
- _this.messages = _this.messages ? _this.messages.concat(filteredMessages) : filteredMessages.slice();
- }
- else if (_this.key === messages.key) {
- _this.messages = _this.messages ? _this.messages.concat([messages]) : [messages];
- }
- if (_this.modal && _this.messages && _this.messages.length) {
- _this.enableModality();
- }
- }
- });
- this.clearSubscription = this.messageService.clearObserver.subscribe(function (key) {
- if (key) {
- if (_this.key === key) {
- _this.messages = null;
- }
- }
- else {
- _this.messages = null;
- }
- if (_this.modal) {
- _this.disableModality();
- }
- });
- };
- Toast.prototype.ngAfterContentInit = function () {
- var _this = this;
- this.templates.forEach(function (item) {
- switch (item.getType()) {
- case 'message':
- _this.template = item.template;
- break;
- default:
- _this.template = item.template;
- break;
- }
- });
- };
- Toast.prototype.onMessageClose = function (event) {
- this.messages.splice(event.index, 1);
- if (this.messages.length === 0) {
- this.disableModality();
- }
- this.onClose.emit({
- message: event.message
- });
- };
- Toast.prototype.enableModality = function () {
- if (!this.mask) {
- this.mask = document.createElement('div');
- this.mask.style.zIndex = String(parseInt(this.containerViewChild.nativeElement.style.zIndex) - 1);
- var maskStyleClass = 'ui-widget-overlay ui-dialog-mask';
- domhandler_1.DomHandler.addMultipleClasses(this.mask, maskStyleClass);
- document.body.appendChild(this.mask);
- }
- };
- Toast.prototype.disableModality = function () {
- if (this.mask) {
- document.body.removeChild(this.mask);
- this.mask = null;
- }
- };
- Toast.prototype.onAnimationStart = function (event) {
- if (event.fromState === 'void' && this.autoZIndex) {
- this.containerViewChild.nativeElement.style.zIndex = String(this.baseZIndex + (++domhandler_1.DomHandler.zindex));
- }
- };
- Toast.prototype.ngOnDestroy = function () {
- if (this.messageSubscription) {
- this.messageSubscription.unsubscribe();
- }
- if (this.clearSubscription) {
- this.clearSubscription.unsubscribe();
- }
- this.disableModality();
- };
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Toast.prototype, "key", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Toast.prototype, "autoZIndex", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Number)
- ], Toast.prototype, "baseZIndex", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Object)
- ], Toast.prototype, "style", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Toast.prototype, "styleClass", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Toast.prototype, "position", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", Boolean)
- ], Toast.prototype, "modal", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Toast.prototype, "showTransitionOptions", void 0);
- __decorate([
- core_1.Input(),
- __metadata("design:type", String)
- ], Toast.prototype, "hideTransitionOptions", void 0);
- __decorate([
- core_1.Output(),
- __metadata("design:type", core_1.EventEmitter)
- ], Toast.prototype, "onClose", void 0);
- __decorate([
- core_1.ViewChild('container', { static: false }),
- __metadata("design:type", core_1.ElementRef)
- ], Toast.prototype, "containerViewChild", void 0);
- __decorate([
- core_1.ContentChildren(shared_1.PrimeTemplate),
- __metadata("design:type", core_1.QueryList)
- ], Toast.prototype, "templates", void 0);
- Toast = __decorate([
- core_1.Component({
- selector: 'p-toast',
- template: "\n <div #container [ngClass]=\"{'ui-toast ui-widget': true, \n 'ui-toast-top-right': position === 'top-right',\n 'ui-toast-top-left': position === 'top-left',\n 'ui-toast-bottom-right': position === 'bottom-right',\n 'ui-toast-bottom-left': position === 'bottom-left',\n 'ui-toast-top-center': position === 'top-center',\n 'ui-toast-bottom-center': position === 'bottom-center',\n 'ui-toast-center': position === 'center'}\" \n [ngStyle]=\"style\" [class]=\"styleClass\">\n <p-toastItem *ngFor=\"let msg of messages; let i=index\" [message]=\"msg\" [index]=\"i\" (onClose)=\"onMessageClose($event)\"\n [template]=\"template\" @toastAnimation (@toastAnimation.start)=\"onAnimationStart($event)\" [showTransitionOptions]=\"showTransitionOptions\" [hideTransitionOptions]=\"hideTransitionOptions\"></p-toastItem>\n </div>\n ",
- animations: [
- animations_1.trigger('toastAnimation', [
- animations_1.transition(':enter, :leave', [
- animations_1.query('@*', animations_1.animateChild())
- ])
- ])
- ]
- }),
- __metadata("design:paramtypes", [messageservice_1.MessageService])
- ], Toast);
- return Toast;
- }());
- exports.Toast = Toast;
- var ToastModule = /** @class */ (function () {
- function ToastModule() {
- }
- ToastModule = __decorate([
- core_1.NgModule({
- imports: [common_1.CommonModule],
- exports: [Toast, shared_1.SharedModule],
- declarations: [Toast, ToastItem]
- })
- ], ToastModule);
- return ToastModule;
- }());
- exports.ToastModule = ToastModule;
- //# sourceMappingURL=toast.js.map
|