Skip to content
This repository has been archived by the owner on Sep 25, 2022. It is now read-only.

Commit

Permalink
kudos js no longer requests when no posts on page
Browse files Browse the repository at this point in the history
  • Loading branch information
masukomi committed Aug 29, 2012
1 parent 90a91bf commit 76dd426
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions app/assets/javascripts/kudos.js.erb
Expand Up @@ -49,27 +49,30 @@ $(function() {
});
// request a list of the current counts for those posts
var kudos_hash = {};
var url = "/kudos/count/" + post_ids.join(',') + '.json';
$.getJSON(url, function(data) {
var items = [];
$.each(data, function(key, value) {
kudos_hash[key] = value;
var text = value != 1 ? ' Kudos' : ' Kudo';
$('#kudo-'+key+'-count')[0].innerText = value + text;
if (post_ids.length > 0) {
var url = "/kudos/count/" + post_ids.join(',') + '.json';
$.getJSON(url, function(data) {
var items = [];
$.each(data, function(key, value) {
kudos_hash[key] = value;
var text = value != 1 ? ' Kudos' : ' Kudo';
$('#kudo-'+key+'-count')[0].innerText = value + text;
});
});
});



$("a.kudos").each(function(e) {
// test if they've already left a kudo for each article by
// checking their cookies.
// TODO: this WILL fail when you hit the max number of cookies for a site.
// remove their ability to give it a kudo if they've already done so.
var id = $(this).closest("article").attr("id");
if ($.cookie(id)){
$(this).removeClass("animate").removeClass("kudoable").addClass("completed").removeClass('icon-heart-empty').addClass('icon-heart');
} // otherwise the cookie is null and they haven't given a kudo
});
$("a.kudos").each(function(e) {
// test if they've already left a kudo for each article by
// checking their cookies.
// TODO: this WILL fail when you hit the max number of cookies for a site.
// remove their ability to give it a kudo if they've already done so.
var id = $(this).closest("article").attr("id");
if ($.cookie(id)){
$(this).removeClass("animate").removeClass("kudoable").addClass("completed").removeClass('icon-heart-empty').addClass('icon-heart');
} // otherwise the cookie is null and they haven't given a kudo
});

}
}

);

0 comments on commit 76dd426

Please sign in to comment.