From ad701076c12795609d0c6ae0cb9b40a001726dea Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 15 Sep 2014 15:37:43 +0200 Subject: add pull to refresh --- js/directive/NewsPullToRefresh.js | 36 ++++++++++++++++++++++++++++++++++++ js/directive/NewsTimeout.js | 3 ++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 js/directive/NewsPullToRefresh.js (limited to 'js/directive') diff --git a/js/directive/NewsPullToRefresh.js b/js/directive/NewsPullToRefresh.js new file mode 100644 index 000000000..7938a8f63 --- /dev/null +++ b/js/directive/NewsPullToRefresh.js @@ -0,0 +1,36 @@ +/** + * ownCloud - News + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt + * @copyright Bernhard Posselt 2014 + */ +app.directive('newsPullToRefresh', function ($route, $rootScope) { + 'use strict'; + + var scrolled = false; + + return { + restrict: 'A', + scope: { + 'newsTimeout': '&' + }, + link: function (scope, element) { + + // change in the route means the content is refreshed + // so reset the var + $rootScope.$on('$routeChangeStart', function () { + scrolled = false; + }); + + element.on('scroll', function () { + if (element.scrollTop() === 0 && scrolled) { + $route.reload(); + } + scrolled = true; + }); + } + }; +}); \ No newline at end of file diff --git a/js/directive/NewsTimeout.js b/js/directive/NewsTimeout.js index 2d88f4363..43c6290a3 100644 --- a/js/directive/NewsTimeout.js +++ b/js/directive/NewsTimeout.js @@ -25,7 +25,8 @@ app.directive('newsTimeout', function ($timeout, $rootScope) { $timeout.cancel(timer); }); - // route change also triggers the timeout + // also delete the entry if undo is ignored and the url + // is changed $rootScope.$on('$locationChangeStart', function () { element.remove(); }); -- cgit v1.2.3