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

Adding ability to unbind scroll handler and destroy plugin object #25

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
14 changes: 12 additions & 2 deletions app/assets/javascripts/jquery.infinite-pages.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Released under the MIT License
scrollTimeout = null
scrollHandler = (=> @check())

@$context.scroll ->
# Use namespace to let us unbind event handler
@$context.on 'scroll.infinitePages', ->
if scrollTimeout
clearTimeout(scrollTimeout)
scrollTimeout = null
Expand Down Expand Up @@ -113,6 +114,11 @@ Released under the MIT License
@_log "Scroll checks resumed"
@check()

# Stop event handling
stop: ->
@$context.off 'scroll.infinitePages'
@_log "Scroll checks stopped"

# Define the plugin
$.fn.extend infinitePages: (option, args...) ->
@each ->
Expand All @@ -122,6 +128,10 @@ Released under the MIT License
if !data
$this.data 'infinitepages', (data = new InfinitePages(this, option))
if typeof option == 'string'
data[option].apply(data, args)
if option == 'destroy'
data.stop args
$this.removeData 'infinitepages'
else
data[option].apply(data, args)

) window.jQuery, window