Commit ce0ec05c6371e055e9cc90e6239cafc015a6a69b

Authored by Dmitriy Zaporozhets
1 parent e3c3c67b

Pager.js to coffee

app/assets/javascripts/pager.js
@@ -1,56 +0,0 @@ @@ -1,56 +0,0 @@
1 -var Pager = {  
2 - limit:0,  
3 - offset:0,  
4 - disable:false,  
5 -  
6 - init:  
7 - function(limit, preload) {  
8 - this.limit=limit;  
9 -  
10 - if(preload) {  
11 - this.offset = 0;  
12 - this.getOld();  
13 - } else {  
14 - this.offset = limit;  
15 - }  
16 -  
17 - this.initLoadMore();  
18 - },  
19 -  
20 - getOld:  
21 - function() {  
22 - $('.loading').show();  
23 - $.ajax({  
24 - type: "GET",  
25 - url: location.href,  
26 - data: "limit=" + this.limit + "&offset=" + this.offset,  
27 - complete: function(){ $('.loading').hide()},  
28 - dataType: "script"});  
29 - },  
30 -  
31 - append:  
32 - function(count, html) {  
33 - $(".content_list").append(html);  
34 - if(count > 0) {  
35 - this.offset += count;  
36 - } else {  
37 - this.disable = true;  
38 - }  
39 - },  
40 -  
41 - initLoadMore:  
42 - function() {  
43 - $(document).endlessScroll({  
44 - bottomPixels: 400,  
45 - fireDelay: 1000,  
46 - fireOnce:true,  
47 - ceaseFire: function() {  
48 - return Pager.disable;  
49 - },  
50 - callback: function(i) {  
51 - $('.loading').show();  
52 - Pager.getOld();  
53 - }  
54 - });  
55 - }  
56 -}  
app/assets/javascripts/pager.js.coffee 0 → 100644
@@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
  1 +@Pager =
  2 + limit: 0
  3 + offset: 0
  4 + disable: false
  5 + init: (limit, preload) ->
  6 + @limit = limit
  7 + if preload
  8 + @offset = 0
  9 + @getOld()
  10 + else
  11 + @offset = limit
  12 + @initLoadMore()
  13 +
  14 + getOld: ->
  15 + $(".loading").show()
  16 + $.ajax
  17 + type: "GET"
  18 + url: location.href
  19 + data: "limit=" + @limit + "&offset=" + @offset
  20 + complete: ->
  21 + $(".loading").hide()
  22 +
  23 + dataType: "script"
  24 +
  25 + append: (count, html) ->
  26 + $(".content_list").append html
  27 + if count > 0
  28 + @offset += count
  29 + else
  30 + @disable = true
  31 +
  32 + initLoadMore: ->
  33 + $(document).endlessScroll
  34 + bottomPixels: 400
  35 + fireDelay: 1000
  36 + fireOnce: true
  37 + ceaseFire: ->
  38 + Pager.disable
  39 +
  40 + callback: (i) ->
  41 + $(".loading").show()
  42 + Pager.getOld()