Skip to content

Commit

Permalink
Incrementing up/down vote counts after voting news (Close #56)
Browse files Browse the repository at this point in the history
Pull request #56 could not be merged directly, as the markup and the
JavaScript code changed. Thanks @stevenleeg.
  • Loading branch information
fcambus committed Jun 23, 2013
1 parent 0a28b64 commit b65b27b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 4 additions & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit b65b27b

Please sign in to comment.