From 5d961dad69124ad0795c286f05b1d0c956d3de6f 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/jquery.infinite-pages.js.coffee b/app/assets/javascripts/jquery.infinite-pages.js.coffee index af8b7ca..c48bc57 100644 --- a/app/assets/javascripts/jquery.infinite-pages.js.coffee +++ b/app/assets/javascripts/jquery.infinite-pages.js.coffee @@ -147,6 +147,7 @@ Released under the MIT License # Have we waited enough time since the last check? shouldCheck = -> +new Date > lastCheckAt + scrollDelay + @$context.unbind('scroll') @$context.scroll -> scrollHandler() if shouldCheck() # Call check once every scrollDelay ms if scrollTimeout