gitlab-org--gitlab-foss/app/assets/javascripts/pager.js.coffee

45 lines
995 B
CoffeeScript
Raw Normal View History

2013-01-27 11:47:19 -05:00
@Pager =
2016-05-24 19:40:27 -04:00
init: (@limit = 0, preload, @disable = false, @callback = $.noop) ->
@loading = $('.loading').first()
2013-01-27 11:47:19 -05:00
if preload
@offset = 0
@getOld()
else
@offset = @limit
2013-01-27 11:47:19 -05:00
@initLoadMore()
getOld: ->
@loading.show()
2013-01-27 11:47:19 -05:00
$.ajax
type: "GET"
url: $(".content_list").data('href') || location.href
2013-01-27 11:47:19 -05:00
data: "limit=" + @limit + "&offset=" + @offset
complete: =>
@loading.hide()
success: (data) ->
Pager.append(data.count, data.html)
2016-05-24 19:40:27 -04:00
Pager.callback()
dataType: "json"
2013-01-27 11:47:19 -05:00
append: (count, html) ->
$(".content_list").append html
if count > 0
@offset += count
else
@disable = true
initLoadMore: ->
$(document).unbind('scroll')
2013-01-27 11:47:19 -05:00
$(document).endlessScroll
bottomPixels: 400
fireDelay: 1000
fireOnce: true
ceaseFire: ->
Pager.disable
callback: (i) =>
unless @loading.is(':visible')
@loading.show()
Pager.getOld()