diff options
Diffstat (limited to 'app/assets/javascripts/ci/pager.js.coffee')
-rw-r--r-- | app/assets/javascripts/ci/pager.js.coffee | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/app/assets/javascripts/ci/pager.js.coffee b/app/assets/javascripts/ci/pager.js.coffee new file mode 100644 index 00000000000..b57e7c736e9 --- /dev/null +++ b/app/assets/javascripts/ci/pager.js.coffee @@ -0,0 +1,42 @@ +@CiPager = + init: (@url, @limit = 0, preload, @disable = false) -> + if preload + @offset = 0 + @getItems() + else + @offset = @limit + @initLoadMore() + + getItems: -> + $(".loading").show() + $.ajax + type: "GET" + url: @url + data: "limit=" + @limit + "&offset=" + @offset + complete: => + $(".loading").hide() + success: (data) => + Pager.append(data.count, data.html) + dataType: "json" + + append: (count, html) -> + if count > 1 + $(".content-list").append html + if count == @limit + @offset += count + else + @disable = true + + initLoadMore: -> + $(document).unbind('scroll') + $(document).endlessScroll + bottomPixels: 400 + fireDelay: 1000 + fireOnce: true + ceaseFire: -> + Pager.disable + + callback: (i) => + unless $(".loading").is(':visible') + $(".loading").show() + Pager.getItems() |