From b65b27b90bd73817238c5b5f36101f175bec35ef Mon Sep 17 00:00:00 2001 From: Frederic Cambus Date: Mon, 24 Jun 2013 00:12:55 +0200 Subject: [PATCH] Incrementing up/down vote counts after voting news (Close #56) Pull request #56 could not be merged directly, as the markup and the JavaScript code changed. Thanks @stevenleeg. --- app.rb | 3 ++- public/js/app.js | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app.rb b/app.rb index 255be3a..175e42c 100644 --- a/app.rb +++ b/app.rb @@ -1670,7 +1670,8 @@ def news_to_html(news) "▼" }+ H.p { - "#{news["up"]} up and #{news["down"]} down, posted by "+ + H.span(:class => :upvotes) { news["up"] } + " up and " + + H.span(:class => :downvotes) { news["down"] } + " down, posted by " + H.username { H.a(:href=>"/user/"+H.urlencode(news["username"])) { H.entities news["username"] diff --git a/public/js/app.js b/public/js/app.js index 76d4cbf..eb92b10 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -227,6 +227,10 @@ function handle_voting(item_type,vote_type,item_id,callback) { success: function(r) { if (r.status == "ok") { var article = $('article[data-'+item_type+'-id="'+item_id+'"]'); + if (item_type == "news") { + var vote_count = $('article[data-'+item_type+'-id="'+item_id+'"] .'+vote_type+'votes'); + vote_count.text(parseInt(vote_count.text(), 10) + 1); + } article.find(".uparrow").addClass(uparrowClass); article.find(".downarrow").addClass(downarrowClass); if (typeof(callback) == 'function') {