summaryrefslogtreecommitdiffstats
path: root/js/directive
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-09-18 10:14:46 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-09-18 10:14:46 +0200
commit4fe70c8f1bd032183990de37d19cdd9faafba0da (patch)
tree889e373be4e320281da8c05776908e1f5df434c7 /js/directive
parent66abbda5576ed5f675c645584969fc3e09152164 (diff)
correctly destroy element when route is being changed
Diffstat (limited to 'js/directive')
-rw-r--r--js/directive/NewsTimeout.js9
1 files changed, 7 insertions, 2 deletions
diff --git a/js/directive/NewsTimeout.js b/js/directive/NewsTimeout.js
index 43c6290a3..e54a32793 100644
--- a/js/directive/NewsTimeout.js
+++ b/js/directive/NewsTimeout.js
@@ -16,19 +16,24 @@ app.directive('newsTimeout', function ($timeout, $rootScope) {
'newsTimeout': '&'
},
link: function (scope, element) {
+ var destroyed = false;
var seconds = 7;
var timer = $timeout(scope.newsTimeout, seconds * 1000);
// remove timeout if element is being removed by
// for instance clicking on the x button
- scope.$on('$destroy', function () {
+ element.on('$destroy', function () {
$timeout.cancel(timer);
});
// also delete the entry if undo is ignored and the url
// is changed
$rootScope.$on('$locationChangeStart', function () {
- element.remove();
+ if (!destroyed) {
+ destroyed = true;
+ element.remove();
+ scope.newsTimeout();
+ }
});
}
};