summaryrefslogtreecommitdiffstats
path: root/js/directive
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-08-03 16:25:16 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-08-03 16:25:16 +0200
commit0524db5914bf22568cc56ecbb56fbd41345541a6 (patch)
tree561a19d4a7188163bcb3ad2153d72273e72a7767 /js/directive
parentbcd1bed967a5f71a3e05d2247cbf8e53084991d4 (diff)
New layout fix, scrolling and keyboard shortcuts fixes
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'js/directive')
-rw-r--r--js/directive/NewsScroll.js25
1 files changed, 10 insertions, 15 deletions
diff --git a/js/directive/NewsScroll.js b/js/directive/NewsScroll.js
index 53bfcddc8..7092dd2a4 100644
--- a/js/directive/NewsScroll.js
+++ b/js/directive/NewsScroll.js
@@ -44,13 +44,13 @@ app.directive('newsScroll', function ($timeout, ITEM_AUTO_PAGE_SIZE,
var markRead = function (enabled, elem, scope) {
if (enabled) {
var ids = [];
- var articles = elem.find('.item:not(.read)');
+ var articles = elem.querySelectorAll('.item:not(.read)');
- articles.each(function(index, article) {
- var item = $(article);
-
- if (item.position().top <= -10) {
- ids.push(parseInt(item.data('id'), 10));
+ articles.forEach(function(article) {
+ var distTop = article.getBoundingClientRect().top;
+ var scrollTop = $(document).scrollTop();
+ if (distTop - scrollTop <= -10) {
+ ids.push(parseInt(article.dataset.id, 10));
} else {
return false;
}
@@ -71,11 +71,6 @@ app.directive('newsScroll', function ($timeout, ITEM_AUTO_PAGE_SIZE,
},
link: function (scope, elem) {
var allowScroll = true;
- var scrollArea = elem;
-
- if (scope.newsScroll) {
- scrollArea = $(scope.newsScroll);
- }
var scrollHandler = function () {
// allow only one scroll event to trigger every 300ms
@@ -84,7 +79,7 @@ app.directive('newsScroll', function ($timeout, ITEM_AUTO_PAGE_SIZE,
$timeout(function () {
allowScroll = true;
- }, SCROLL_TIMEOUT*1000);
+ }, SCROLL_TIMEOUT * 1000);
autoPage(ITEM_AUTO_PAGE_SIZE, elem, scope);
@@ -96,18 +91,18 @@ app.directive('newsScroll', function ($timeout, ITEM_AUTO_PAGE_SIZE,
// allow user to undo accidental scroll
timer = $timeout(function () {
markRead(scope.newsScrollEnabledMarkRead,
- elem,
+ elem[0],
scope);
timer = undefined;
}, MARK_READ_TIMEOUT*1000);
}
};
- scrollArea.on('scroll', scrollHandler);
+ $(document).on('scroll', scrollHandler);
// remove scroll handler if element is destroyed
scope.$on('$destroy', function () {
- scrollArea.off('scroll', scrollHandler);
+ $(document).off('scroll', scrollHandler);
});
}
};