source: extensions/simple_themes/simple/js/rating.min.js @ 13548

Last change on this file since 13548 was 13546, checked in by plg, 13 years ago

import theme Simple, version 2.0

  • adaptation of the theme for Piwigo 2.1
File size: 2.8 KB
Line 
1var 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;}}
5for(var i=0;i<gRatingButtons.length;i++)
6{var rateButton=gRatingButtons[i];rateButton.initialRateValue=rateButton.value;try{rateButton.type="button";}catch(e){}
7if(navigator.userAgent.indexOf('AppleWebKit/')==-1&&navigator.userAgent.indexOf('MSIE 8')==-1)rateButton.value="";with(rateButton.style)
8{textIndent="-50px";marginLeft=marginRight=0;}
9if(i!=gRatingButtons.length-1&&rateButton.nextSibling.nodeType==3)
10rateButton.parentNode.removeChild(rateButton.nextSibling);if(i>0&&rateButton.previousSibling.nodeType==3)
11rateButton.parentNode.removeChild(rateButton.previousSibling);if(window.addEventListener){rateButton.addEventListener("click",updateRating,false);rateButton.addEventListener("mouseout",resetRatingStarDisplay,false);rateButton.addEventListener("mouseover",updateRatingStarDisplayEvt,false);}
12else if(window.attachEvent){rateButton.attachEvent("onclick",updateRating);rateButton.attachEvent("onmouseout",resetRatingStarDisplay);rateButton.attachEvent("onmouseover",updateRatingStarDisplayEvt);}}
13resetRatingStarDisplay();}
14function resetRatingStarDisplay()
15{updateRatingStarDisplay(gUserRating);}
16function updateRatingStarDisplay(userRating)
17{for(var i=0;i<gRatingButtons.length;i++)
18gRatingButtons[i].className=(userRating!==""&&userRating>=gRatingButtons[i].initialRateValue)?"rateButtonStarFull":"rateButtonStarEmpty";}
19function updateRatingStarDisplayEvt(e)
20{updateRatingStarDisplay(e.target?e.target.initialRateValue:e.srcElement.initialRateValue);}
21function updateRating(e)
22{var rateButton=e.target||e.srcElement;if(rateButton.initialRateValue==gUserRating)
23return 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;}
Note: See TracBrowser for help on using the repository browser.