From 1d54ddeb9bde88f68729be20e128a9e9dc5982a9 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 2 Dec 2012 16:57:36 +0100 Subject: [PATCH 1/3] Converted commits.js to coffeescript --- app/assets/javascripts/commits.js | 59 ------------------------ app/assets/javascripts/commits.js.coffee | 54 ++++++++++++++++++++++ app/views/commits/show.html.haml | 4 +- app/views/commits/show.js.haml | 2 +- 4 files changed, 57 insertions(+), 62 deletions(-) delete mode 100644 app/assets/javascripts/commits.js create mode 100644 app/assets/javascripts/commits.js.coffee diff --git a/app/assets/javascripts/commits.js b/app/assets/javascripts/commits.js deleted file mode 100644 index b31fe485896..00000000000 --- a/app/assets/javascripts/commits.js +++ /dev/null @@ -1,59 +0,0 @@ -var CommitsList = { - ref:null, - limit:0, - offset:0, - disable:false, - - init: - function(ref, limit) { - $(".day-commits-table li.commit").live('click', function(e){ - if(e.target.nodeName != "A") { - location.href = $(this).attr("url"); - e.stopPropagation(); - return false; - } - }); - - this.ref=ref; - this.limit=limit; - this.offset=limit; - this.initLoadMore(); - $('.loading').show(); - }, - - getOld: - function() { - $('.loading').show(); - $.ajax({ - type: "GET", - url: location.href, - data: "limit=" + this.limit + "&offset=" + this.offset + "&ref=" + this.ref, - complete: function(){ $('.loading').hide()}, - dataType: "script"}); - }, - - append: - function(count, html) { - $("#commits_list").append(html); - if(count > 0) { - this.offset += count; - } else { - this.disable = true; - } - }, - - initLoadMore: - function() { - $(document).endlessScroll({ - bottomPixels: 400, - fireDelay: 1000, - fireOnce:true, - ceaseFire: function() { - return CommitsList.disable; - }, - callback: function(i) { - CommitsList.getOld(); - } - }); - } -} diff --git a/app/assets/javascripts/commits.js.coffee b/app/assets/javascripts/commits.js.coffee new file mode 100644 index 00000000000..92ca4eb7db9 --- /dev/null +++ b/app/assets/javascripts/commits.js.coffee @@ -0,0 +1,54 @@ +class CommitsList + @data = + ref: null + limit: 0 + offset: 0 + @disable = false + + @showProgress: -> + $('.loading').show() + + @hideProgress: -> + $('.loading').show() + + @init: (ref, limit) -> + $(".day-commits-table li.commit").live 'click', (event) -> + if event.target.nodeName != "A" + location.href = $(this).attr("url") + e.stopPropagation() + return false + + @data.ref = ref + @data.limit = limit + @data.offset = limit + + this.initLoadMore() + this.showProgress(); + + @getOld: -> + this.showProgress() + $.ajax + type: "GET" + url: location.href + data: @data + complete: this.hideProgress + dataType: "script" + + @append: (count, html) -> + $("#commits-list").append(html) + if count > 0 + @data.offset += count + else + @disable = true + + @initLoadMore: -> + $(document).endlessScroll + bottomPixels: 400 + fireDelay: 1000 + fireOnce: true + ceaseFire: => + @disable + callback: => + this.getOld() + +this.CommitsList = CommitsList \ No newline at end of file diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml index 9451a038df0..f066f25b8bb 100644 --- a/app/views/commits/show.html.haml +++ b/app/views/commits/show.html.haml @@ -5,13 +5,13 @@ = breadcrumbs %div{id: dom_id(@project)} - #commits_list= render "commits" + #commits-list= render "commits" .clear .loading{ style: "display:none;"} - if @commits.count == @limit :javascript $(function(){ - CommitsList.init("#{@ref}", #{@limit}); + CommitList.init("#{@ref}", #{@limit}); }); diff --git a/app/views/commits/show.js.haml b/app/views/commits/show.js.haml index 797bc14cc1b..9ea2b7756e4 100644 --- a/app/views/commits/show.js.haml +++ b/app/views/commits/show.js.haml @@ -1,3 +1,3 @@ :plain - CommitsList.append(#{@commits.count}, "#{escape_javascript(render(partial: 'commits/commits'))}"); + CommitList.append(#{@commits.count}, "#{escape_javascript(render(partial: 'commits/commits'))}"); -- GitLab From 394c01ffe988d959ccddd7bb3736aa21bb0be029 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 2 Dec 2012 18:59:46 +0100 Subject: [PATCH 2/3] CommitList back to CommitsList --- app/views/commits/show.html.haml | 2 +- app/views/commits/show.js.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml index f066f25b8bb..d180b8ec426 100644 --- a/app/views/commits/show.html.haml +++ b/app/views/commits/show.html.haml @@ -12,6 +12,6 @@ - if @commits.count == @limit :javascript $(function(){ - CommitList.init("#{@ref}", #{@limit}); + CommitsList.init("#{@ref}", #{@limit}); }); diff --git a/app/views/commits/show.js.haml b/app/views/commits/show.js.haml index 9ea2b7756e4..797bc14cc1b 100644 --- a/app/views/commits/show.js.haml +++ b/app/views/commits/show.js.haml @@ -1,3 +1,3 @@ :plain - CommitList.append(#{@commits.count}, "#{escape_javascript(render(partial: 'commits/commits'))}"); + CommitsList.append(#{@commits.count}, "#{escape_javascript(render(partial: 'commits/commits'))}"); -- GitLab From 13de6b31356753b2d95c5bf09720d1884a3fd7ce Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 2 Dec 2012 19:01:04 +0100 Subject: [PATCH 3/3] show/hide fixup --- app/assets/javascripts/commits.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/commits.js.coffee b/app/assets/javascripts/commits.js.coffee index 92ca4eb7db9..47d6fcf8089 100644 --- a/app/assets/javascripts/commits.js.coffee +++ b/app/assets/javascripts/commits.js.coffee @@ -9,7 +9,7 @@ class CommitsList $('.loading').show() @hideProgress: -> - $('.loading').show() + $('.loading').hide() @init: (ref, limit) -> $(".day-commits-table li.commit").live 'click', (event) -> -- GitLab