Skip to content

Commit

Permalink
allow to stop/reinit plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
zhisme committed May 20, 2018
1 parent 6d3d48a commit a3a8f4a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/assets/javascripts/jquery.infinite-pages.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@ Released under the MIT License

# Setup and bind to related events
init: ->

# Debounce scroll event to improve performance
scrollTimeout = null
scrollHandler = (=> @check())

@$context.scroll ->
if scrollTimeout
# Use namespace to let us unbind event handler
@$context.on 'scroll.infinitePages', ->
if scrollTimeout && self.active
clearTimeout(scrollTimeout)
scrollTimeout = null
scrollTimeout = setTimeout(scrollHandler, 250)

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

# Internal helper for logging messages
_log: (msg) ->
console?.log(msg) if @options.debug
Expand Down Expand Up @@ -128,6 +132,12 @@ 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 if option == 'reinit'
data.init args
else
data[option].apply(data, args)

) window.jQuery, window

0 comments on commit a3a8f4a

Please # to comment.