1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
|
var RateItRating;function doRateIt(){if(window.MooTools){var b=new Class({Implements:Options,options:{step:0.1,readonly:false,resetable:false},initialize:function(c){this.setOptions(c);$$(".rateItRating").each(function(d){this.initMe(d)}.bind(this))},initMe:function(c){if(!Browser.ie||Browser.version>6){c.id=c.getAttribute("id");c.rateable=c.getAttribute("rel")=="not-rateable"?false:true;c.wrapper=c.getElement(".wrapper");c.textEl=c.getElement(".ratingText");c.selected=c.wrapper.getElement(".rateItRating-selected");c.hover=c.wrapper.getElement(".rateItRating-hover");c.widthFx=new Fx.Tween(c.selected,{property:"width",link:"chain"});var d=this.getBackgroundImage(c.wrapper);this.options.starwidth=d.width;this.options.starheight=d.height/3;if(this.options.starwidth===undefined||this.options.starwidth<16){this.options.starwidth=16}if(this.options.starheight===undefined||this.options.starheight<16){this.options.starheight=16}this.setBackgroundPosition(c.selected,-1*this.options.starheight);this.setBackgroundPosition(c.hover,-1*2*this.options.starheight);c.starPercent=this.getStarPercent(c.id);c.ratableId=this.getRatableId(c.id);c.ratableType=this.getRatableType(c.id);this.options.max=this.getRatableMaxValue(c.id);c.selected.setStyle("height",this.options.starheight);c.hover.setStyle("height",this.options.starheight);c.wrapper.setStyle("width",this.options.starwidth*this.options.max);c.wrapper.setStyle("height",this.options.starheight);this.fillVote(c.starPercent,c);c.currentFill=this.getFillPercent(c.starPercent);if(c.rateable){c.mouseCrap=function(k){var j=k.event.layerX;if(!j){j=k.event.offsetX}var i=this.getVotePercent(j);var f=Math.ceil((i/100)*this.options.max);var g=f*this.options.starwidth;if(c.hover.getStyle("width").toInt()!=g){c.selected.setStyle("display","none");c.hover.setStyle("width",Math.min(g,this.options.starwidth*this.options.max));c.hover.setStyle("display","block")}var h=f/this.options.max*100;this.fillVote(h,c)}.bind(this);c.wrapper.addEvent("mouseenter",function(f){c.wrapper.addEvent("mousemove",c.mouseCrap)});c.wrapper.addEvent("mouseleave",function(f){c.removeEvent("mousemove");c.hover.setStyle("width",0);c.hover.setStyle("display","none");c.selected.setStyle("display","block");c.widthFx.start(c.currentFill)});c.wrapper.addEvent("click",function(j){c.currentFill=c.newFill;c.wrapper.removeEvents();c.textEl.oldTxt=c.textEl.get("text");c.textEl.set("html"," ");c.textEl.addClass("loading");if(typeof($(".mbrateItRating"))!="undefined"&&c.id.indexOf("mb")==0){var h=c.id;h=h.replace("mb","");if(typeof(arrRatings)=="object"){for(var f=0;f<arrRatings.length;f++){if(arrRatings[f].rateItID==h){arrRatings[f].rated=true;arrRatings[f].width=c.hover.getStyle("width");break}}}if(typeof($(h))!="undefined"){var i=$(h).getElement(".wrapper");i.removeEvents();i.getElement(".rateItRating-selected").setStyle("display","none");i.getElement(".rateItRating-hover").setStyle("width",c.hover.getStyle("width"));i.getElement(".rateItRating-hover").setStyle("display","block")}}else{if(typeof(arrRatings)=="object"){for(var f=0;f<arrRatings.length;f++){if(arrRatings[f].rateItID==c.id){arrRatings[f].rated=true;arrRatings[f].width=c.hover.getStyle("width");break}}}}var g=this.getVotePercent(c.newFill);if(this.options.url!=null){new Request({url:this.options.url,onComplete:c.updateText}).post({vote:g,id:c.ratableId,type:c.ratableType})}}.bind(this));c.updateText=function(g){error=g.split("ERROR:")[1];c.textEl.removeClass("loading");if(error){c.showError(error);return false}c.textEl.set("text",g);if(typeof($(".mbrateItRating"))!="undefined"&&c.id.indexOf("mb")==0){var f=c.getAttribute("id");f=f.replace("mb","");if(typeof(arrRatings)=="object"){for(var e=0;e<arrRatings.length;e++){if(arrRatings[e].rateItID==f){arrRatings[e].description=g;break}}}if(typeof($(f))!="undefined"){$(f).getElement(".ratingText").set("text",g)}}else{if(typeof(arrRatings)=="object"){for(var e=0;e<arrRatings.length;e++){if(arrRatings[e].rateItID==c.id){arrRatings[e].description=g;break}}}}}}c.showError=fun
|