',{
'class' : 'jRatingInfos',
html : getNote(relativeX)+' / '+opts.rateMax+'',
css : {
top: (e.pageY + opts.rateInfosY),
left: (e.pageX + opts.rateInfosX)
}
}).appendTo('body').show();
},
mouseover : function(e){
$(this).css('cursor','pointer');
},
mouseout : function(){
$(this).css('cursor','default');
if(hasRated) average.width(globalWidth);
else average.width(0);
},
mousemove : function(e){
var realOffsetLeft = findRealLeft(this);
var relativeX = e.pageX - realOffsetLeft;
relativeX = (100 / document.documentElement.clientWidth)*relativeX;
if(opts.step) newWidth = Math.floor(relativeX/starWidth)*starWidth + starWidth;
else newWidth = relativeX;
average.width(newWidth+'vw');
if (opts.showRateInfo)
$("p.jRatingInfos")
.css({
left: (e.pageX + opts.rateInfosX)
})
.html(getNote(newWidth) +' / '+opts.rateMax+'');
},
mouseleave : function(){
$("p.jRatingInfos").remove();
},
click : function(e){
var element = this;
/*set vars*/
hasRated = true;
globalWidth = newWidth;
nbOfRates--;
if(!opts.canRateAgain || parseInt(nbOfRates) <= 0) $(this).unbind().css('cursor','default').addClass('jDisabled');
if (opts.showRateInfo) $("p.jRatingInfos").fadeOut('fast',function(){$(this).remove();});
e.preventDefault();
var rate = getNote(newWidth);
average.width(newWidth+'vw');
/** ONLY FOR THE DEMO, YOU CAN REMOVE THIS CODE **/
$('.datasSent p').html('idBox : '+idBox+'
rate : '+rate+'
action : rating');
$('.serverResponse p').html('Loading...');
/** END ONLY FOR THE DEMO **/
if(opts.onClick) opts.onClick( element, rate );
if(opts.sendRequest) {
$.post(opts.phpPath,{
idBox : idBox,
rate : rate,
action : 'rating'
},
function(data) {
if(!data.error)
{
/** ONLY FOR THE DEMO, YOU CAN REMOVE THIS CODE **/
$('.serverResponse p').html(data.server);
/** END ONLY FOR THE DEMO **/
/** Here you can display an alert box,
or use the jNotify Plugin :) http://www.myqjqueryplugins.com/jNotify
exemple : */
if(opts.onSuccess) opts.onSuccess( element, rate );
}
else
{
/** ONLY FOR THE DEMO, YOU CAN REMOVE THIS CODE **/
$('.serverResponse p').html(data.server);
/** END ONLY FOR THE DEMO **/
/** Here you can display an alert box,
or use the jNotify Plugin :) http://www.myqjqueryplugins.com/jNotify
exemple : */
if(opts.onError) opts.onError( element, rate );
}
},
'json'
);
}
}
});
function getNote(relativeX) {
var noteBrut = parseFloat((relativeX*100/widthRatingContainer)*parseInt(opts.rateMax)/100);
var dec=Math.pow(10,parseInt(opts.decimalLength));
var note = Math.round(noteBrut*dec)/dec;
return note;
};
function getStarWidth(){
switch(opts.type) {
case 'small' :
starWidth = 12; // width of the picture small.png
starHeight = 10; // height of the picture small.png
bgPath = opts.smallStarsPath;
break;
default :
starWidth = 1.19 //23; // width of the picture stars.png
starHeight = 1.06 //20; // height of the picture stars.png
bgPath = opts.bigStarsPath;
}
};
function findRealLeft(obj) {
if( !obj ) return 0;
return obj.offsetLeft + findRealLeft( obj.offsetParent );
};
});
}
})(jQuery);