-
Notifications
You must be signed in to change notification settings - Fork 3
/
ui-bootstrap-alerts.min.js
1 lines (1 loc) · 2.12 KB
/
ui-bootstrap-alerts.min.js
1
angular.module("ui.bootstrap.alerts",[]).service("AlertService",[function(){this.id=1,this.alerts={},this.titleMap={error:"Error",danger:"Danger",warning:"Warning",success:"Success",info:"Info"},this.alert=function(a){a.id=this.id++,a.title=this.titleMap[a.type],this.alerts[a.context]=this.alerts[a.context]||[];for(var b=0;b<this.alerts[a.context].length;b++)if(this.alerts[a.context][b].message===a.message)return this.alerts[a.context][b];return this.alerts[a.context].push(a),a},this.context=function(a){var b=this;return this.alerts[a]=this.alerts[a]||[],{getAllAlerts:function(){return b.alerts[a]=b.alerts[a]||[],b.alerts[a]},error:function(c){return b.alert({context:a,type:"error",message:c})},danger:function(c){return b.alert({context:a,type:"danger",message:c})},warning:function(c){return b.alert({context:a,type:"warning",message:c})},success:function(c){return b.alert({context:a,type:"success",message:c})},info:function(c){return b.alert({context:a,type:"info",message:c})},remove:function(c){for(var d=0;d<b.alerts[a].length;d++)b.alerts[a][d].id===c.id&&b.alerts[a].splice(d,1);return!1},clear:function(){b.alerts[a]=null}}},angular.extend(this,this.context("general"))}]),angular.module("ui.bootstrap.alerts").controller("AlertCtrl",["$scope","$attrs","AlertService",function(a,b,c){a.alertContext=b.context||"general",a.alertClassFor=function(a){var b=[];switch(a.type){case"warning":break;case"success":b.push("alert-success");break;case"info":b.push("alert-info");break;case"error":b.push("alert-danger");break;case"danger":b.push("alert-danger")}return b.join(" ")},a.remove=function(b){c.context(a.alertContext).remove(b)},a.$watch(function(){return c.context(a.alertContext).getAllAlerts()},function(b){a.alerts=b,a.anyAlerts=a.alerts.length>0},!0)}]),angular.module("ui.bootstrap.alerts").directive("alerts",function(){return{restrict:"E",replace:!0,scope:!0,template:'<div ng-controller="AlertCtrl" ng-show="anyAlerts"><div class="alert" ng-class="alertClassFor(alert)" ng-repeat="alert in alerts"><button class="close" data-dismiss="alert" ng-click="remove(alert)">×</button><strong>{{alert.title}}</strong> {{alert.message}}</div></div>'}});