Permalink
Browse files

Refresh counters on gem show pages

  • Loading branch information...
1 parent 7e17a05 commit 7d3a3de73ddc262f0dce9a5c1d124916abacd27a @nate nate committed Sep 4, 2010
Showing with 12 additions and 1 deletion.
  1. +1 −1 app/views/rubygems/show.html.erb
  2. +11 −0 public/javascripts/application.js
@@ -67,7 +67,7 @@
<% end %>
</div>
- <div class="downloads">
+ <div class="downloads counter" data-href="<%= api_v1_download_path(@rubygem, :format => 'json') %>">
<span>
<strong><%= number_with_delimiter(@rubygem.downloads) %></strong> total downloads
</span>
@@ -23,6 +23,17 @@ $(document).ready(function() {
});
}, 5000);
}
+
+ if ($('.downloads.counter').length > 0) {
+ setInterval(function() {
+ $.getJSON($('.downloads.counter').attr('data-href'), function(data) {
+ $('.downloads.counter strong:first')
+ .text(number_with_delimiter(data['total_downloads']));
+ $('.downloads.counter strong:last')
+ .text(number_with_delimiter(data['latest_version_downloads']));
+ });
+ }, 5000);
+ }
});
// http://kevinvaldek.com/number-with-delimiter-in-javascript

0 comments on commit 7d3a3de

Please sign in to comment.