Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurable debounce #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/assets/javascripts/jquery.infinite-pages.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Released under the MIT License
debug: false # set to true to log messages to the console
navSelector: 'a[rel=next]'
buffer: 1000 # 1000px buffer by default
debounce: 250 # 250ms debounce by default
loading: null # optional callback when next-page request begins
success: null # optional callback when next-page request finishes
error: null # optional callback when next-page request fails
Expand All @@ -43,12 +44,13 @@ Released under the MIT License
# Debounce scroll event to improve performance
scrollTimeout = null
scrollHandler = (=> @check())
debounce = @options.debounce

@$context.scroll ->
if scrollTimeout
clearTimeout(scrollTimeout)
scrollTimeout = null
scrollTimeout = setTimeout(scrollHandler, 250)
scrollTimeout = setTimeout(scrollHandler, debounce)

# Internal helper for logging messages
_log: (msg) ->
Expand Down