From a910139d512c6611669dbfee09d341a82ea6c34f Mon Sep 17 00:00:00 2001 From: Chase Gray Date: Fri, 5 Sep 2014 12:16:05 -0700 Subject: [PATCH] disable click to close --- build/angular-growl.js | 16 +++++++++------- build/angular-growl.min.js | 2 +- src/growlDirective.js | 16 +++++++++------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/build/angular-growl.js b/build/angular-growl.js index 52a7bda..ec03064 100644 --- a/build/angular-growl.js +++ b/build/angular-growl.js @@ -30,13 +30,15 @@ angular.module('angular-growl').directive('growl', [function () { } }); $scope.stopTimeoutClose = function (message) { - angular.forEach(message.promises, function (promise) { - $timeout.cancel(promise); - }); - if (message.close) { - growlMessages.deleteMessage(message); - } else { - message.close = true; + if (!message.clickToClose) { + angular.forEach(message.promises, function (promise) { + $timeout.cancel(promise); + }); + if (message.close) { + growlMessages.deleteMessage(message); + } else { + message.close = true; + } } }; $scope.alertClasses = function (message) { diff --git a/build/angular-growl.min.js b/build/angular-growl.min.js index baebbb2..0195a5d 100644 --- a/build/angular-growl.min.js +++ b/build/angular-growl.min.js @@ -3,4 +3,4 @@ * http://janstevens.github.io/angular-growl-2 * Copyright (c) 2014 Marco Rinck,Jan Stevens; Licensed MIT */ -angular.module("angular-growl",[]),angular.module("angular-growl").directive("growl",[function(){"use strict";return{restrict:"A",templateUrl:"templates/growl/growl.html",replace:!1,scope:{reference:"@",inline:"@",limitMessages:"="},controller:["$scope","$timeout","growl","growlMessages",function(a,b,c,d){d.init(a.reference,a.inline,c.onlyUnique(),c.reverseOrder()),a.growlMessages=d,a.inlineMessage=a.inline||c.inlineMessages(),a.$watch("limitMessages",function(a){angular.isUndefined(a)||(d.limitMessages=a)}),a.stopTimeoutClose=function(a){angular.forEach(a.promises,function(a){b.cancel(a)}),a.close?d.deleteMessage(a):a.close=!0},a.alertClasses=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":"warning"===a.severity,icon:a.disableIcons===!1,"alert-dismissable":!a.disableCloseButton}},a.showCountDown=function(a){return!a.disableCountDown&&a.ttl>0},a.wrapperClasses=function(){var b={};return b["growl-fixed"]=!a.inlineMessage,b[c.position()]=!0,b},a.computeTitle=function(a){var b={success:"Success",error:"Error",info:"Information",warn:"Warning"};return b[a.severity]}}]}}]),angular.module("angular-growl").run(["$templateCache",function(a){"use strict";void 0===a.get("templates/growl/growl.html")&&a.put("templates/growl/growl.html",'

')}]),angular.module("angular-growl").provider("growl",function(){"use strict";var a={success:null,error:null,warning:null,info:null},b="messages",c="text",d="title",e="severity",f=!0,g="variables",h=0,i=!1,j="top-right",k=!1,l=!1,m=!1,n=!1;this.globalTimeToLive=function(b){if("object"==typeof b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);else for(var d in a)a.hasOwnProperty(d)&&(a[d]=b)},this.globalDisableCloseButton=function(a){k=a},this.globalDisableIcons=function(a){l=a},this.globalReversedOrder=function(a){m=a},this.globalDisableCountDown=function(a){n=a},this.messageVariableKey=function(a){g=a},this.globalInlineMessages=function(a){i=a},this.globalPosition=function(a){j=a},this.messagesKey=function(a){b=a},this.messageTextKey=function(a){c=a},this.messageTitleKey=function(a){d=a},this.messageSeverityKey=function(a){e=a},this.onlyUniqueMessages=function(a){f=a},this.serverMessagesInterceptor=["$q","growl",function(a,c){function d(a){a.data[b]&&a.data[b].length>0&&c.addServerMessages(a.data[b])}return{response:function(a){return d(a),a},responseError:function(b){return d(b),a.reject(b)}}}],this.$get=["$rootScope","$interpolate","$filter","$timeout","growlMessages",function(b,o,p,q,r){function s(a){if(D)a.text=D(a.text,a.variables);else{var c=o(a.text);a.text=c(a.variables)}var d=r.addMessage(a);return b.$broadcast("growlMessage",a),q(function(){},0),d}function t(b,c,d){var e,f=c||{};return e={text:b,title:f.title,severity:d,ttl:f.ttl||a[d],variables:f.variables||{},disableCloseButton:void 0===f.disableCloseButton?k:f.disableCloseButton,disableIcons:void 0===f.disableIcons?l:f.disableIcons,disableCountDown:void 0===f.disableCountDown?n:f.disableCountDown,position:f.position||j,referenceId:f.referenceId||h,destroy:function(){r.deleteMessage(e)},onclose:f.onclose,onopen:f.onopen},s(e)}function u(a,b){return t(a,b,"warning")}function v(a,b){return t(a,b,"error")}function w(a,b){return t(a,b,"info")}function x(a,b){return t(a,b,"success")}function y(a){var b,f,h,i;for(i=a.length,b=0;i>b;b++)if(f=a[b],f[c]){h=f[e]||"error";var j={};j.variables=f[g]||{},j.title=f[d],t(f[c],j,h)}}function z(){return f}function A(){return m}function B(){return i}function C(){return j}var D;try{D=p("translate")}catch(E){}return{warning:u,error:v,info:w,success:x,addServerMessages:y,onlyUnique:z,reverseOrder:A,inlineMessages:B,position:C}}]}),angular.module("angular-growl").service("growlMessages",["$sce","$timeout",function(a,b){"use strict";var c,d;this.init=function(a,b,e,f){this.messages=c=[],this.limitMessages=b,this.onlyUnique=e,this.reverseOrder=f,d=a||0},this.addMessage=function(e){if(parseInt(d,10)===parseInt(e.referenceId,10)){var f,g;if(this.onlyUnique&&(angular.forEach(c,function(b){g=a.getTrustedHtml(b.text),e.text===g&&e.severity===b.severity&&b.title===b.title&&(f=!0)}),f))return;if(e.text=a.trustAsHtml(String(e.text)),e.ttl&&-1!==e.ttl&&(e.countdown=e.ttl/1e3,e.promises=[],e.close=!1,e.countdownFunction=function(){e.countdown>1?(e.countdown--,e.promises.push(b(e.countdownFunction,1e3))):e.countdown--}),angular.isDefined(this.limitMessages)){var h=c.length-(this.limitMessages-1);h>0&&c.splice(this.limitMessages-1,h)}return this.reverseOrder?c.unshift(e):c.push(e),"function"==typeof e.onopen&&e.onopen(),e.ttl&&-1!==e.ttl&&(e.promises.push(b(angular.bind(this,function(){this.deleteMessage(e)}),e.ttl)),e.promises.push(b(e.countdownFunction,1e3))),e}},this.deleteMessage=function(a){var b=c.indexOf(a);b>-1&&c.splice(b,1),"function"==typeof a.onclose&&a.onclose()}}]); \ No newline at end of file +angular.module("angular-growl",[]),angular.module("angular-growl").directive("growl",[function(){"use strict";return{restrict:"A",templateUrl:"templates/growl/growl.html",replace:!1,scope:{reference:"@",inline:"@",limitMessages:"="},controller:["$scope","$timeout","growl","growlMessages",function(a,b,c,d){d.init(a.reference,a.inline,c.onlyUnique(),c.reverseOrder()),a.growlMessages=d,a.inlineMessage=a.inline||c.inlineMessages(),a.$watch("limitMessages",function(a){angular.isUndefined(a)||(d.limitMessages=a)}),a.stopTimeoutClose=function(a){a.clickToClose||(angular.forEach(a.promises,function(a){b.cancel(a)}),a.close?d.deleteMessage(a):a.close=!0)},a.alertClasses=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":"warning"===a.severity,icon:a.disableIcons===!1,"alert-dismissable":!a.disableCloseButton}},a.showCountDown=function(a){return!a.disableCountDown&&a.ttl>0},a.wrapperClasses=function(){var b={};return b["growl-fixed"]=!a.inlineMessage,b[c.position()]=!0,b},a.computeTitle=function(a){var b={success:"Success",error:"Error",info:"Information",warn:"Warning"};return b[a.severity]}}]}}]),angular.module("angular-growl").run(["$templateCache",function(a){"use strict";void 0===a.get("templates/growl/growl.html")&&a.put("templates/growl/growl.html",'

')}]),angular.module("angular-growl").provider("growl",function(){"use strict";var a={success:null,error:null,warning:null,info:null},b="messages",c="text",d="title",e="severity",f=!0,g="variables",h=0,i=!1,j="top-right",k=!1,l=!1,m=!1,n=!1;this.globalTimeToLive=function(b){if("object"==typeof b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);else for(var d in a)a.hasOwnProperty(d)&&(a[d]=b)},this.globalDisableCloseButton=function(a){k=a},this.globalDisableIcons=function(a){l=a},this.globalReversedOrder=function(a){m=a},this.globalDisableCountDown=function(a){n=a},this.messageVariableKey=function(a){g=a},this.globalInlineMessages=function(a){i=a},this.globalPosition=function(a){j=a},this.messagesKey=function(a){b=a},this.messageTextKey=function(a){c=a},this.messageTitleKey=function(a){d=a},this.messageSeverityKey=function(a){e=a},this.onlyUniqueMessages=function(a){f=a},this.serverMessagesInterceptor=["$q","growl",function(a,c){function d(a){a.data[b]&&a.data[b].length>0&&c.addServerMessages(a.data[b])}return{response:function(a){return d(a),a},responseError:function(b){return d(b),a.reject(b)}}}],this.$get=["$rootScope","$interpolate","$filter","$timeout","growlMessages",function(b,o,p,q,r){function s(a){if(D)a.text=D(a.text,a.variables);else{var c=o(a.text);a.text=c(a.variables)}var d=r.addMessage(a);return b.$broadcast("growlMessage",a),q(function(){},0),d}function t(b,c,d){var e,f=c||{};return e={text:b,title:f.title,severity:d,ttl:f.ttl||a[d],variables:f.variables||{},disableCloseButton:void 0===f.disableCloseButton?k:f.disableCloseButton,disableIcons:void 0===f.disableIcons?l:f.disableIcons,disableCountDown:void 0===f.disableCountDown?n:f.disableCountDown,position:f.position||j,referenceId:f.referenceId||h,destroy:function(){r.deleteMessage(e)},onclose:f.onclose,onopen:f.onopen},s(e)}function u(a,b){return t(a,b,"warning")}function v(a,b){return t(a,b,"error")}function w(a,b){return t(a,b,"info")}function x(a,b){return t(a,b,"success")}function y(a){var b,f,h,i;for(i=a.length,b=0;i>b;b++)if(f=a[b],f[c]){h=f[e]||"error";var j={};j.variables=f[g]||{},j.title=f[d],t(f[c],j,h)}}function z(){return f}function A(){return m}function B(){return i}function C(){return j}var D;try{D=p("translate")}catch(E){}return{warning:u,error:v,info:w,success:x,addServerMessages:y,onlyUnique:z,reverseOrder:A,inlineMessages:B,position:C}}]}),angular.module("angular-growl").service("growlMessages",["$sce","$timeout",function(a,b){"use strict";var c,d;this.init=function(a,b,e,f){this.messages=c=[],this.limitMessages=b,this.onlyUnique=e,this.reverseOrder=f,d=a||0},this.addMessage=function(e){if(parseInt(d,10)===parseInt(e.referenceId,10)){var f,g;if(this.onlyUnique&&(angular.forEach(c,function(b){g=a.getTrustedHtml(b.text),e.text===g&&e.severity===b.severity&&b.title===b.title&&(f=!0)}),f))return;if(e.text=a.trustAsHtml(String(e.text)),e.ttl&&-1!==e.ttl&&(e.countdown=e.ttl/1e3,e.promises=[],e.close=!1,e.countdownFunction=function(){e.countdown>1?(e.countdown--,e.promises.push(b(e.countdownFunction,1e3))):e.countdown--}),angular.isDefined(this.limitMessages)){var h=c.length-(this.limitMessages-1);h>0&&c.splice(this.limitMessages-1,h)}return this.reverseOrder?c.unshift(e):c.push(e),"function"==typeof e.onopen&&e.onopen(),e.ttl&&-1!==e.ttl&&(e.promises.push(b(angular.bind(this,function(){this.deleteMessage(e)}),e.ttl)),e.promises.push(b(e.countdownFunction,1e3))),e}},this.deleteMessage=function(a){var b=c.indexOf(a);b>-1&&c.splice(b,1),"function"==typeof a.onclose&&a.onclose()}}]); \ No newline at end of file diff --git a/src/growlDirective.js b/src/growlDirective.js index bf637a9..5eb18c4 100644 --- a/src/growlDirective.js +++ b/src/growlDirective.js @@ -25,13 +25,15 @@ angular.module("angular-growl").directive("growl", [ //Cancels all promises within message upon deleting message or stop deleting. $scope.stopTimeoutClose = function(message){ - angular.forEach(message.promises, function(promise){ - $timeout.cancel(promise); - }); - if(message.close){ - growlMessages.deleteMessage(message); - } else { - message.close = true; + if (!message.clickToClose) { + angular.forEach(message.promises, function(promise){ + $timeout.cancel(promise); + }); + if(message.close){ + growlMessages.deleteMessage(message); + } else { + message.close = true; + } } };