diff --git a/build/angular-growl.js b/build/angular-growl.js index e461296..89f8719 100644 --- a/build/angular-growl.js +++ b/build/angular-growl.js @@ -1,7 +1,7 @@ /** - * angular-growl - v0.4.0 - 2013-11-19 + * angular-growl - v0.4.0 - 2014-11-19 * https://github.com/marcorinck/angular-growl - * Copyright (c) 2013 Marco Rinck; Licensed MIT + * Copyright (c) 2014 Marco Rinck; Licensed MIT */ angular.module('angular-growl', []); angular.module('angular-growl').directive('growl', [ @@ -89,20 +89,19 @@ angular.module('angular-growl').provider('growl', function () { 'growl', function ($q, growl) { function checkResponse(response) { - if (response.data[_messagesKey] && response.data[_messagesKey].length > 0) { + if (response.data && response.data[_messagesKey] && response.data[_messagesKey].length > 0) { growl.addServerMessages(response.data[_messagesKey]); } } - function success(response) { - checkResponse(response); - return response; - } - function error(response) { - checkResponse(response); - return $q.reject(response); - } - return function (promise) { - return promise.then(success, error); + return { + response: function (response) { + checkResponse(response); + return response; + }, + responseError: function (response) { + checkResponse(response); + return $q.reject(response); + } }; } ]; diff --git a/build/angular-growl.min.css b/build/angular-growl.min.css index e1ed842..832d8fd 100644 --- a/build/angular-growl.min.css +++ b/build/angular-growl.min.css @@ -1,7 +1,7 @@ /** - * angular-growl - v0.4.0 - 2013-11-19 + * angular-growl - v0.4.0 - 2014-11-19 * https://github.com/marcorinck/angular-growl - * Copyright (c) 2013 Marco Rinck; Licensed MIT + * Copyright (c) 2014 Marco Rinck; Licensed MIT */ .growl{position:fixed;top:10px;right:10px;float:right;width:250px}.growl-item.ng-enter,.growl-item.ng-leave{-webkit-transition:.5s linear all;-moz-transition:.5s linear all;-o-transition:.5s linear all;transition:.5s linear all}.growl-item.ng-enter,.growl-item.ng-leave.ng-leave-active{opacity:0}.growl-item.ng-leave,.growl-item.ng-enter.ng-enter-active{opacity:1} \ No newline at end of file diff --git a/build/angular-growl.min.js b/build/angular-growl.min.js index 83798c5..a604d0f 100644 --- a/build/angular-growl.min.js +++ b/build/angular-growl.min.js @@ -1,6 +1,6 @@ /** - * angular-growl - v0.4.0 - 2013-11-19 + * angular-growl - v0.4.0 - 2014-11-19 * https://github.com/marcorinck/angular-growl - * Copyright (c) 2013 Marco Rinck; Licensed MIT + * Copyright (c) 2014 Marco Rinck; Licensed MIT */ -angular.module("angular-growl",[]),angular.module("angular-growl").directive("growl",["$rootScope",function(a){"use strict";return{restrict:"A",template:'
',replace:!1,scope:!0,controller:["$scope","$timeout","growl",function(b,c,d){function e(a){b.messages.push(a),a.ttl&&-1!==a.ttl&&c(function(){b.deleteMessage(a)},a.ttl)}var f=d.onlyUnique();b.messages=[],a.$on("growlMessage",function(a,c){var d;f?(angular.forEach(b.messages,function(a){c.text===a.text&&c.severity===a.severity&&(d=!0)}),d||e(c)):e(c)}),b.deleteMessage=function(a){var c=b.messages.indexOf(a);c>-1&&b.messages.splice(c,1)},b.computeClasses=function(a){return{"alert-success":"success"===a.severity,"alert-error":"error"===a.severity,"alert-danger":"error"===a.severity,"alert-info":"info"===a.severity,"alert-warning":"warn"===a.severity}}}]}}]),angular.module("angular-growl").provider("growl",function(){"use strict";var a=null,b=!1,c="messages",d="text",e="severity",f=!0;this.globalTimeToLive=function(b){a=b},this.globalEnableHtml=function(a){b=a},this.messagesKey=function(a){c=a},this.messageTextKey=function(a){d=a},this.messageSeverityKey=function(a){e=a},this.onlyUniqueMessages=function(a){f=a},this.serverMessagesInterceptor=["$q","growl",function(a,b){function d(a){a.data[c]&&a.data[c].length>0&&b.addServerMessages(a.data[c])}function e(a){return d(a),a}function f(b){return d(b),a.reject(b)}return function(a){return a.then(e,f)}}],this.$get=["$rootScope","$filter",function(c,g){function h(a){p&&(a.text=p(a.text)),c.$broadcast("growlMessage",a)}function i(c,d,e){var f,g=d||{};f={text:c,severity:e,ttl:g.ttl||a,enableHtml:g.enableHtml||b},h(f)}function j(a,b){i(a,b,"warn")}function k(a,b){i(a,b,"error")}function l(a,b){i(a,b,"info")}function m(a,b){i(a,b,"success")}function n(a){var b,c,f,g;for(g=a.length,b=0;g>b;b++)if(c=a[b],c[d]&&c[e]){switch(c[e]){case"warn":f="warn";break;case"success":f="success";break;case"info":f="info";break;case"error":f="error"}i(c[d],void 0,f)}}function o(){return f}var p;try{p=g("translate")}catch(q){}return{addWarnMessage:j,addErrorMessage:k,addInfoMessage:l,addSuccessMessage:m,addServerMessages:n,onlyUnique:o}}]}); \ No newline at end of file +angular.module("angular-growl",[]),angular.module("angular-growl").directive("growl",["$rootScope",function(a){"use strict";return{restrict:"A",template:'
',replace:!1,scope:!0,controller:["$scope","$timeout","growl",function(b,c,d){function e(a){b.messages.push(a),a.ttl&&-1!==a.ttl&&c(function(){b.deleteMessage(a)},a.ttl)}var f=d.onlyUnique();b.messages=[],a.$on("growlMessage",function(a,c){var d;f?(angular.forEach(b.messages,function(a){c.text===a.text&&c.severity===a.severity&&(d=!0)}),d||e(c)):e(c)}),b.deleteMessage=function(a){var c=b.messages.indexOf(a);c>-1&&b.messages.splice(c,1)},b.computeClasses=function(a){return{"alert-success":"success"===a.severity,"alert-error":"error"===a.severity,"alert-danger":"error"===a.severity,"alert-info":"info"===a.severity,"alert-warning":"warn"===a.severity}}}]}}]),angular.module("angular-growl").provider("growl",function(){"use strict";var a=null,b=!1,c="messages",d="text",e="severity",f=!0;this.globalTimeToLive=function(b){a=b},this.globalEnableHtml=function(a){b=a},this.messagesKey=function(a){c=a},this.messageTextKey=function(a){d=a},this.messageSeverityKey=function(a){e=a},this.onlyUniqueMessages=function(a){f=a},this.serverMessagesInterceptor=["$q","growl",function(a,b){function d(a){a.data&&a.data[c]&&a.data[c].length>0&&b.addServerMessages(a.data[c])}return{response:function(a){return d(a),a},responseError:function(b){return d(b),a.reject(b)}}}],this.$get=["$rootScope","$filter",function(c,g){function h(a){p&&(a.text=p(a.text)),c.$broadcast("growlMessage",a)}function i(c,d,e){var f,g=d||{};f={text:c,severity:e,ttl:g.ttl||a,enableHtml:g.enableHtml||b},h(f)}function j(a,b){i(a,b,"warn")}function k(a,b){i(a,b,"error")}function l(a,b){i(a,b,"info")}function m(a,b){i(a,b,"success")}function n(a){var b,c,f,g;for(g=a.length,b=0;g>b;b++)if(c=a[b],c[d]&&c[e]){switch(c[e]){case"warn":f="warn";break;case"success":f="success";break;case"info":f="info";break;case"error":f="error"}i(c[d],void 0,f)}}function o(){return f}var p;try{p=g("translate")}catch(q){}return{addWarnMessage:j,addErrorMessage:k,addInfoMessage:l,addSuccessMessage:m,addServerMessages:n,onlyUnique:o}}]}); \ No newline at end of file diff --git a/src/growlFactory.js b/src/growlFactory.js index d3e5329..83cd8fc 100644 --- a/src/growlFactory.js +++ b/src/growlFactory.js @@ -60,28 +60,25 @@ angular.module("angular-growl").provider("growl", function() { /** * $http interceptor that can be added to array of $http interceptors during config phase of application - * via $httpProvider.responseInterceptors.push(...) + * via $httpProvider.interceptors.push(...) * */ this.serverMessagesInterceptor = ['$q', 'growl', function ($q, growl) { function checkResponse(response) { - if (response.data[_messagesKey] && response.data[_messagesKey].length > 0) { + if (response.data && response.data[_messagesKey] && response.data[_messagesKey].length > 0) { growl.addServerMessages(response.data[_messagesKey]); } } - function success(response) { - checkResponse(response); - return response; - } - - function error(response) { - checkResponse(response); - return $q.reject(response); - } - - return function (promise) { - return promise.then(success, error); + return { + response: function(response) { + checkResponse(response); + return response; + }, + responseError: function(response) { + checkResponse(response); + return $q.reject(response); + } }; }];