Skip to content

Commit ffca3a2

Browse files
committed
Release 1.0.0-beta.1
1 parent 81bb02e commit ffca3a2

File tree

11 files changed

+216
-51
lines changed

11 files changed

+216
-51
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Version 1.0.0-beta.1
4+
5+
- Maximum opened toasts can be limited now.
6+
- Allows to attach an `onShown` and `onHidden` callback.
7+
- Allows toasts to override options without title [9013c4d](https://github.com/Foxandxss/angular-toastr/commit/9013c4d1c7562d2ba5047c1e969a0316eb4e6c1d)
8+
39
## Version 0.5.2
410

511
- Removed the support for IE 8 (in terms of CSS)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ app.config(function(toastrConfig) {
115115
success: 'toast-success',
116116
warning: 'toast-warning'
117117
},
118+
maxOpened: 0,
118119
messageClass: 'toast-message',
119120
newestOnTop: true,
120121
onHidden: null,
@@ -136,6 +137,7 @@ Those are the default values, you can pick what you need from it and override wi
136137
* **containerId**: The name of the container where you want to append your toasts (the container will be created for you).
137138
* **extendedTimeOut**: The timeout after you hover a toast.
138139
* **iconClasses**: The default type classes for the different toasts.
140+
* **maxOpened**: Maximum number of toasts displayed at once.
139141
* **messageClass**: The class for the toast's message.
140142
* **newestOnTop**: Add new toasts on top of the old one. Put on false to put them on the bottom.
141143
* **onHidden**: A callback function called when a toast gets hidden.

bower.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
{
22
"name": "angular-toastr",
3-
"version": "0.5.2",
3+
"version": "1.0.0-beta.1",
4+
"authors": [
5+
"Jesus Rodriguez <Foxandxss@gmail.com>"
6+
],
7+
"keywords": [
8+
"angular",
9+
"angularjs",
10+
"toast",
11+
"toastr"
12+
],
413
"main": [
514
"./dist/angular-toastr.js",
615
"./dist/angular-toastr.css"

dist/angular-toastr.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,33 @@
5050
return _buildNotification(type, message, title, optionsOverride);
5151
}
5252

53-
function remove(toastIndex) {
54-
var toast = findToast(toastIndex);
53+
function remove(toastId) {
54+
var toast = findToast(toastId);
55+
var defer = $q.defer();
5556

5657
if (toast) { // Avoid clicking when fading out
5758

5859
$animate.leave(toast.el).then(function() {
60+
defer.resolve();
5961
if (toast.scope.options.onHidden) {
6062
toast.scope.options.onHidden();
6163
}
6264
toast.scope.$destroy();
65+
var index = toasts.indexOf(toast);
66+
toasts.splice(index, 1);
6367
if (lastToast()) {
6468
toasts = [];
6569
container.remove();
6670
container = null;
6771
containerDefer = $q.defer();
6872
}
6973
});
74+
} else {
75+
defer.resolve();
7076
}
7177

78+
return defer.promise;
79+
7280
function findToast(toastId) {
7381
for (var i = 0; i < toasts.length; i++) {
7482
if (toasts[i].toastId === toastId) {
@@ -102,6 +110,10 @@
102110
return angular.extend({}, toastrConfig);
103111
}
104112

113+
function _createFakePromise(promise) {
114+
return $q.when(); // resolve immediately
115+
}
116+
105117
function _createOrGetContainer(options) {
106118
if(container) { return containerDefer.promise; }
107119

@@ -120,22 +132,32 @@
120132
}
121133

122134
function _notify(map) {
135+
// This promise creates a nice effect when maxOpened toasts is reached.
136+
var promise;
137+
123138
var options = _getOptions();
124139

125140
var newToast = createToast();
126141

142+
if (options.maxOpened && toasts.length >= options.maxOpened) {
143+
promise = remove(toasts[0].toastId);
144+
} else {
145+
promise = _createFakePromise(promise);
146+
}
127147
toasts.push(newToast);
128148

129149
_createOrGetContainer(options).then(function() {
130-
if (options.newestOnTop) {
131-
$animate.enter(newToast.el, container).then(function() {
132-
newToast.scope.init();
133-
});
134-
} else {
135-
$animate.enter(newToast.el, container, container[0].lastChild).then(function() {
136-
newToast.scope.init();
137-
});
138-
}
150+
promise.then(function() {
151+
if (options.newestOnTop) {
152+
$animate.enter(newToast.el, container).then(function() {
153+
newToast.scope.init();
154+
});
155+
} else {
156+
$animate.enter(newToast.el, container, container[0].lastChild).then(function() {
157+
newToast.scope.init();
158+
});
159+
}
160+
});
139161
});
140162

141163
return newToast;
@@ -208,6 +230,7 @@
208230
success: 'toast-success',
209231
warning: 'toast-warning'
210232
},
233+
maxOpened: 0,
211234
messageClass: 'toast-message',
212235
newestOnTop: true,
213236
onHidden: null,

dist/angular-toastr.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-toastr.tpls.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,33 @@
5050
return _buildNotification(type, message, title, optionsOverride);
5151
}
5252

53-
function remove(toastIndex) {
54-
var toast = findToast(toastIndex);
53+
function remove(toastId) {
54+
var toast = findToast(toastId);
55+
var defer = $q.defer();
5556

5657
if (toast) { // Avoid clicking when fading out
5758

5859
$animate.leave(toast.el).then(function() {
60+
defer.resolve();
5961
if (toast.scope.options.onHidden) {
6062
toast.scope.options.onHidden();
6163
}
6264
toast.scope.$destroy();
65+
var index = toasts.indexOf(toast);
66+
toasts.splice(index, 1);
6367
if (lastToast()) {
6468
toasts = [];
6569
container.remove();
6670
container = null;
6771
containerDefer = $q.defer();
6872
}
6973
});
74+
} else {
75+
defer.resolve();
7076
}
7177

78+
return defer.promise;
79+
7280
function findToast(toastId) {
7381
for (var i = 0; i < toasts.length; i++) {
7482
if (toasts[i].toastId === toastId) {
@@ -102,6 +110,10 @@
102110
return angular.extend({}, toastrConfig);
103111
}
104112

113+
function _createFakePromise(promise) {
114+
return $q.when(); // resolve immediately
115+
}
116+
105117
function _createOrGetContainer(options) {
106118
if(container) { return containerDefer.promise; }
107119

@@ -120,22 +132,32 @@
120132
}
121133

122134
function _notify(map) {
135+
// This promise creates a nice effect when maxOpened toasts is reached.
136+
var promise;
137+
123138
var options = _getOptions();
124139

125140
var newToast = createToast();
126141

142+
if (options.maxOpened && toasts.length >= options.maxOpened) {
143+
promise = remove(toasts[0].toastId);
144+
} else {
145+
promise = _createFakePromise(promise);
146+
}
127147
toasts.push(newToast);
128148

129149
_createOrGetContainer(options).then(function() {
130-
if (options.newestOnTop) {
131-
$animate.enter(newToast.el, container).then(function() {
132-
newToast.scope.init();
133-
});
134-
} else {
135-
$animate.enter(newToast.el, container, container[0].lastChild).then(function() {
136-
newToast.scope.init();
137-
});
138-
}
150+
promise.then(function() {
151+
if (options.newestOnTop) {
152+
$animate.enter(newToast.el, container).then(function() {
153+
newToast.scope.init();
154+
});
155+
} else {
156+
$animate.enter(newToast.el, container, container[0].lastChild).then(function() {
157+
newToast.scope.init();
158+
});
159+
}
160+
});
139161
});
140162

141163
return newToast;
@@ -208,6 +230,7 @@
208230
success: 'toast-success',
209231
warning: 'toast-warning'
210232
},
233+
maxOpened: 0,
211234
messageClass: 'toast-message',
212235
newestOnTop: true,
213236
onHidden: null,

0 commit comments

Comments
 (0)