From 0524db5914bf22568cc56ecbb56fbd41345541a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Fri, 3 Aug 2018 16:25:16 +0200 Subject: New layout fix, scrolling and keyboard shortcuts fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- js/directive/NewsScroll.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'js/directive') 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); }); } }; -- cgit v1.2.3