/**
* jQuery Ajax Rater Plugin modified
*
* This rater is based on the code Ritesh Agrawal did. Unfortunatly his CSS and the hover technique breaks in some browsers.
* So i thought, why not use the best CSS star-rater known to man kind and throw it in the mix.
* I have used the CSS and technique from Komodo Media since it is stable and tested on many, many browsers.
*
* This rater compared, has no cancel button. But i think we can live with that :)
* To avoid conflicts i have changed the function name.
*
* Licensed under The MIT License
*
* @version 1.0
* @since 03.01.2007
* @author Kjell Bublitz 1) ? true : false});
var container = $(this);
$.extend(container, { averageRating: settings.curvalue, url: settings.url });
if(!settings.style || settings.style == null || settings.style == 'basic') {
var raterwidth = settings.maxvalue * 25;
var ratingparent = '';
}
if(settings.style == 'small') {
var raterwidth = settings.maxvalue * 10;
var ratingparent = '';
}
if(settings.style == 'inline') {
var raterwidth = settings.maxvalue * 10;
var ratingparent = '';
}
container.append(ratingparent);
// create rater
var starWidth, starIndex, listitems = '';
var curvalueWidth = Math.floor(100 / settings.maxvalue * settings.curvalue);
for(var i = 0; i <= settings.maxvalue ; i++) {
if (i == 0) {
listitems+='- '+settings.curvalue+'/'+settings.maxvalue+'
';
} else {
starWidth = Math.floor(100 / settings.maxvalue * i);
starIndex = (settings.maxvalue - i) + 2;
listitems+='- '+i+'
';
}
}
container.find('.star-'+settings.image+'').append(listitems); // i am using find here, because the span wrapped in the small style would break children()
if(settings.maxvalue > 1) { // add a container for the ajax result
container.append('');
}
var stars = $(container).find('.star-'+settings.image+'').children('.star');
stars.click(function() {
if(settings.maxvalue == 1) { // on / off
settings.curvalue = (settings.curvalue == 0) ? 1 : 0;
$(container).find('.star-'+settings.image+'').children('.current-rating').css({width:(settings.curvalue*100)+'%'});
$.post(container.url, { "user_rating": settings.curvalue, "article_id": settings.article_id });
return false;
}
else {
switch(settings.setup) {
case 'login_first':
$('img#cd_ajaxvote_loading_' + settings.article_id + '').slideDown(1000);
ajax_timeout = setTimeout(function() {
$.ajax({
type: 'POST',
url: container.url,
data: 'plgCdAjaxvoteAction=login_first',
success: function(msg) {
$('div#cd_ajaxvote_status_' + settings.article_id + '').html(msg).show(1000);
$('img#cd_ajaxvote_loading_' + settings.article_id + '').hide(1000);
t = setTimeout( function () {
$('div#cd_ajaxvote_status_' + settings.article_id + '').hide(1000);
}, 2000);
}
});
}, 2000);
break;
case 'intro_only':
$('img#cd_ajaxvote_loading_' + settings.article_id + '').slideDown(1000);
ajax_timeout = setTimeout(function() {
$.ajax({
type: 'POST',
url: container.url,
data: 'plgCdAjaxvoteAction=intro_only',
success: function(msg) {
$('div#cd_ajaxvote_status_' + settings.article_id + '').html(msg).show(1000);
$('img#cd_ajaxvote_loading_' + settings.article_id + '').hide(1000);
t = setTimeout( function () {
$('div#cd_ajaxvote_status_' + settings.article_id + '').hide(1000);
}, 2000);
}
});
}, 2000);
break;
case 'vote':
settings.curvalue = stars.index(this) + 1;
raterValue = $(this).children('a')[0].href.split('#')[1];
$('img#cd_ajaxvote_loading_' + settings.article_id + '').slideDown(1000);
ajax_timeout = setTimeout(function() {
$.ajax({
type: 'POST',
url: container.url,
async: false,
data: 'plgCdAjaxvoteAction=update&user_rating=' + raterValue + '&article_id=' + settings.article_id,
success: function(msg) {
$('div#cd_ajaxvote_status_' + settings.article_id + '').html(msg).show(1000);
$('img#cd_ajaxvote_loading_' + settings.article_id + '').hide(1000);
t = setTimeout( function () {
$('div#cd_ajaxvote_status_' + settings.article_id + '').hide(1000);
}, 2000);
if ($('div#cd_ajaxvote_status_message').hasClass('cd_ajaxvote_status_success')) {
var getActualRating = $('span#cd_ajaxvote_get_actual_' + settings.article_id + '').html() - 0;
$('span#cd_ajaxvote_get_actual_' + settings.article_id + '').html(getActualRating + 1);
} else {
// nothing
}
}
});
}, 2000);
break;
default:
return false;
break;
}
return false;
}
return true;
});
return this; // strict warning: anonymous function does not always return a value. fix?
}
})(jQuery);