Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://github.com/Foxandxss/angular-toastr/issues/204 #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/toastr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

angular.module('toastr', [])
.factory('toastr', toastr);
.factory('toastr', toastr);

toastr.$inject = ['$animate', '$injector', '$document', '$rootScope', '$sce', 'toastrConfig', '$q'];

Expand Down Expand Up @@ -69,7 +69,7 @@

function refreshTimer(toast, newTime) {
if (toast && toast.isOpened && toasts.indexOf(toast) >= 0) {
toast.scope.refreshTimer(newTime);
toast.scope.refreshTimer(newTime);
}
}

Expand Down Expand Up @@ -161,12 +161,12 @@

toasts.push(newToast);

if (ifMaxOpenedAndAutoDismiss()) {
var oldToasts = toasts.slice(0, (toasts.length - options.maxOpened));
for (var i = 0, len = oldToasts.length; i < len; i++) {
remove(oldToasts[i].toastId);
}
}
// if (ifMaxOpenedAndAutoDismiss()) {
// var oldToasts = toasts.slice(0, (toasts.length - options.maxOpened));
// for (var i = 0, len = oldToasts.length; i < len; i++) {
// remove(oldToasts[i].toastId);
// }
// }

if (maxOpenedNotReached()) {
newToast.open.resolve();
Expand All @@ -178,18 +178,29 @@
if (options.newestOnTop) {
$animate.enter(newToast.el, container).then(function() {
newToast.scope.init();
maybeRemoveOldToasts();
});
} else {
var sibling = container[0].lastChild ? angular.element(container[0].lastChild) : null;
$animate.enter(newToast.el, container, sibling).then(function() {
newToast.scope.init();
maybeRemoveOldToasts();
});
}
});
});

return newToast;

function maybeRemoveOldToasts() {
if (ifMaxOpenedAndAutoDismiss()) {
var oldToasts = toasts.slice(0, (toasts.length - options.maxOpened));
for (var i = 0, len = oldToasts.length; i < len; i++) {
remove(oldToasts[i].toastId);
}
}
}

function ifMaxOpenedAndAutoDismiss() {
return options.autoDismiss && options.maxOpened && toasts.length > options.maxOpened;
}
Expand Down Expand Up @@ -255,7 +266,7 @@

function cleanOptionsOverride(options) {
var badOptions = ['containerId', 'iconClasses', 'maxOpened', 'newestOnTop',
'positionClass', 'preventDuplicates', 'preventOpenDuplicates', 'templates'];
'positionClass', 'preventDuplicates', 'preventOpenDuplicates', 'templates'];
for (var i = 0, l = badOptions.length; i < l; i++) {
delete options[badOptions[i]];
}
Expand All @@ -266,7 +277,7 @@

function createToastEl(scope) {
var angularDomEl = angular.element('<div toast></div>'),
$compile = $injector.get('$compile');
$compile = $injector.get('$compile');
return $compile(angularDomEl)(scope);
}

Expand Down