Skip to content

Commit fcecd1e

Browse files
committed
Merge pull request DerekRies#9 from fetrarij/duration
add ability to set the notification duration
2 parents 513131d + 69eed59 commit fcecd1e

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ like:
4343

4444
You can use these methods with the following line of code
4545

46-
`$notification.info(title, content, userData);`
47-
`$notification.warning(title, content, userData);`
48-
`$notification.error(title, content, userData);`
49-
`$notification.success(title, content, userData);`
46+
`$notification.info(title, content, userData, duration);`
47+
`$notification.warning(title, content, userData, duration);`
48+
`$notification.error(title, content, userData, duration);`
49+
`$notification.success(title, content, userData, duration);`
5050

5151
**Title** is of course the title displayed in a large, bold text on the notification.
5252
**Content** is the additional detail text for that notification. The **userData** parameter
5353
is optional but allows you to store some data with a particular notification.
5454

55+
**Duration** is optional (milliseconds): It allows you to set hhow long the notification is shown. Put `0` or `false` if you want a persistent notification. If not given it take the value in the setting.
56+
5557
You can also use a generic notify method more inline with the standard chrome desktop
5658
notifications by specifying an image to display in the notification.
5759
`$notification.notify('image.jpg', 'My Title', 'My notification description text');`

notification.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,24 @@ angular.module('notifications', []).
111111

112112
/* ============== NOTIFICATION METHODS ==============*/
113113

114-
info: function(title, content, userData){
114+
info: function(title, content, userData, duration){
115115
console.log(title, content);
116-
return this.awesomeNotify('info','info', title, content, userData);
116+
return this.awesomeNotify('info','info', title, content, userData, duration);
117117
},
118118

119-
error: function(title, content, userData){
120-
return this.awesomeNotify('error', 'remove', title, content, userData);
119+
error: function(title, content, userData, duration){
120+
return this.awesomeNotify('error', 'remove', title, content, userData, duration);
121121
},
122122

123-
success: function(title, content, userData){
124-
return this.awesomeNotify('success', 'ok', title, content, userData);
123+
success: function(title, content, userData, duration){
124+
return this.awesomeNotify('success', 'ok', title, content, userData, duration);
125125
},
126126

127-
warning: function(title, content, userData){
128-
return this.awesomeNotify('warning', 'exclamation', title, content, userData);
127+
warning: function(title, content, userData, duration){
128+
return this.awesomeNotify('warning', 'exclamation', title, content, userData, duration);
129129
},
130130

131-
awesomeNotify: function(type, icon, title, content, userData){
131+
awesomeNotify: function(type, icon, title, content, userData, duration){
132132
/**
133133
* Supposed to wrap the makeNotification method for drawing icons using font-awesome
134134
* rather than an image.
@@ -139,27 +139,30 @@ angular.module('notifications', []).
139139
* through classes.
140140
*/
141141
// image = '<i class="icon-' + image + '"></i>';
142-
return this.makeNotification(type, false, icon, title, content, userData);
142+
return this.makeNotification(type, false, icon, title, content, userData, duration);
143143
},
144144

145-
notify: function(image, title, content, userData){
145+
notify: function(image, title, content, userData, duration){
146146
// Wraps the makeNotification method for displaying notifications with images
147147
// rather than icons
148148
return this.makeNotification('custom', image, true, title, content, userData);
149149
},
150150

151-
makeNotification: function(type, image, icon, title, content, userData){
151+
makeNotification: function(type, image, icon, title, content, userData, duration){
152152
var notification = {
153153
'type': type,
154154
'image': image,
155155
'icon': icon,
156156
'title': title,
157157
'content': content,
158158
'timestamp': +new Date(),
159-
'userData': userData
159+
'userData': userData,
160+
'duration': duration
160161
};
161162
notifications.push(notification);
162-
163+
if(duration == undefined) {
164+
duration = settings[type].duration;
165+
}
163166
if(settings.html5Mode){
164167
html5Notify(image, title, content, function(){
165168
console.log("inner on display function");
@@ -169,10 +172,11 @@ angular.module('notifications', []).
169172
}
170173
else{
171174
queue.push(notification);
172-
$timeout(function removeFromQueueTimeout(){
173-
queue.splice(queue.indexOf(notification), 1);
174-
}, settings[type].duration);
175-
175+
if(duration){
176+
$timeout(function removeFromQueueTimeout(){
177+
queue.splice(queue.indexOf(notification), 1);
178+
}, duration);
179+
}
176180
}
177181

178182
this.save();

0 commit comments

Comments
 (0)