From d63f7361f15b8a9fe0bbe2fade01f598bc8e50d9 Mon Sep 17 00:00:00 2001 From: "Beaver, Richard" Date: Sat, 21 Mar 2015 16:04:11 -0700 Subject: [PATCH] Issue #11 - Support for per-message duration --- README.md | 1 + angular-notify.js | 9 +++++---- dist/angular-notify.js | 9 +++++---- dist/angular-notify.min.js | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1b63bc1..2a46fc2 100755 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ function myController($scope,notify){ // <-- Inject notify The `notify` function can either be passed a string or an object. When passing an object, the object parameters can be: * `message` - Required. The message to show. +* `duration` - Optional. The duration (in milliseconds) of message. A duration of 0 will prevent messages from closing automatically. * `templateUrl` - Optional. A custom template for the UI of the message. * `classes` - Optional. A list of custom CSS classes to apply to the message element. * `messageTemplate` - Optional. A string containing any valid Angular HTML which will be shown instead of the regular `message` text. The string must contain one root element like all valid Angular HTML templates (so wrap everything in a ``). diff --git a/angular-notify.js b/angular-notify.js index ebe2588..8e10c91 100755 --- a/angular-notify.js +++ b/angular-notify.js @@ -3,7 +3,7 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' var startTop = 10; var verticalSpacing = 15; - var duration = 10000; + var defaultDuration = 10000; var defaultTemplateUrl = 'angular-notify.html'; var position = 'center'; var container = document.body; @@ -16,6 +16,7 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' args = {message:args}; } + args.duration = args.duration ? args.duration : defaultDuration; args.templateUrl = args.templateUrl ? args.templateUrl : defaultTemplateUrl; args.position = args.position ? args.position : position; args.container = args.container ? args.container : container; @@ -90,10 +91,10 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' layoutMessages(); }); - if (duration > 0){ + if (args.duration > 0){ $timeout(function(){ scope.$close(); - },duration); + },args.duration); } }).error(function(data){ @@ -124,7 +125,7 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' notify.config = function(args){ startTop = !angular.isUndefined(args.startTop) ? args.startTop : startTop; verticalSpacing = !angular.isUndefined(args.verticalSpacing) ? args.verticalSpacing : verticalSpacing; - duration = !angular.isUndefined(args.duration) ? args.duration : duration; + defaultDuration = !angular.isUndefined(args.duration) ? args.duration : defaultDuration; defaultTemplateUrl = args.templateUrl ? args.templateUrl : defaultTemplateUrl; position = !angular.isUndefined(args.position) ? args.position : position; container = args.container ? args.container : container; diff --git a/dist/angular-notify.js b/dist/angular-notify.js index 7675820..fd372b9 100644 --- a/dist/angular-notify.js +++ b/dist/angular-notify.js @@ -3,7 +3,7 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' var startTop = 10; var verticalSpacing = 15; - var duration = 10000; + var defaultDuration = 10000; var defaultTemplateUrl = 'angular-notify.html'; var position = 'center'; var container = document.body; @@ -16,6 +16,7 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' args = {message:args}; } + args.duration = args.duration ? args.duration : defaultDuration; args.templateUrl = args.templateUrl ? args.templateUrl : defaultTemplateUrl; args.position = args.position ? args.position : position; args.container = args.container ? args.container : container; @@ -90,10 +91,10 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' layoutMessages(); }); - if (duration > 0){ + if (args.duration > 0){ $timeout(function(){ scope.$close(); - },duration); + },args.duration); } }).error(function(data){ @@ -124,7 +125,7 @@ angular.module('cgNotify', []).factory('notify',['$timeout','$http','$compile',' notify.config = function(args){ startTop = !angular.isUndefined(args.startTop) ? args.startTop : startTop; verticalSpacing = !angular.isUndefined(args.verticalSpacing) ? args.verticalSpacing : verticalSpacing; - duration = !angular.isUndefined(args.duration) ? args.duration : duration; + defaultDuration = !angular.isUndefined(args.duration) ? args.duration : defaultDuration; defaultTemplateUrl = args.templateUrl ? args.templateUrl : defaultTemplateUrl; position = !angular.isUndefined(args.position) ? args.position : position; container = args.container ? args.container : container; diff --git a/dist/angular-notify.min.js b/dist/angular-notify.min.js index 5d950ba..10492c6 100644 --- a/dist/angular-notify.min.js +++ b/dist/angular-notify.min.js @@ -1 +1 @@ -angular.module("cgNotify",[]).factory("notify",["$timeout","$http","$compile","$templateCache","$rootScope",function(a,b,c,d,e){var f=10,g=15,h=1e4,i="angular-notify.html",j="center",k=document.body,l=[],m=function(m){"object"!=typeof m&&(m={message:m}),m.templateUrl=m.templateUrl?m.templateUrl:i,m.position=m.position?m.position:j,m.container=m.container?m.container:k,m.classes=m.classes?m.classes:"";var n=m.scope?m.scope.$new():e.$new();n.$message=m.message,n.$classes=m.classes,n.$messageTemplate=m.messageTemplate,b.get(m.templateUrl,{cache:d}).success(function(b){var d=c(b)(n);if(d.bind("webkitTransitionEnd oTransitionEnd otransitionend transitionend msTransitionEnd",function(a){("opacity"===a.propertyName||0===a.currentTarget.style.opacity||a.originalEvent&&"opacity"===a.originalEvent.propertyName)&&(d.remove(),l.splice(l.indexOf(d),1),j())}),m.messageTemplate){for(var e,i=0;i=0;c--){var d=10,e=l[c],h=e[0].offsetHeight,i=b+h+d;e.attr("data-closing")?i+=20:b+=h+g,e.css("top",i+"px").css("margin-top","-"+(h+d)+"px").css("visibility","visible"),a++}};a(function(){j()}),h>0&&a(function(){n.$close()},h)}).error(function(a){throw new Error("Template specified for cgNotify ("+m.templateUrl+") could not be loaded. "+a)});var o={};return o.close=function(){n.$close&&n.$close()},Object.defineProperty(o,"message",{get:function(){return n.$message},set:function(a){n.$message=a}}),o};return m.config=function(a){f=angular.isUndefined(a.startTop)?f:a.startTop,g=angular.isUndefined(a.verticalSpacing)?g:a.verticalSpacing,h=angular.isUndefined(a.duration)?h:a.duration,i=a.templateUrl?a.templateUrl:i,j=angular.isUndefined(a.position)?j:a.position,k=a.container?a.container:k},m.closeAll=function(){for(var a=l.length-1;a>=0;a--){var b=l[a];b.css("opacity",0)}},m}]),angular.module("cgNotify").run(["$templateCache",function(a){"use strict";a.put("angular-notify.html",'
\n\n
\n {{$message}}\n
\n\n
\n \n
\n\n \n\n
')}]); \ No newline at end of file +angular.module("cgNotify",[]).factory("notify",["$timeout","$http","$compile","$templateCache","$rootScope",function(a,b,c,d,e){var f=10,g=15,h=1e4,i="angular-notify.html",j="center",k=document.body,l=[],m=function(m){"object"!=typeof m&&(m={message:m}),m.duration=m.duration?m.duration:h,m.templateUrl=m.templateUrl?m.templateUrl:i,m.position=m.position?m.position:j,m.container=m.container?m.container:k,m.classes=m.classes?m.classes:"";var n=m.scope?m.scope.$new():e.$new();n.$message=m.message,n.$classes=m.classes,n.$messageTemplate=m.messageTemplate,b.get(m.templateUrl,{cache:d}).success(function(b){var d=c(b)(n);if(d.bind("webkitTransitionEnd oTransitionEnd otransitionend transitionend msTransitionEnd",function(a){("opacity"===a.propertyName||0===a.currentTarget.style.opacity||a.originalEvent&&"opacity"===a.originalEvent.propertyName)&&(d.remove(),l.splice(l.indexOf(d),1),i())}),m.messageTemplate){for(var e,h=0;h=0;c--){var d=10,e=l[c],h=e[0].offsetHeight,i=b+h+d;e.attr("data-closing")?i+=20:b+=h+g,e.css("top",i+"px").css("margin-top","-"+(h+d)+"px").css("visibility","visible"),a++}};a(function(){i()}),m.duration>0&&a(function(){n.$close()},m.duration)}).error(function(a){throw new Error("Template specified for cgNotify ("+m.templateUrl+") could not be loaded. "+a)});var o={};return o.close=function(){n.$close&&n.$close()},Object.defineProperty(o,"message",{get:function(){return n.$message},set:function(a){n.$message=a}}),o};return m.config=function(a){f=angular.isUndefined(a.startTop)?f:a.startTop,g=angular.isUndefined(a.verticalSpacing)?g:a.verticalSpacing,h=angular.isUndefined(a.duration)?h:a.duration,i=a.templateUrl?a.templateUrl:i,j=angular.isUndefined(a.position)?j:a.position,k=a.container?a.container:k},m.closeAll=function(){for(var a=l.length-1;a>=0;a--){var b=l[a];b.css("opacity",0)}},m}]),angular.module("cgNotify").run(["$templateCache",function(a){"use strict";a.put("angular-notify.html",'
\n\n
\n {{$message}}\n
\n\n
\n \n
\n\n \n\n
')}]); \ No newline at end of file