Шаблон с голосованиями
{exp:weblog:entries...}
{exp:rating:form form_name="Gallery Ratings" required="rating" require_membership="no" anonymous="yes" allow_duplicates="no" entry_id="{entry_id}" return="/{my_weblog}/{segment_2}" template="{my_template_group}/rating_ajax_submit_result" class="rating-form"}
<input type="hidden" name="entry_url_title" value="{entry_id}" />
<input type="hidden" name="rating" id="rating_inpt_id{entry_id}" value="" />
<input type="hidden" name="submit" />
{if not_duplicate}
<b class="not_duplicate"></b>
{if:elseif duplicate}
<b class="duplicate"></b>
{/if}
{/exp:rating:form}
<div id="rating{entry_id}" class="stars">
{exp:rating:stats entry_id="{entry_id}" theme="default"}
<b>{stars_overall_avg}</b>
<span>{overall_count} {exp:plural_forms digit="{overall_count}" words="голос|голоса|голосов" onlyword="true"}</span>
{/exp:rating:stats}
{exp:rating:count entry_id="{entry_id}"}
{if rating_count==0}
<b><img class="rating_star" src="/themes/rating_themes/default/images/star-0.gif"/><img class="rating_star" src="/themes/rating_themes/default/images/star-0.gif"/><img class="rating_star" src="/themes/rating_themes/default/images/star-0.gif"/><img class="rating_star" src="/themes/rating_themes/default/images/star-0.gif"/><img class="rating_star" src="/themes/rating_themes/default/images/star-0.gif"/></b>
<span>{rating_count}{exp:plural_forms digit="{rating_count}" words="голос|голоса|голосов" onlyword="true"}</span>
{/if}
{/exp:rating:count}
</div>
{/exp:weblog:entries}
Шаблон rating_ajax_submit_result
{if success}OK{/if}{if failure}{message}{/if}
Шаблон rating_ajax_return_value
{exp:weblog:entries weblog="{my_weblog}" limit="1"}
{exp:rating:stats entry_id="{entry_id}" theme="default"}
{stars_overall_avg}
<span>{overall_count} {exp:plural_forms digit="{overall_count}" words="голос|голоса|голосов" onlyword="true"}</span>
{/exp:rating:stats}
{/exp:weblog:entries}
JS (из библиотек понадобится jquery, плагин jquery forms и плагин jgrowl) код написан под структуру html выше
$(document).ready(function() {
$(".rating-form").submit(function() {
if($("b",this).attr('class')=='not_duplicate'){
var id = $("input[name=entry_url_title]",this).val();
$("#rating"+id+" span").html('<img src="/images/loading.gif" width="16" height="16">');
$(this).ajaxSubmit({
success: function(responseText, statusText){
var url = "/rating_ajax_return_value/" + id;
if(responseText == "OK"){
$.get(url, function(data){
$("#rating"+id).fadeOut("normal", function(){
$(this).empty().append(data).fadeIn();
});
});
} else {
$.jGrowl(responseText, {
life :5000
});
$.get(url, function(data){
$("#rating"+id).empty().append(data);
});
}
}
})
}
return false;
});
//css
$("div.stars").prev('.rating-form').children('b.duplicate').parent('.rating-form').next("div.stars").children('b').children('img').css('cursor','default');
// rolls
$("div.stars b img").hover(function() {
var id=$(this).parent('b').children('img').index(this)+1;
var entry_id=$(this).parent('b').parent('.stars').attr('id').replace(/rating(.+)$/i, "$1");
if($("b",$('#rating_form'+entry_id)).attr('class')=='not_duplicate'){
var o = $(this).parent('b').children('img:lt('+id+')');
o.attr("src", o.attr("rel").replace(/-[0-9]+\.(.+)$/i, ".$1"));
}
}, function() {
$(this).parent('b').children('img').each(function (i) { $(this).attr('src',$(this).attr("rel")); });
}).each(function (i) {
$(this).attr('rel',$(this).attr("src"));
}).click(function(){
var id=$(this).parent('b').children('img').index(this)+1;
var entry_id=$(this).parent('b').parent('.stars').attr('id').replace(/rating(.+)$/i, "$1");
$('#rating_inpt_id'+entry_id).val(id);
$('#rating_form'+entry_id).submit();
});
});