BigW Consortium Gitlab

commits.js.coffee 1.11 KB
Newer Older
1
class @CommitsList
2 3 4 5 6
  @data =
    ref: null
    limit: 0
    offset: 0
  @disable = false
7

8 9
  @showProgress: ->
    $('.loading').show()
10

11 12
  @hideProgress: ->
    $('.loading').hide()
13

14
  @init: (ref, limit) ->
15
    $("body").on "click", ".day-commits-table li.commit", (event) ->
16 17 18 19 20 21 22 23
      if event.target.nodeName != "A"
        location.href = $(this).attr("url")
        e.stopPropagation()
        return false

    @data.ref = ref
    @data.limit = limit
    @data.offset = limit
24

25
    this.initLoadMore()
26
    this.showProgress()
27 28 29 30 31 32 33 34

  @getOld: ->
    this.showProgress()
    $.ajax
      type: "GET"
      url: location.href
      data: @data
      complete: this.hideProgress
35 36 37
      success: (data) ->
        CommitsList.append(data.count, data.html)
      dataType: "json"
38 39 40 41 42 43 44

  @append: (count, html) ->
    $("#commits-list").append(html)
    if count > 0
      @data.offset += count
    else
      @disable = true
45

46
  @initLoadMore: ->
47
    $(document).unbind('scroll')
48 49 50 51 52 53 54 55
    $(document).endlessScroll
      bottomPixels: 400
      fireDelay: 1000
      fireOnce: true
      ceaseFire: =>
        @disable
      callback: =>
        this.getOld()