Simplified automatic pagination
This commit is contained in:
parent
244a0a8fce
commit
e712c99138
@ -11,6 +11,7 @@
|
|||||||
# about supported directives.
|
# about supported directives.
|
||||||
#
|
#
|
||||||
#= require jquery3
|
#= require jquery3
|
||||||
|
#= require jquery_ujs
|
||||||
#= require jquery-sparkline
|
#= require jquery-sparkline
|
||||||
# For tags input
|
# For tags input
|
||||||
#= require jquery-ui/widgets/autocomplete
|
#= require jquery-ui/widgets/autocomplete
|
||||||
|
@ -1,28 +1,15 @@
|
|||||||
# Automatic ajax pagination
|
# Automatic ajax pagination
|
||||||
|
|
||||||
# To not setup pagination twice
|
|
||||||
pager = true
|
|
||||||
$(document).on 'turbolinks:load', ->
|
$(document).on 'turbolinks:load', ->
|
||||||
$('.pagination .next a')
|
$('.pagination .next a').attr('data-remote', true).each ->
|
||||||
.attr('data-remote', true)
|
|
||||||
.click ->
|
|
||||||
$('#loading').fadeIn()
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
next = $('.pagination .next a', data).attr('href')
|
|
||||||
if next?
|
|
||||||
return $(this).show().data('remote', true).attr('href', next)
|
|
||||||
else
|
|
||||||
return $(this).parents('.pagination').remove()
|
|
||||||
|
|
||||||
# Go to the next page when page is scrolled
|
# Go to the next page when page is scrolled
|
||||||
$(document).scroll ->
|
$(document).scroll =>
|
||||||
$('.pagination .next a:visible').filter =>
|
if $(this).visible true, true
|
||||||
this.visible()
|
# "Next" link is also hidden while pagination is done
|
||||||
.hide().click() # "Next" link is hidden while pagination is done
|
$(this).click().parents('.pagination').hide()
|
||||||
|
|
||||||
|
$(document).on 'ajax:success', '.pagination .next a', (event, data) ->
|
||||||
|
$(this).parents('tfoot').prev().append $('tbody tr', data)
|
||||||
|
|
||||||
|
next = $('.pagination .next a', data).attr 'href'
|
||||||
|
if next?
|
||||||
|
$(this).attr('href', next).parents('.pagination').show()
|
||||||
|
Loading…
Reference in New Issue
Block a user