summaryrefslogtreecommitdiffstats
path: root/js/directive
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-09-13 16:58:38 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-09-13 16:58:38 +0200
commit08df2433cad543587458a64a0b81122e1f966cb8 (patch)
tree466125e54bba6ca99bf695a4274722c7284fa36e /js/directive
parent11c4b03d70583d8b4c7e7bce408a3c3a3d9c1f17 (diff)
autopaging
Diffstat (limited to 'js/directive')
-rw-r--r--js/directive/NewsScroll.js59
1 files changed, 30 insertions, 29 deletions
diff --git a/js/directive/NewsScroll.js b/js/directive/NewsScroll.js
index e93c7091d..c0b345163 100644
--- a/js/directive/NewsScroll.js
+++ b/js/directive/NewsScroll.js
@@ -9,34 +9,33 @@
*/
app.directive('newsScroll', function ($timeout) {
'use strict';
+ var timer;
// autopaging
- var autoPage = function (enabled, limit, elem, scope) {
- if (enabled) {
- var counter = 0;
- var articles = elem.find('.item');
-
- for (var i = articles.length - 1; i >= 0; i -= 1) {
- var item = $(articles[i]);
+ var autoPage = function (limit, elem, scope) {
+ var counter = 0;
+ var articles = elem.find('.item');
+ for (var i = articles.length - 1; i >= 0; i -= 1) {
+ var item = $(articles[i]);
- // if the counter is higher than the size it means
- // that it didnt break to auto page yet and that
- // there are more items, so break
- if (counter >= limit) {
- break;
- }
- // this is only reached when the item is not is
- // below the top and we didnt hit the factor yet so
- // autopage and break
- if (item.position().top < 0) {
- scope.$apply(scope.newsScrollAutoPage);
- break;
- }
+ // if the counter is higher than the size it means
+ // that it didnt break to auto page yet and that
+ // there are more items, so break
+ if (counter >= limit) {
+ break;
+ }
- counter += 1;
+ // this is only reached when the item is not is
+ // below the top and we didnt hit the factor yet so
+ // autopage and break
+ if (item.position().top < 0) {
+ scope.$apply(scope.newsScrollAutoPage);
+ break;
}
+
+ counter += 1;
}
};
@@ -68,7 +67,6 @@ app.directive('newsScroll', function ($timeout) {
'newsScrollAutoPage': '&',
'newsScrollMarkRead': '&',
'newsScrollEnabledMarkRead': '=',
- 'newsScrollEnabledAutoPage': '=',
'newsScrollMarkReadTimeout': '@', // optional, defaults to 1 second
'newsScrollTimeout': '@', // optional, defaults to 1 second
'newsScrollAutoPageWhenLeft': '@' // optional, defaults to 50
@@ -86,24 +84,27 @@ app.directive('newsScroll', function ($timeout) {
var autoPageLimit = scope.newsScrollAutoPageWhenLeft || 50;
var scrollHandler = function () {
- // allow only one scroll event to trigger at once
+ // allow only one scroll event to trigger every 300ms
if (allowScroll) {
allowScroll = false;
$timeout(function () {
allowScroll = true;
- }, scrollTimeout*1000);
+ }, scrollTimeout*100);
- autoPage(scope.newsScrollEnabledAutoPage,
- autoPageLimit,
- elem,
- scope);
+ autoPage(autoPageLimit, elem, scope);
+
+ // dont stack mark read requests
+ if (timer) {
+ $timeout.cancel(timer);
+ }
// allow user to undo accidental scroll
- $timeout(function () {
+ timer = $timeout(function () {
markRead(scope.newsScrollEnabledMarkRead,
elem,
scope);
+ timer = undefined;
}, markReadTimeout*1000);
}
};