/* * AngularJS Toaster * Version: 2.1.0 * * Copyright 2013-2016 Jiri Kavulak. * All Rights Reserved. * Use, reproduction, distribution, and modification of this code is subject to the terms and * conditions of the MIT license, available at http://www.opensource.org/licenses/mit-license.php * * Author: Jiri Kavulak * Related to project of John Papa, Hans Fjällemark and Nguyễn Thiện Hùng (thienhung1989) */ !function(a,b){"use strict";angular.module("toaster",[]).constant("toasterConfig",{limit:0,"tap-to-dismiss":!0,"close-button":!1,"close-html":'',"newest-on-top":!0,"time-out":5e3,"icon-classes":{error:"toast-error",info:"toast-info",wait:"toast-wait",success:"toast-success",warning:"toast-warning"},"body-output-type":"","body-template":"toasterBodyTmpl.html","icon-class":"toast-info","position-class":"toast-top-right","title-class":"toast-title","message-class":"toast-message","prevent-duplicates":!1,"mouseover-timer-stop":!0}).run(["$templateCache",function(a){a.put("angularjs-toaster/toast.html",'
{{toaster.title}}
{{toaster.body}}
')}]).service("toaster",["$rootScope","toasterConfig",function(a,b){function e(a){return function(b,c,d,e,f,g,h,i,j){return angular.isString(b)?this.pop(a,b,c,d,e,f,g,h,i,j):this.pop(angular.extend(b,{type:a}))}}var c=function(){var a={};return a.newGuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0,c="x"==a?b:3&b|8;return c.toString(16)})},a}();this.pop=function(b,d,e,f,g,h,i,j,k,l){if(angular.isObject(b)){var m=b;this.toast={type:m.type,title:m.title,body:m.body,timeout:m.timeout,bodyOutputType:m.bodyOutputType,clickHandler:m.clickHandler,showCloseButton:m.showCloseButton,closeHtml:m.closeHtml,toastId:m.toastId,onShowCallback:m.onShowCallback,onHideCallback:m.onHideCallback,directiveData:m.directiveData,tapToDismiss:m.tapToDismiss},i=m.toasterId}else this.toast={type:b,title:d,body:e,timeout:f,bodyOutputType:g,clickHandler:h,showCloseButton:j,toastId:k,onHideCallback:l};return this.toast.toastId&&this.toast.toastId.length||(this.toast.toastId=c.newGuid()),a.$emit("toaster-newToast",i,this.toast.toastId),{toasterId:i,toastId:this.toast.toastId}},this.clear=function(b,c){angular.isObject(b)?a.$emit("toaster-clearToasts",b.toasterId,b.toastId):a.$emit("toaster-clearToasts",b,c)};for(var d in b["icon-classes"])this[d]=e(d)}]).factory("toasterEventRegistry",["$rootScope",function(a){var f,b=null,c=null,d=[],e=[];return f={setup:function(){b||(b=a.$on("toaster-newToast",function(a,b,c){for(var e=0,f=d.length;e=0&&d.splice(c,1),0===d.length&&(b(),b=null)},unsubscribeToClearToastsEvent:function(a){var b=e.indexOf(a);b>=0&&e.splice(b,1),0===e.length&&(c(),c=null)}},{setup:f.setup,subscribeToNewToastEvent:f.subscribeToNewToastEvent,subscribeToClearToastsEvent:f.subscribeToClearToastsEvent,unsubscribeToNewToastEvent:f.unsubscribeToNewToastEvent,unsubscribeToClearToastsEvent:f.unsubscribeToClearToastsEvent}}]).directive("directiveTemplate",["$compile","$injector",function(a,b){return{restrict:"A",scope:{directiveName:"@directiveName",directiveData:"@directiveData"},replace:!0,link:function(c,d,e){c.$watch("directiveName",function(f){if(angular.isUndefined(f)||f.length<=0)throw new Error("A valid directive name must be provided via the toast body argument when using bodyOutputType: directive");var g;try{g=b.get(e.$normalize(f)+"Directive")}catch(a){throw new Error(f+" could not be found. The name should appear as it exists in the markup, not camelCased as it would appear in the directive declaration, e.g. directive-name not directiveName.")}var h=g[0];if(h.scope!==!0&&h.scope)throw new Error("Cannot use a directive with an isolated scope. The scope must be either true or falsy (e.g. false/null/undefined). Occurred for directive "+f+".");if(h.restrict.indexOf("A")<0)throw new Error('Directives must be usable as attributes. Add "A" to the restrict option (or remove the option entirely). Occurred for directive '+f+".");c.directiveData&&(c.directiveData=angular.fromJson(c.directiveData));var i=a("
")(c);d.append(i)})}}}]).directive("toasterContainer",["$parse","$rootScope","$interval","$sce","toasterConfig","toaster","toasterEventRegistry",function(a,b,c,d,e,f,g){return{replace:!0,restrict:"EA",scope:!0,link:function(b,h,i){function k(a,d){a.timeoutPromise=c(function(){b.removeToast(a.toastId)},d,1)}function l(c,e){if(c.type=j["icon-classes"][c.type],c.type||(c.type=j["icon-class"]),j["prevent-duplicates"]===!0&&b.toasters.length){if(b.toasters[b.toasters.length-1].body===c.body)return;var f,g,h=!1;for(f=0,g=b.toasters.length;f0&&b.toasters.length>j.limit&&b.toasters.pop()):(b.toasters.push(c),j.limit>0&&b.toasters.length>j.limit&&b.toasters.shift()),angular.isFunction(c.onShowCallback)&&c.onShowCallback()}function m(a){var d=b.toasters[a];d.timeoutPromise&&c.cancel(d.timeoutPromise),b.toasters.splice(a,1),angular.isFunction(d.onHideCallback)&&d.onHideCallback()}function n(a){for(var c=b.toasters.length-1;c>=0;c--)o(a)?m(c):b.toasters[c].toastId==a&&m(c)}function o(a){return angular.isUndefined(a)||null===a}var j;j=angular.extend({},e,b.$eval(i.toasterOptions)),b.config={toasterId:j["toaster-id"],position:j["position-class"],title:j["title-class"],message:j["message-class"],tap:j["tap-to-dismiss"],closeButton:j["close-button"],closeHtml:j["close-html"],animation:j["animation-class"],mouseoverTimer:j["mouseover-timer-stop"]},b.$on("$destroy",function(){g.unsubscribeToNewToastEvent(b._onNewToast),g.unsubscribeToClearToastsEvent(b._onClearToasts)}),b.configureTimer=function(a){var b=angular.isNumber(a.timeout)?a.timeout:j["time-out"];"object"==typeof b&&(b=b[a.type]),b>0&&k(a,b)},b.removeToast=function(a){var c,d;for(c=0,d=b.toasters.length;c