2016-01-10 14:41:20 +01:00
|
|
|
# Automatic ajax pagination
|
2016-01-18 00:24:53 +01:00
|
|
|
|
|
|
|
# To not setup pagination twice
|
|
|
|
pager = true
|
2016-07-02 16:48:47 +02:00
|
|
|
$(document).on 'turbolinks:load', ->
|
2016-01-10 14:41:20 +01:00
|
|
|
$('.pagination .next a')
|
|
|
|
.attr('data-remote', true)
|
|
|
|
.click ->
|
|
|
|
$('#loading').fadeIn()
|
|
|
|
|
2016-01-18 00:24:53 +01:00
|
|
|
if pager
|
|
|
|
pager = false
|
|
|
|
$(document).on 'ajax:success', '.pagination .next a', (event, data, status, xhr) ->
|
|
|
|
$('#loading').fadeOut()
|
|
|
|
elts = $('tbody tr', data)
|
|
|
|
$(this).parents('tfoot').prev().append(elts)
|
2016-01-10 14:41:20 +01:00
|
|
|
|
2016-01-18 00:24:53 +01:00
|
|
|
next = $('.pagination .next a', data).attr('href')
|
|
|
|
if next?
|
|
|
|
return $(this).show().data('remote', true).attr('href', next)
|
|
|
|
else
|
|
|
|
return $(this).parents('.pagination').remove()
|
2016-01-10 14:41:20 +01:00
|
|
|
|
|
|
|
# Go to the next page when page is scrolled
|
2018-07-16 22:43:36 +02:00
|
|
|
$(document).scroll ->
|
|
|
|
$('.pagination .next a:visible').filter =>
|
|
|
|
this.visible()
|
|
|
|
.hide().click() # "Next" link is hidden while pagination is done
|