From 63941ece19544b13eaa7905ae6913aac213629a0 Mon Sep 17 00:00:00 2001 From: Ben Dilley Date: Tue, 21 Sep 2021 14:13:30 +0100 Subject: [PATCH] Unbind scroll event when reinstantiated Scroll trigger would only take effect on first load: navigating back to the same page would fail to auto-load the next page on scroll. Solution from: https://github.com/magoosh/jquery-infinite-pages/pull/24 --- app/assets/javascripts/jquery.infinite-pages.js.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/javascripts/jquery.infinite-pages.js.coffee b/app/assets/javascripts/jquery.infinite-pages.js.coffee index af8b7ca..a0f316d 100644 --- a/app/assets/javascripts/jquery.infinite-pages.js.coffee +++ b/app/assets/javascripts/jquery.infinite-pages.js.coffee @@ -147,6 +147,8 @@ Released under the MIT License # Have we waited enough time since the last check? shouldCheck = -> +new Date > lastCheckAt + scrollDelay + console.log "Unbinding..." + @$context.unbind('scroll') @$context.scroll -> scrollHandler() if shouldCheck() # Call check once every scrollDelay ms if scrollTimeout