(function($){
$(document).ready(function (){
$('.rating').raty({
starType:'i' ,
numberMax:post_ratings.number,
number:post_ratings.number,
path:post_ratings.path,
score:function(){
return $(this).data('rating');
},
readOnly:function(){
return $(this).data('readonly');
},
click:function(score, event){
var blocks=$('.post-ratings[data-post="' + $(this).data('post') + '"]');
$.ajax({
url:post_ratings.ajaxURL,
type:'GET',
dataType:'json',
context:this,
data:({
action:'rate_post',
nonce:post_ratings.nonce,
post_id:$(this).data('post'),
rate:score
}),
beforeSend: function (){
blocks.removeClass('error').addClass('loading');
},
error: function(response){
blocks.addClass('error');
},
success: function(response){
if(response.error){
blocks.addClass('error').find('.rating-meta').html(response.error);
return;
}
blocks.find('.rating-meta').replaceWith($('.rating-meta', response.html));
blocks.find('.rating').raty('set', { readOnly: true });
blocks.find('.rating').raty('set', { score: score });
blocks.find('.rating').raty('reload');
blocks.trigger('rated_post', response);
}});
return true;
}});
});
})(jQuery);