Pager.js to coffee
This commit is contained in:
parent
e3c3c67b25
commit
ce0ec05c63
2 changed files with 42 additions and 56 deletions
42
app/assets/javascripts/pager.js.coffee
Normal file
42
app/assets/javascripts/pager.js.coffee
Normal file
|
@ -0,0 +1,42 @@
|
|||
@Pager =
|
||||
limit: 0
|
||||
offset: 0
|
||||
disable: false
|
||||
init: (limit, preload) ->
|
||||
@limit = limit
|
||||
if preload
|
||||
@offset = 0
|
||||
@getOld()
|
||||
else
|
||||
@offset = limit
|
||||
@initLoadMore()
|
||||
|
||||
getOld: ->
|
||||
$(".loading").show()
|
||||
$.ajax
|
||||
type: "GET"
|
||||
url: location.href
|
||||
data: "limit=" + @limit + "&offset=" + @offset
|
||||
complete: ->
|
||||
$(".loading").hide()
|
||||
|
||||
dataType: "script"
|
||||
|
||||
append: (count, html) ->
|
||||
$(".content_list").append html
|
||||
if count > 0
|
||||
@offset += count
|
||||
else
|
||||
@disable = true
|
||||
|
||||
initLoadMore: ->
|
||||
$(document).endlessScroll
|
||||
bottomPixels: 400
|
||||
fireDelay: 1000
|
||||
fireOnce: true
|
||||
ceaseFire: ->
|
||||
Pager.disable
|
||||
|
||||
callback: (i) ->
|
||||
$(".loading").show()
|
||||
Pager.getOld()
|
Loading…
Add table
Add a link
Reference in a new issue