diff options
author | Jonathan Treffler <mail@jonathan-treffler.de> | 2020-08-07 11:06:13 +0200 |
---|---|---|
committer | Simon Spannagel <simonspa@kth.se> | 2021-12-16 19:49:12 +0100 |
commit | a2b48907f4f6d32d5d9c2350d9f11502506996b1 (patch) | |
tree | 7e235ab894327bfc6d5592125c3fcde4c4e5455c /js-old/directive/NewsTimeout.js | |
parent | be3db27ed3d7c75e054e54ea6ba0639cf29487dc (diff) |
renamed js into js old
Signed-off-by: Jonathan Treffler <mail@jonathan-treffler.de>
Diffstat (limited to 'js-old/directive/NewsTimeout.js')
-rw-r--r-- | js-old/directive/NewsTimeout.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/js-old/directive/NewsTimeout.js b/js-old/directive/NewsTimeout.js new file mode 100644 index 000000000..43a2ad50a --- /dev/null +++ b/js-old/directive/NewsTimeout.js @@ -0,0 +1,45 @@ +/** + * Nextcloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsTimeout', function ($timeout, $rootScope) { + 'use strict'; + + return { + restrict: 'A', + scope: { + '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 () { + destroyed = true; + $timeout.cancel(timer); + }); + + // also delete the entry if undo is ignored and the url + // is changed + $rootScope.$on('$locationChangeStart', function () { + // $locationChangeStart triggers twice because of the trailing + // slash on the link which is kinda a hack to reload the route + // if you click on the link when the route is the same + $timeout.cancel(timer); + if (!destroyed) { + destroyed = true; + element.remove(); + scope.newsTimeout(); + } + }); + } + }; +});
\ No newline at end of file |