1 | var gRatingOptions,gRatingButtons,gUserRating;function makeNiceRatingForm(options) |
---|
2 | {gRatingOptions=options||{};var form=document.getElementById('rateForm');if(!form)return;gRatingButtons=form.getElementsByTagName('input');gUserRating="";for(var i=0;i<gRatingButtons.length;i++) |
---|
3 | {if(gRatingButtons[i].type=="button") |
---|
4 | {gUserRating=gRatingButtons[i].value;break;}} |
---|
5 | for(var i=0;i<gRatingButtons.length;i++) |
---|
6 | {var rateButton=gRatingButtons[i];rateButton.initialRateValue=rateButton.value;try{rateButton.type="button";}catch(e){} |
---|
7 | if(navigator.userAgent.indexOf('AppleWebKit/')==-1&&navigator.userAgent.indexOf('MSIE 8')==-1)rateButton.value="";with(rateButton.style) |
---|
8 | {textIndent="-50px";marginLeft=marginRight=0;} |
---|
9 | if(i!=gRatingButtons.length-1&&rateButton.nextSibling.nodeType==3) |
---|
10 | rateButton.parentNode.removeChild(rateButton.nextSibling);if(i>0&&rateButton.previousSibling.nodeType==3) |
---|
11 | rateButton.parentNode.removeChild(rateButton.previousSibling);if(window.addEventListener){rateButton.addEventListener("click",updateRating,false);rateButton.addEventListener("mouseout",resetRatingStarDisplay,false);rateButton.addEventListener("mouseover",updateRatingStarDisplayEvt,false);} |
---|
12 | else if(window.attachEvent){rateButton.attachEvent("onclick",updateRating);rateButton.attachEvent("onmouseout",resetRatingStarDisplay);rateButton.attachEvent("onmouseover",updateRatingStarDisplayEvt);}} |
---|
13 | resetRatingStarDisplay();} |
---|
14 | function resetRatingStarDisplay() |
---|
15 | {updateRatingStarDisplay(gUserRating);} |
---|
16 | function updateRatingStarDisplay(userRating) |
---|
17 | {for(var i=0;i<gRatingButtons.length;i++) |
---|
18 | gRatingButtons[i].className=(userRating!==""&&userRating>=gRatingButtons[i].initialRateValue)?"rateButtonStarFull":"rateButtonStarEmpty";} |
---|
19 | function updateRatingStarDisplayEvt(e) |
---|
20 | {updateRatingStarDisplay(e.target?e.target.initialRateValue:e.srcElement.initialRateValue);} |
---|
21 | function updateRating(e) |
---|
22 | {var rateButton=e.target||e.srcElement;if(rateButton.initialRateValue==gUserRating) |
---|
23 | return false;for(var i=0;i<gRatingButtons.length;i++)gRatingButtons[i].disabled=true;var y=new PwgWS(gRatingOptions.rootUrl);y.callService("pwg.images.rate",{image_id:gRatingOptions.image_id,rate:rateButton.initialRateValue},{onFailure:function(num,text){alert(num+" "+text);document.location=rateButton.form.action+"&rate="+rateButton.initialRateValue;},onSuccess:function(result){gUserRating=rateButton.initialRateValue;for(var i=0;i<gRatingButtons.length;i++)gRatingButtons[i].disabled=false;if(gRatingOptions.updateRateElement)gRatingOptions.updateRateElement.innerHTML=gRatingOptions.updateRateText;if(gRatingOptions.ratingSummaryElement) |
---|
24 | {var t=gRatingOptions.ratingSummaryText;var args=[result.average,result.count,result.stdev],idx=0,rexp=new RegExp(/%\.?\d*[sdf]/);_xxx=t.match(rexp);while(idx<args.length)t=t.replace(rexp,args[idx++]);gRatingOptions.ratingSummaryElement.innerHTML=t;}}});return false;} |
---|