Skip to content

Commit f75f952

Browse files
tlvinceFoxandxss
authored andcommitted
feat: auto dismiss the last maxOpened toasts
For example, when `maxOpened: 1`, always show the newest toast regardless of timeouts. Closes #76.
1 parent f978c0a commit f75f952

File tree

8 files changed

+38
-2
lines changed

8 files changed

+38
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ app.config(function(toastrConfig) {
122122
warning: 'toast-warning'
123123
},
124124
maxOpened: 0,
125+
autoDismiss: false,
125126
messageClass: 'toast-message',
126127
newestOnTop: true,
127128
onHidden: null,
@@ -151,6 +152,7 @@ Those are the default values, you can pick what you need from it and override wi
151152
* **extendedTimeOut**: The timeout after you hover a toast.
152153
* **iconClasses**: The default type classes for the different toasts.
153154
* **maxOpened**: Maximum number of toasts displayed at once.
155+
* **autoDismiss** If set, show only the most recent `maxOpened` toast(s)
154156
* **messageClass**: The class for the toast's message.
155157
* **newestOnTop**: Add new toasts on top of the old one. Put on false to put them on the bottom.
156158
* **onHidden**: A callback function called when a toast gets hidden.

dist/angular-toastr.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@
144144

145145
toasts.push(newToast);
146146

147+
if (options.autoDismiss && options.maxOpened > 0) {
148+
var oldToasts = toasts.slice(0, (toasts.length - options.maxOpened));
149+
for (var i = 0, len = oldToasts.length; i < len; i++) {
150+
remove(oldToasts[i].toastId);
151+
}
152+
}
153+
147154
if (maxOpenedNotReached()) {
148155
newToast.open.resolve();
149156
}
@@ -264,6 +271,7 @@
264271
warning: 'toast-warning'
265272
},
266273
maxOpened: 0,
274+
autoDismiss: false,
267275
messageClass: 'toast-message',
268276
newestOnTop: true,
269277
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@
144144

145145
toasts.push(newToast);
146146

147+
if (options.autoDismiss && options.maxOpened > 0) {
148+
var oldToasts = toasts.slice(0, (toasts.length - options.maxOpened));
149+
for (var i = 0, len = oldToasts.length; i < len; i++) {
150+
remove(oldToasts[i].toastId);
151+
}
152+
}
153+
147154
if (maxOpenedNotReached()) {
148155
newToast.open.resolve();
149156
}
@@ -264,6 +271,7 @@
264271
warning: 'toast-warning'
265272
},
266273
maxOpened: 0,
274+
autoDismiss: false,
267275
messageClass: 'toast-message',
268276
newestOnTop: true,
269277
onHidden: null,

0 commit comments

Comments
 (0)