UNPKG

angular2-toaster-mod

Version:

An Angular 2 Toaster Notification library based on AngularJS-Toaster

1 lines 15.1 kB
{"version":3,"file":"toaster-container.component.js","sourceRoot":"","sources":["../../src/toaster-container.component.ts"],"names":[],"mappings":"OAAO,EAAC,SAAS,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAC,MAAM,eAAe;OAClE,EAAC,aAAa,EAAC,MAAM,kBAAkB;OACvC,EAAC,cAAc,EAAgB,MAAM,mBAAmB;AAK/D;IAUI,mCAAY,cAA8B,EAAU,GAAuB,EAAU,MAAc;QAA/C,QAAG,GAAH,GAAG,CAAoB;QAAU,WAAM,GAAN,MAAM,CAAQ;QAH5F,WAAM,GAAY,EAAE,CAAC;QAIxB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACzC,CAAC;IAED,4CAAQ,GAAR;QACI,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,KAAK,IAAI,IAAI,OAAO,IAAI,CAAC,aAAa,KAAK,WAAW,CAAC,CAAC,CAAC;YAC3E,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;QAC7C,CAAC;IACL,CAAC;IAED,iBAAiB;IACjB,yCAAK,GAAL,UAAM,KAAY,EAAE,aAAuB;QACvC,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,YAAY,IAAI,CAAC,KAAK,CAAC,eAAe,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC;YAC9E,IAAI,WAAW,GAAG,IAAI,CAAC;YACvB,EAAE,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;gBACrB,EAAE,CAAC,CAAC,OAAO,KAAK,CAAC,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC;oBAC3C,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;gBAC3D,CAAC;gBAAC,IAAI,CAAC,CAAC;oBACJ,OA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EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;YACV,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,OAAO,KAAK,OAAO,EAArB,CAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxE,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,IAAI,CAAC,eAAe,EAAE,CAAC;QAC3B,CAAC;IACL,CAAC;IAED,+CAAW,GAAX;QACI,EAAE,CAAA,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;YAAC,IAAI,CAAC,kBAAkB,CAAC,WAAW,EAAE,CAAC;QAAC,CAAC;QACtE,EAAE,CAAA,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC;YAAC,IAAI,CAAC,qBAAqB,CAAC,WAAW,EAAE,CAAC;QAAC,CAAC;IAChF,CAAC;IACE,oCAAU,GAA0B;QAC3C,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;oBACtB,QAAQ,EAAE,mBAAmB;oBAC7B,QAAQ,EAAE,okBASL,CAAA,GAAG;iBAIX,EAAG,EAAE;KACL,CAAC;IACF,kBAAkB;IACX,wCAAc,GAAmE,cAAM,OAAA;QAC9F,EAAC,IAAI,EAAE,cAAc,GAAG;QACxB,EAAC,IAAI,EAAE,iBAAiB,GAAG;QAC3B,EAAC,IAAI,EAAE,MAAM,GAAG;KACf,EAJ6F,CAI7F,CAAC;IACK,wCAAc,GAA2C;QAChE,eAAe,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;KAClC,CAAC;IACF,gCAAC;AAAD,CAAC,AAtND,IAsNC","sourcesContent":["import {Component, Input, ChangeDetectorRef, NgZone} from '@angular/core';\nimport {ToasterConfig} from './toaster-config';\nimport {ToasterService, IClearWrapper} from './toaster.service';\nimport {Toast} from './toast';\n\n\n\nexport class ToasterContainerComponent {\n private addToastSubscriber: any;\n private clearToastsSubscriber: any;\n private toasterService: ToasterService;\n \n toasterconfig: ToasterConfig;\n\n public toasts: Toast[] = [];\n\n\n constructor(toasterService: ToasterService, private ref : ChangeDetectorRef, private ngZone: NgZone) {\n this.toasterService = toasterService;\n }\n\n ngOnInit() {\n this.registerSubscribers();\n if (this.toasterconfig === null || typeof this.toasterconfig === 'undefined') {\n this.toasterconfig = new ToasterConfig();\n }\n }\n\n // event handlers\n click(toast: Toast, isCloseButton?: boolean) {\n if (this.toasterconfig.tapToDismiss || (toast.showCloseButton && isCloseButton)) {\n var removeToast = true;\n if (toast.clickHandler) {\n if (typeof toast.clickHandler === \"function\") {\n removeToast = toast.clickHandler(toast, isCloseButton);\n } else {\n console.log(\"The toast click handler is not a callable function.\");\n return false;\n }\n }\n\n if (removeToast) {\n this.removeToast(toast);\n }\n }\n }\n \n childClick($event: any) {\n this.click($event.value.toast, $event.value.isCloseButton);\n }\n\n stopTimer(toast: Toast) {\n if (this.toasterconfig.mouseoverTimerStop) {\n if (toast.timeoutId) {\n window.clearTimeout(toast.timeoutId);\n toast.timeoutId = null;\n }\n }\n }\n\n restartTimer(toast: Toast) {\n if (this.toasterconfig.mouseoverTimerStop) {\n if (!toast.timeoutId) {\n this.configureTimer(toast);\n }\n } else if (toast.timeoutId === null) {\n this.removeToast(toast);\n }\n }\n\n\n // private functions\n private registerSubscribers() {\n this.addToastSubscriber = this.toasterService.addToast.subscribe((toast: Toast) => {\n this.addToast(toast);\n });\n\n this.clearToastsSubscriber = this.toasterService.clearToasts.subscribe((clearWrapper: IClearWrapper) => {\n this.clearToasts(clearWrapper);\n });\n }\n\n private addToast(toast: Toast) {\n toast.toasterConfig = this.toasterconfig;\n\n if (toast.toastContainerId && this.toasterconfig.toastContainerId\n && toast.toastContainerId !== this.toasterconfig.toastContainerId) return;\n\n if (!toast.type) {\n toast.type = this.toasterconfig.defaultTypeClass;\n }\n\n if (this.toasterconfig.preventDuplicates && this.toasts.length > 0) {\n if (toast.toastId && this.toasts.some(t => t.toastId === toast.toastId)) {\n return;\n } else if (this.toasts.some(t => t.body === toast.body)) {\n return;\n }\n }\n\n if (toast.showCloseButton === null || typeof toast.showCloseButton === \"undefined\") {\n if (typeof this.toasterconfig.showCloseButton === \"object\") {\n toast.showCloseButton = this.toasterconfig.showCloseButton[toast.type];\n } else if (typeof this.toasterconfig.showCloseButton === \"boolean\") {\n toast.showCloseButton = <boolean>this.toasterconfig.showCloseButton;\n }\n }\n\n if (toast.showCloseButton) {\n toast.closeHtml = toast.closeHtml || this.toasterconfig.closeHtml;\n }\n\n toast.bodyOutputType = toast.bodyOutputType || this.toasterconfig.bodyOutputType;\n\n this.configureTimer(toast);\n\n if (this.toasterconfig.newestOnTop) {\n this.ngZone.run(() => {\n this.toasts.unshift(toast);\n });\n if (this.isLimitExceeded()) {\n this.toasts.pop();\n }\n } else {\n this.toasts.push(toast);\n if (this.isLimitExceeded()) {\n this.toasts.shift();\n }\n }\n\n if (toast.onShowCallback) {\n toast.onShowCallback(toast);\n }\n }\n\n private configureTimer(toast: Toast) {\n var timeout = (typeof toast.timeout === \"number\") \n ? toast.timeout : this.toasterconfig.timeout;\n\n if (typeof timeout === \"object\") timeout = timeout[toast.type];\n if (timeout > 0) {\n toast.timeoutId = window.setTimeout(() => {\n this.ref.markForCheck();\n this.removeToast(toast);\n }, timeout);\n }\n }\n\n private isLimitExceeded() {\n return this.toasterconfig.limit && this.toasts.length > this.toasterconfig.limit;\n }\n\n private removeToast(toast: Toast) {\n var index = this.toasts.indexOf(toast);\n if (index < 0) return;\n\n this.toasts.splice(index, 1);\n if (toast.timeoutId) {\n window.clearTimeout(toast.timeoutId);\n toast.timeoutId = null;\n }\n if (toast.onHideCallback) toast.onHideCallback(toast);\n this.toasterService._removeToastSubject.next({ toastId: toast.toastId, toastContainerId: toast.toastContainerId });\n }\n\n private removeAllToasts() {\n for (var i = this.toasts.length - 1; i >= 0; i--) {\n this.removeToast(this.toasts[i]);\n }\n }\n\n private clearToasts(clearWrapper: IClearWrapper) {\n let toastId = clearWrapper.toastId;\n let toastContainerId = clearWrapper.toastContainerId;\n\n if (toastContainerId === null || typeof toastContainerId === 'undefined') {\n this.clearToastsAction(toastId);\n } else if (toastContainerId === this.toasterconfig.toastContainerId) {\n this.clearToastsAction(toastId);\n }\n }\n\n private clearToastsAction(toastId?: string) {\n if (toastId) {\n this.removeToast(this.toasts.filter(t => t.toastId === toastId)[0]);\n } else {\n this.removeAllToasts();\n }\n }\n\n ngOnDestroy() {\n if(this.addToastSubscriber) { this.addToastSubscriber.unsubscribe(); }\n if(this.clearToastsSubscriber) { this.clearToastsSubscriber.unsubscribe(); }\n }\nstatic decorators: DecoratorInvocation[] = [\n{ type: Component, args: [{\n selector: 'toaster-container',\n template: `\n <div id=\"toast-container\" [ngClass]=\"[toasterconfig.positionClass, toasterconfig.animationClass]\" class=\"ng-animate\">\n <div toastComp *ngFor=\"let toast of toasts\" class=\"toast\" [toast]=\"toast\"\n [iconClass]=\"toasterconfig.iconClasses[toast.type]\" \n [ngClass]=\"toasterconfig.typeClasses[toast.type]\"\n (click)=\"click(toast)\" (clickEvent)=\"childClick($event)\" \n (mouseover)=\"stopTimer(toast)\" (mouseout)=\"restartTimer(toast)\">\n </div>\n </div>\n `//,\n // TODO: use styleUrls once Angular 2 supports the use of relative paths\n // https://github.com/angular/angular/issues/2383\n //styleUrls: ['./toaster.css']\n}, ] },\n];\n/** @nocollapse */\nstatic ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n{type: ToasterService, },\n{type: ChangeDetectorRef, },\n{type: NgZone, },\n];\nstatic propDecorators: {[key: string]: DecoratorInvocation[]} = {\n'toasterconfig': [{ type: Input },],\n};\n}\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n"]}