/*rateYo V2.1.1, A simple and flexible star rating plugin prashanth pamidi (https://github.com/prrashi)*/ !function(a){"use strict";function b(a,b,c){return a===b?a=b:a===c&&(a=c),a}function c(a,b,c){var d=a>=b&&c>=a;if(!d)throw Error("Invalid Rating, expected value between "+b+" and "+c);return a}function d(a){return"undefined"!=typeof a}function e(a,b,c){var d=(b-a)*(c/100);return d=Math.round(a+d).toString(16),1===d.length&&(d="0"+d),d}function f(a,b,c){if(!a||!b)return null;c=d(c)?c:0,a=p(a),b=p(b);var f=e(a.r,b.r,c),g=e(a.b,b.b,c),h=e(a.g,b.g,c);return"#"+f+h+g}function g(e,h){function j(a){d(a)||(a=h.rating),X=a;var b=a/N,c=b*P;b>1&&(c+=(Math.ceil(b)-1)*R),q(h.ratedFill),V.css("width",c+"%")}function k(){S=O*h.numStars+Q*(h.numStars-1),P=O/S*100,R=Q/S*100,e.width(S),j()}function m(a){var b=h.starWidth=a;return O=window.parseFloat(h.starWidth.replace("px","")),U.find("svg").attr({width:h.starWidth,height:b}),V.find("svg").attr({width:h.starWidth,height:b}),k(),e}function o(a){return h.spacing=a,Q=parseFloat(h.spacing.replace("px","")),U.find("svg:not(:first-child)").css({"margin-left":a}),V.find("svg:not(:first-child)").css({"margin-left":a}),k(),e}function p(a){return h.normalFill=a,U.find("svg").attr({fill:h.normalFill}),e}function q(a){if(h.multiColor){var b=X-W,c=b/h.maxValue*100,d=h.multiColor||{},g=d.startColor||n.startColor,i=d.endColor||n.endColor;a=f(g,i,c)}else Z=a;return h.ratedFill=a,V.find("svg").attr({fill:h.ratedFill}),e}function r(a){h.multiColor=a,q(a?a:Z)}function s(b){h.numStars=b,N=h.maxValue/h.numStars,U.empty(),V.empty();for(var c=0;ca&&A(a),j(),e}function u(a){return h.precision=a,A(h.rating),e}function v(a){return h.halfStar=a,e}function w(a){return h.fullStar=a,e}function x(a){var b=a%N,c=N/2,d=h.halfStar,e=h.fullStar;return e||d?(e||d&&b>c?a+=N-b:(a-=b,b>0&&(a+=c)),a):a}function y(a){var b=U.offset(),c=b.left,d=c+U.width(),e=h.maxValue,f=a.pageX,g=0;if(c>f)g=W;else if(f>d)g=e;else{var i=(f-c)/(d-c);if(Q>0){i*=100;for(var j=i;j>0;)j>P?(g+=N,j-=P+R):(g+=j/P*N,j=0)}else g=i*h.maxValue;g=x(g)}return g}function z(a){return h.readOnly=a,e.attr("readonly",!0),L(),a||(e.removeAttr("readonly"),K()),e}function A(a){var d=a,f=h.maxValue;return"string"==typeof d&&("%"===d[d.length-1]&&(d=d.substr(0,d.length-1),f=100,t(f)),d=parseFloat(d)),c(d,W,f),d=parseFloat(d.toFixed(h.precision)),b(parseFloat(d),W,f),h.rating=d,j(),Y&&e.trigger("rateyo.set",{rating:d}),e}function B(a){return h.onInit=a,e}function C(a){return h.onSet=a,e}function D(a){return h.onChange=a,e}function E(a){var c=y(a).toFixed(h.precision),d=h.maxValue;c=b(parseFloat(c),W,d),j(c),e.trigger("rateyo.change",{rating:c})}function F(){j(),e.trigger("rateyo.change",{rating:h.rating})}function G(a){var b=y(a).toFixed(h.precision);b=parseFloat(b),M.rating(b)}function H(a,b){h.onInit&&"function"==typeof h.onInit&&h.onInit.apply(this,[b.rating,M])}function I(a,b){h.onChange&&"function"==typeof h.onChange&&h.onChange.apply(this,[b.rating,M])}function J(a,b){h.onSet&&"function"==typeof h.onSet&&h.onSet.apply(this,[b.rating,M])}function K(){e.on("mousemove",E).on("mouseenter",E).on("mouseleave",F).on("click",G).on("rateyo.init",H).on("rateyo.change",I).on("rateyo.set",J)}function L(){e.off("mousemove",E).off("mouseenter",E).off("mouseleave",F).off("click",G).off("rateyo.init",H).off("rateyo.change",I).off("rateyo.set",J)}this.node=e.get(0);var M=this;e.empty().addClass("jq-ry-container");var N,O,P,Q,R,S,T=a("
").addClass("jq-ry-group-wrapper").appendTo(e),U=a("
").addClass("jq-ry-normal-group").addClass("jq-ry-group").appendTo(T),V=a("
").addClass("jq-ry-rated-group").addClass("jq-ry-group").appendTo(T),W=0,X=h.rating,Y=!1,Z=h.ratedFill;this.rating=function(a){return d(a)?(A(a),e):h.rating},this.destroy=function(){return h.readOnly||L(),g.prototype.collection=i(e.get(0),this.collection),e.removeClass("jq-ry-container").children().remove(),e},this.method=function(a){if(!a)throw Error("Method name not specified!");if(!d(this[a]))throw Error("Method "+a+" doesn't exist!");var b=Array.prototype.slice.apply(arguments,[]),c=b.slice(1),e=this[a];return e.apply(this,c)},this.option=function(a,b){if(!d(a))return h;var c;switch(a){case"starWidth":c=m;break;case"numStars":c=s;break;case"normalFill":c=p;break;case"ratedFill":c=q;break;case"multiColor":c=r;break;case"maxValue":c=t;break;case"precision":c=u;break;case"rating":c=A;break;case"halfStar":c=v;break;case"fullStar":c=w;break;case"readOnly":c=z;break;case"spacing":c=o;break;case"onInit":c=B;break;case"onSet":c=C;break;case"onChange":c=D;break;default:throw Error("No such option as "+a)}return d(b)?c(b):h[a]},s(h.numStars),z(h.readOnly),this.collection.push(this),this.rating(h.rating,!0),Y=!0,e.trigger("rateyo.init",{rating:h.rating})}function h(b,c){var d;return a.each(c,function(){return b===this.node?(d=this,!1):void 0}),d}function i(b,c){return a.each(c,function(a){if(b===this.node){var d=c.slice(0,a),e=c.slice(a+1,c.length);return c=d.concat(e),!1}}),c}function j(b){var c=g.prototype.collection,d=a(this);if(0===d.length)return d;var e=Array.prototype.slice.apply(arguments,[]);if(0===e.length)b=e[0]={};else{if(1!==e.length||"object"!=typeof e[0]){if(e.length>=1&&"string"==typeof e[0]){var f=e[0],i=e.slice(1),j=[];return a.each(d,function(a,b){var d=h(b,c);if(!d)throw Error("Trying to set options before even initialization");var e=d[f];if(!e)throw Error("Method "+f+" does not exist!");var g=e.apply(d,i);j.push(g)}),j=1===j.length?j[0]:j}throw Error("Invalid Arguments")}b=e[0]}return b=a.extend({},m,b),a.each(d,function(){var d=h(this,c);return d?void 0:new g(a(this),a.extend({},b))})}function k(){return j.apply(this,Array.prototype.slice.apply(arguments,[]))}var l='',m={starWidth:"32px",normalFill:"gray",ratedFill:"#f39c12",numStars:5,maxValue:5,precision:1,rating:0,fullStar:!1,halfStar:!1,readOnly:!1,spacing:"0px",multiColor:null,onInit:null,onChange:null,onSet:null},n={startColor:"#c0392b",endColor:"#f1c40f"},o=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i,p=function(a){if(!o.test(a))return null;var b=o.exec(a),c=parseInt(b[1],16),d=parseInt(b[2],16),e=parseInt(b[3],16);return{r:c,g:d,b:e}};g.prototype.collection=[],window.RateYo=g,a.fn.rateYo=k}(window.jQuery); //# sourceMappingURL=jquery.rateyo.min.js.map