pager.js.coffee 884 字节
Newer Older
D
Dmitriy Zaporozhets 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
@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()
22 23 24
      success: (data) ->
        Pager.append(data.count, data.html)
      dataType: "json"
D
Dmitriy Zaporozhets 已提交
25 26 27 28 29 30 31 32 33

  append: (count, html) ->
    $(".content_list").append html
    if count > 0
      @offset += count
    else
      @disable = true

  initLoadMore: ->
34
    $(document).unbind('scroll')
D
Dmitriy Zaporozhets 已提交
35 36 37 38 39 40 41 42 43 44
    $(document).endlessScroll
      bottomPixels: 400
      fireDelay: 1000
      fireOnce: true
      ceaseFire: ->
        Pager.disable

      callback: (i) ->
        $(".loading").show()
        Pager.getOld()