pager.js.coffee 906 字节
Newer Older
D
Dmitriy Zaporozhets 已提交
1
@Pager =
2 3
  init: (@limit = 0, preload, @disable = false) ->
    @loading = $(".loading")
D
Dmitriy Zaporozhets 已提交
4 5 6 7
    if preload
      @offset = 0
      @getOld()
    else
8
      @offset = @limit
D
Dmitriy Zaporozhets 已提交
9 10 11
    @initLoadMore()

  getOld: ->
12
    @loading.show()
D
Dmitriy Zaporozhets 已提交
13 14 15 16
    $.ajax
      type: "GET"
      url: location.href
      data: "limit=" + @limit + "&offset=" + @offset
17 18
      complete: =>
        @loading.hide()
19 20 21
      success: (data) ->
        Pager.append(data.count, data.html)
      dataType: "json"
D
Dmitriy Zaporozhets 已提交
22 23 24 25 26 27 28 29 30

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

  initLoadMore: ->
31
    $(document).unbind('scroll')
D
Dmitriy Zaporozhets 已提交
32 33 34 35 36 37 38
    $(document).endlessScroll
      bottomPixels: 400
      fireDelay: 1000
      fireOnce: true
      ceaseFire: ->
        Pager.disable

39 40 41 42
      callback: (i) =>
        unless @loading.is(':visible')
          @loading.show()
          Pager.getOld()