Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refresh counters on gem show pages

  • Loading branch information...
commit 7d3a3de73ddc262f0dce9a5c1d124916abacd27a 1 parent 7e17a05
@nate nate authored
View
2  app/views/rubygems/show.html.erb
@@ -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>
View
11 public/javascripts/application.js
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.