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=function(e){c.textEl.addClass("ratingError");c.textEl.set("text",e);(function(){c.textEl.set("text",c.textEl.oldTxt);c.textEl.removeClass("ratingError")}).delay(2000)}}else{c.getElement(".ratingText").inject(c,"before");c.remove()}},fillVote:function(d,c){c.newFill=this.getFillPercent(d);if(this.getVotePercent(c.newFill)>100){c.newFill=this.getFillPercent(100)}c.selected.setStyle("width",c.newFill)},getStarPercent:function(g){var c=g.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic)-(\d*\.?\d+)_(\d*\.?\d+)$/);if(c!=null){var f=c[3].toFloat();var e=c[4].toFloat();var d=(f/e)*100;return d}else{return 0}},getFillPercent:function(c){return(c/100)*(this.options.starwidth*this.options.max)},getVotePercent:function(d){var c=this.options.starwidth*this.options.max;var e=(d/c*100).round(2);return e},getRatableId:function(d){var c=d.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic)-(\d*\.?\d+)_(\d*\.?\d+)$/);return c!=null?c[1]:""},getRatableType:function(d){var c=d.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic)-(\d*\.?\d+)_(\d*\.?\d+)$/);return c!=null?c[2]:""},getRatableMaxValue:function(d){var c=d.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic)-(\d*\.?\d+)_(\d*\.?\d+)$/);return c!=null?c[4].toInt():0},setBackgroundPosition:function(c,d){c.setStyle("background-position","0% "+d+"px")},getBackgroundImagePath:function(c){return c.getStyle("background-image")},getBackgroundImage:function(d){var f=/url\s*\(["']?(.*)["']?\)/i;var e=document.createElement("img");var c=this.getBackgroundImagePath(d);c=c.match(f)[1];c=c.replace('"',"");e.src=c;return e}});window.addEvent("domready",function(c){RateItRating=new b({url:"SimpleAjax.php"})})}else{if(window.jQuery){(function(){b={options:{step:0.1,readonly:false,resetable:false},initialize:function(d){if(typeof d=="object"&&typeof d.url!="undefined"){this.options.url=d.url}var c=this;jQuery(".rateItRating").each(function(f,e){c.initMe(e)});return this},initMe:function(d){var c=this;if(!Browser.Engine.trident4){var e=jQuery(d);e.data("id",e.attr("id"));e.data("rateable",e.attr("rel")=="not-rateable"?false:true);e.data("wrapper",e.find(".wrapper"));e.data("textEl",e.find(".ratingText"));e.data("selected",e.find(".rateItRating-selected"));e.data("hover",e.find(".rateItRating-hover"));var f=c.getBackgroundImage(e.data("wrapper"));c.options.starwidth=f.width;c.options.starheight=f.height/3;if(c.options.starwidth===undefined||c.options.starwidth<16){c.options.starwidth=16}if(c.options.starheight===undefined||c.options.starheight<16){c.options.starheight=16}c.setBackgroundPosition(e.data("selected"),-1*c.options.starheight);c.setBackgroundPosition(e.data("hover"),-1*2*c.options.starheight);e.data("starPercent",c.getStarPercent(e.data("id")));e.data("ratableId",c.getRatableId(e.data("id")));e.data("ratableType",c.getRatableType(e.data("id")));c.options.max=c.getRatableMaxValue(e.data("id"));e.data("selected").css("height",c.options.starheight);e.data("hover").css("height",c.options.starheight);e.data("wrapper").css("width",c.options.starwidth*c.options.max);e.data("wrapper").css("height",c.options.starheight);c.fillVote(e.data("starPercent"),e);e.data("currentFill",c.getFillPercent(e.data("starPercent")));if(e.data("rateable")){e.data("wrapper").mouseenter(function(g){e.data("selected").hide(500,"easeInOutQuad");e.data("hover").show();e.data("wrapper").mousemove({el:e,self:c},c.mouseCrap)});e.data("wrapper").mouseleave(function(g){e.data("wrapper").unbind("mousemove");e.data("hover").hide();e.data("selected").show();e.data("selected").animate({width:e.data("currentFill")},500)});e.data("wrapper").click(function(j){e.data("currentFill",e.data("newFill"));e.data("wrapper").unbind();e.data("oldTxt",e.data("textEl").text());e.data("textEl").html(" ");e.data("textEl").addClass("loading");if(typeof(jQuery(".mbrateItRating"))!="undefined"&&e.data("id").indexOf("mb")==0){var i=e.data("id");i=i.replace("mb","");if(typeof(arrRatings)=="object"){for(var g=0;g<arrRatings.length;g++){if(arrRatings[g].rateItID==i){arrRatings[g].rated=true;arrRatings[g].width=e.data("hover").css("width");break}}}if(typeof(jQuery("#"+a(i)))!="undefined"){var k=jQuery("#"+a(i)).find(".wrapper");k.unbind();k.find(".rateItRating-selected").css("display","none");k.find(".rateItRating-hover").css("width",e.data("hover").css("width"));k.find(".rateItRating-hover").css("display","block")}}else{if(typeof(arrRatings)=="object"){for(var g=0;g<arrRatings.length;g++){if(arrRatings[g].rateItID==e.data("id")){arrRatings[g].rated=true;arrRatings[g].width=e.data("hover").css("width");break}}}}var h=c.getVotePercent(e.data("newFill"));if(c.options.url!=null){jQuery.ajax({url:c.options.url,type:"post",data:{vote:h,id:e.data("ratableId"),type:e.data("ratableType")}}).done(function(l){e.data("updateText")(e,l)})}})}e.data("updateText",c.updateText)}else{alert("Ich bin ein IE6")}},fillVote:function(d,c){c.data("newFill",this.getFillPercent(d));if(this.getVotePercent(c.data("newFill"))>100){c.data("newFill",this.getFillPercent(100))}c.data("selected").css("width",c.data("newFill"))},mouseCrap:function(h){var f=h.data.el;var e=h.data.self;var j=h.originalEvent.layerX;if(!j){j=h.originalEvent.offsetX}var i=e.getVotePercent(j);var c=Math.ceil((i/100)*e.options.max);var d=c*e.options.starwidth;if(parseInt(f.data("hover").css("width"))!=d){f.data("selected").css("display","none");f.data("hover").css("width",Math.min(d,e.options.starwidth*e.options.max));f.data("hover").css("display","block")}var g=c/e.options.max*100;e.fillVote(g,f)},getStarPercent:function(g){var c=g.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic)-(\d*\.?\d+)_(\d*\.?\d+)$/);if(c!=null){var f=parseFloat(c[3]);var e=parseFloat(c[4]);var d=(f/e)*100;return d}else{return 0}},getFillPercent:function(c){return(c/100)*(this.options.starwidth*this.options.max)},getVotePercent:function(d){var c=this.options.starwidth*this.options.max;var e=(d/c*100).toFixed(2);return e},getRatableId:function(d){var c=d.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic)-(\d*\.?\d+)_(\d*\.?\d+)$/);return c!=null?c[1]:""},getRatableType:function(d){var c=d.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic)-(\d*\.?\d+)_(\d*\.?\d+)$/);return c!=null?c[2]:""},getRatableMaxValue:function(d){var c=d.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic)-(\d*\.?\d+)_(\d*\.?\d+)$/);return c!=null?parseInt(c[4]):0},setBackgroundPosition:function(c,d){c.css("background-position","0% "+d+"px")},getBackgroundImagePath:function(c){return c.css("background-image")},getBackgroundImage:function(d){var f=/url\s*\(["']?(.*)["']?\)/i;var e=document.createElement("img");var c=this.getBackgroundImagePath(d);c=c.match(f)[1];c=c.replace('"',"");e.src=c;return e},updateText:function(d,f){error=f.split("ERROR:")[1];d.data("textEl").removeClass("loading");if(error){this.RateItRating.showError(d,error);return false}d.data("textEl").text(f);if(typeof(jQuery(".mbrateItRating"))!="undefined"&&d.data("id").indexOf("mb")==0){var e=d.attr("id");e=e.replace("mb","");if(typeof(arrRatings)=="object"){for(var c=0;c<arrRatings.length;c++){if(arrRatings[c].rateItID==e){arrRatings[c].description=f;break}}}if(typeof(jQuery("#"+a(e)))!="undefined"){jQuery("#"+a(e)).find(".ratingText").text(f)}}else{if(typeof(arrRatings)=="object"){for(var c=0;c<arrRatings.length;c++){if(arrRatings[c].rateItID==d.data("id")){arrRatings[c].description=f;break}}}}},showError:function(d,c){d.data("textEl").addClass("ratingError");d.data("textEl").text(c);setTimeout(function(){d.data("textEl").text(d.data("oldTxt"));d.data("textEl").removeClass("ratingError")},2000)}}})(jQuery);jQuery(document).ready(function(){jQuery.ajax({type:"GET",url:"system/modules/rateit/public/js/jquery-ui-effects.custom.min.js",dataType:"script",async:false,cache:true});jQuery.ajax({type:"GET",url:"system/modules/rateit/public/js/helper.js",dataType:"script",async:false,cache:true});RateItRating=Object.create(b).initialize({url:"SimpleAjax.php"})});var a=function(c){c=c.replace(new RegExp("\\$","g"),"\\$");c=c.replace(new RegExp("~","g"),"\\~");c=c.replace(new RegExp("\\[","g"),"\\[");c=c.replace(new RegExp("\\]","g"),"\\]");c=c.replace(new RegExp("\\|","g"),"\\|");c=c.replace(new RegExp("\\.","g"),"\\.");c=c.replace(new RegExp("#","g"),"\\#");return c}}}}onReadyRateIt(function(){doRateIt()}); |