diff --git a/plugins/CoreHome/angularjs/notification/notification.directive.js b/plugins/CoreHome/angularjs/notification/notification.directive.js index 167c61575b317e3835f83d738ea9a2542af70eac..4168be33f3ee07513d87be654275440ef877bb6a 100644 --- a/plugins/CoreHome/angularjs/notification/notification.directive.js +++ b/plugins/CoreHome/angularjs/notification/notification.directive.js @@ -43,7 +43,11 @@ templateUrl: 'plugins/CoreHome/angularjs/notification/notification.directive.html?cb=' + piwik.cacheBuster, controller: 'NotificationController', controllerAs: 'notification', - link: function (scope, element, attrs) { + link: function (scope, element) { + if (scope.notificationId) { + closeExistingNotificationHavingSameIdIfNeeded(scope.notificationId, element); + } + if (scope.context) { element.children('.notification').addClass('notification-' + scope.context); } @@ -53,10 +57,6 @@ scope.noclear = false; } - if (scope.notificationId) { - closeExistingNotificationHavingSameIdIfNeeded(); - } - if ('toast' == scope.type) { addToastEvent(); } @@ -65,15 +65,6 @@ addCloseEvent(); } - function closeExistingNotificationHavingSameIdIfNeeded() { - // TODO: instead of doing a global query for notification, there should be a notification-container - // directive that manages notifications. - var existingNode = angular.element('.system.notification[notification-id=' + attrs.id + ']'); - if (existingNode && existingNode.length) { - existingNode.remove(); - } - } - function addToastEvent() { $timeout(function () { element.fadeOut('slow', function() { @@ -89,6 +80,15 @@ } }); } + + function closeExistingNotificationHavingSameIdIfNeeded(id, notificationElement) { + // TODO: instead of doing a global query for notification, there should be a notification-container + // directive that manages notifications. + var existingNode = angular.element('[notification-id=' + id + ']').not(notificationElement); + if (existingNode && existingNode.length) { + existingNode.remove(); + } + } } }; } diff --git a/plugins/CoreHome/javascripts/notification.js b/plugins/CoreHome/javascripts/notification.js index 4d8ff0c8f72ccacf15aab5ceabbe4958d5edd654..e6c3f017f2ebf6484e945f7212768676cfb8f35a 100644 --- a/plugins/CoreHome/javascripts/notification.js +++ b/plugins/CoreHome/javascripts/notification.js @@ -50,8 +50,6 @@ options = {}; } - closeExistingNotificationHavingSameIdIfNeeded(options); - var template = generateNotificationHtmlMarkup(options, message); this.$node = placeNotification(template, options); }; @@ -111,16 +109,4 @@ return $notificationNode; } - function closeExistingNotificationHavingSameIdIfNeeded(options) - { - if (!options.id) { - return; - } - - var $existingNode = $('[notification-id=' + options.id + ']'); - if ($existingNode && $existingNode.length) { - $existingNode.remove(); - } - } - })(jQuery, require); \ No newline at end of file