From 3cd75e664e7132699847e9b2c95f4afea5bce304 Mon Sep 17 00:00:00 2001 From: "tiago.silva" Date: Tue, 20 Jul 2021 22:12:11 -0300 Subject: [PATCH] improving plugin to work in mobile --- src/directive.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/directive.js b/src/directive.js index fefbed0..0fe437d 100644 --- a/src/directive.js +++ b/src/directive.js @@ -107,15 +107,29 @@ var doBind = function () { directive.scrollListener = throttle(doCheck.bind(directive), directive.throttleDelay); directive.scrollEventTarget.addEventListener('scroll', directive.scrollListener); + //Required for mobile touch scrolling + directive.scrollEventTarget.addEventListener('touchmove', directive.scrollListener); + + /* + * Check if scroll was changed + * For cases when mobile user slide touch fast to end of page + * and the "touchmove" event not fire in finish of scroll + */ + var scrollCheckInterval = setInterval(() => { + directive.scrollListener(); + }, 1000) + this.vm.$on('hook:beforeDestroy', function () { directive.scrollEventTarget.removeEventListener('scroll', directive.scrollListener); + directive.scrollEventTarget.removeEventListener('touchmove', directive.scrollListener); + clearInterval(scrollCheckInterval); }); var disabledExpr = element.getAttribute('infinite-scroll-disabled'); var disabled = false; if (disabledExpr) { - this.vm.$watch(disabledExpr, function(value) { + this.vm.$watch(disabledExpr, function (value) { directive.disabled = value; if (!value && directive.immediateCheck) { doCheck.call(directive); @@ -148,7 +162,7 @@ var doBind = function () { var eventName = element.getAttribute('infinite-scroll-listen-for-event'); if (eventName) { - directive.vm.$on(eventName, function() { + directive.vm.$on(eventName, function () { doCheck.call(directive); }); }