diff --git a/message-center.js b/message-center.js index 4005306..afb41b3 100644 --- a/message-center.js +++ b/message-center.js @@ -10,6 +10,7 @@ MessageCenterModule. function ($rootScope, $sce, $timeout) { return { mcMessages: this.mcMessages || [], + offlistener: this.offlistener || undefined, status: { unseen: 'unseen', shown: 'shown', @@ -65,11 +66,11 @@ MessageCenterModule. if (!this.mcMessages[index].processed) { if (this.mcMessages[index].status == this.status.unseen) { this.mcMessages[index].status = this.status.shown; + this.mcMessages[index].processed = true; } else if (this.mcMessages[index].status == this.status.next) { this.mcMessages[index].status = this.status.unseen; } - this.mcMessages[index].processed = true; } } }, @@ -110,8 +111,9 @@ MessageCenterModule. $rootScope.mcMessages = messageCenterService.mcMessages; messageCenterService.flush(); }; - $rootScope.$on('$locationChangeStart', changeReaction); - + if (messageCenterService.offlistener === undefined) { + messageCenterService.offlistener = $rootScope.$on('$locationChangeSuccess', changeReaction); + } scope.animation = attrs.animation || 'fade in'; } }; diff --git a/test/app/index.html b/test/app/index.html index 01b66ec..32c636c 100644 --- a/test/app/index.html +++ b/test/app/index.html @@ -63,6 +63,13 @@ $scope.saveFailure = function() { messageCenterService.add('danger', 'Something went wrong!'); }; + $scope.saveSuccessGoHome = function() { + messageCenterService.add('success', 'Saved successfully and went home!', {status: messageCenterService.status.next}); + $scope.goIndex(); + }; + $scope.goIndex = function() { + $location.path('/'); + }; }) .controller('AllowHTMLController', function($scope, $location, messageCenterService) { @@ -72,7 +79,14 @@ $scope.plainText = function() { messageCenterService.add('warning', 'HTML is NOT allowed.'); }; - }); + }) + + .controller('PermanentController', function($scope, $location, messageCenterService) { + $scope.goIndex = function() { + $location.path('/'); + }; + }) + ; @@ -100,6 +114,8 @@
diff --git a/test/app/index3.html b/test/app/index3.html new file mode 100644 index 0000000..bb6208a --- /dev/null +++ b/test/app/index3.html @@ -0,0 +1,144 @@ + + +
+ + + + + + +
+