/*
!The MIT License (MIT)
**/
! function (t) {
t.fn.jRate = function (o) {
"use strict";
function r(t) {
return "undefined" != typeof t
}
function e() {
return r(M) ? M.rating : void 0
}
function n(t) {
if (!r(t) || t < M.min || t > M.max) throw t + " is not in range(" + min + "," + max + ")";
M.rating = t, l(t)
}
function a(t) {
var o, r = '';
break;
case "CIRCLE":
o = r + ">" + a + '';
break;
case "RECTANGLE":
o = r + ">" + a + '';
break;
case "TRIANGLE":
o = r + ">" + a + '';
break;
case "RHOMBUS":
o = r + ">" + a + '';
break;
case "FOOD":
o = r + 'viewBox="0 0 50 50">' + a + '';
break;
case "TWITTER":
o = r + 'viewBox="0 0 512 512">' + a + '';
break;
case "BULB":
o = r + 'viewBox="0 0 512 512">' + a + '';
break;
default:
throw Error("No such shape as " + M.shape)
}
return o
}
function i() {
_.css("white-space", "nowrap"), _.css("cursor", "pointer"), _.css("fill", M.shape)
}
function c(t, o) {
t.on("mousemove", u(o)).on("mouseenter", u(o)).on("click", m(o)).on("mouseover", u(o)).on("hover", u(o)).on("mouseleave", d).on("mouseout", d).on("JRate.change", y).on("JRate.set", k), M.touch && t.on("touchstart", w(o)).on("touchmove", w(o)).on("touchend", v(o)).on("tap", v(o))
}
function s() {
for (var t = _.attr("id"), o = 0; o < M.count; o++) z.eq(o).find("#" + t + "_grad" + (o + 1)).find("stop").eq(0).attr({
offset: "0%"
}), z.eq(o).find("#" + t + "_grad" + (o + 1)).find("stop").eq(0).attr({
"stop-color": M.backgroundColor
}), z.eq(o).find("#" + t + "_grad" + (o + 1)).find("stop").eq(1).attr({
offset: "0%"
}), z.eq(o).find("#" + t + "_grad" + (o + 1)).find("stop").eq(1).attr({
"stop-color": M.backgroundColor
})
}
function l(t) {
s();
var o = (M.max - M.min) / M.count;
t = (t - M.min) / o;
var e = M.startColor,
n = _.attr("id");
if (M.reverse)
for (var a = 0; t > a; a++) {
var i = M.count - 1 - a;
if (z.eq(i).find("#" + n + "_grad" + (i + 1)).find("stop").eq(0).attr({
offset: "100%"
}), z.eq(i).find("#" + n + "_grad" + (i + 1)).find("stop").eq(0).attr({
"stop-color": e
}), parseInt(t) !== t) {
var c = Math.ceil(M.count - t) - 1;
z.eq(c).find("#" + n + "_grad" + (c + 1)).find("stop").eq(0).attr({
offset: 100 - 10 * t % 10 * 10 + "%"
}), z.eq(c).find("#" + n + "_grad" + (c + 1)).find("stop").eq(0).attr({
"stop-color": M.backgroundColor
}), z.eq(c).find("#" + n + "_grad" + (c + 1)).find("stop").eq(1).attr({
offset: 100 - 10 * t % 10 * 10 + "%"
}), z.eq(c).find("#" + n + "_grad" + (c + 1)).find("stop").eq(1).attr({
"stop-color": e
})
}
r(q) && (e = R(M.count - 1, a))
} else
for (var a = 0; t > a; a++) z.eq(a).find("#" + n + "_grad" + (a + 1)).find("stop").eq(0).attr({
offset: "100%"
}), z.eq(a).find("#" + n + "_grad" + (a + 1)).find("stop").eq(0).attr({
"stop-color": e
}), 10 * t % 10 > 0 && (z.eq(Math.ceil(t) - 1).find("#" + n + "_grad" + (a + 1)).find("stop").eq(0).attr({
offset: 10 * t % 10 * 10 + "%"
}), z.eq(Math.ceil(t) - 1).find("#" + n + "_grad" + (a + 1)).find("stop").eq(0).attr({
"stop-color": e
})), r(q) && (e = R(M.count, a))
}
function f(t) {
var o, r;
return o = document.createElement("canvas"), o.height = 1, o.width = 1, r = o.getContext("2d"), r.fillStyle = t, r.fillRect(0, 0, 1, 1), r.getImageData(0, 0, 1, 1).data
}
function d() {
M.readOnly || (l(M.rating), y(null, {
rating: M.rating
}))
}
function h(t) {
var o = 1 / M.precision;
return Math.round(t * o) / o
}
function g(t, o, r, e) {
if (!M.readOnly) {
var n, a = z.eq(o - 1);
n = M.horizontal ? (t.pageX - a.offset().left) / a.width() : (t.pageY - a.offset().top) / a.height();
var i = (M.max - M.min) / M.count;
n = M.reverse ? n : 1 - n;
var c = ((M.reverse ? M.max - M.min - o + 1 : o) - n) * i;
c = M.min + Number(h(c)), c < M.minSelected && (c = M.minSelected), c <= M.max && c >= M.min && (l(c), e && (M.rating = c), a.trigger(r, {
rating: c
}))
}
}
function p(t, o, r, e) {
if (!M.readOnly) {
var n = t.originalEvent.changedTouches;
if (!(n.length > 1)) {
var a, i = n[0],
c = z.eq(o - 1);
a = M.horizontal ? (i.pageX - c.offset().left) / c.width() : (i.pageY - c.offset().top) / c.height();
var s = (M.max - M.min) / M.count;
a = M.reverse ? a : 1 - a;
var f = ((M.reverse ? M.max - M.min - o + 1 : o) - a) * s;
f = M.min + Number(h(f)), f < M.minSelected && (f = M.minSelected), f <= M.max && f >= M.min && (l(f), e && (M.rating = f), c.trigger(r, {
rating: f
}))
}
}
}
function u(t) {
return function (o) {
g(o, t, "JRate.change")
}
}
function m(t) {
return function (o) {
g(o, t, "JRate.set", !0)
}
}
function w(t) {
return function (o) {
p(o, t, "JRate.touch")
}
}
function v(t) {
return function (o) {
p(o, t, "JRate.tap", !0)
}
}
function y(t, o) {
M.onChange && "function" == typeof M.onChange && M.onChange.apply(this, [o.rating])
}
function k(t, o) {
M.onSet && "function" == typeof M.onSet && M.onSet.apply(this, [o.rating])
}
function C() {
var t, o, r, e;
for (o = 0; o < M.count; o++) _.append(a(o + 1));
for (z = _.find("svg"), o = 0; o < M.count; o++) t = z.eq(o), c(t, o + 1), M.horizontal ? t.css("margin-right", M.shapeGap || "0px") : t.css({
display: "block",
"margin-bottom": M.shapeGap || "0px"
}), M.widthGrowth && (r = "scaleX(" + (1 + M.widthGrowth * o) + ")", t.css({
transform: r,
"-webkit-transform": r,
"-moz-transform": r,
"-ms-transform": r,
"-o-transform": r
})), M.heightGrowth && (e = "scaleY(" + (1 + M.heightGrowth * o) + ")", t.css({
transform: e,
"-webkit-transform": e,
"-moz-transform": e,
"-ms-transform": e,
"-o-transform": e
}));
s(), l(M.rating), z.attr({
width: M.width,
height: M.height
})
}
var x, q, z, _ = t(this),
b = {
rating: 0,
shape: "STAR",
count: 5,
width: "20",
height: "20",
widthGrowth: 0,
heightGrowth: 0,
backgroundColor: "white",
startColor: "yellow",
endColor: "green",
strokeColor: "black",
transparency: 1,
shapeGap: "0px",
opacity: 1,
min: 0,
max: 5,
precision: .1,
minSelected: 0,
horizontal: !0,
reverse: !1,
readOnly: !1,
touch: !0,
onChange: null,
onSet: null
},
M = t.extend({}, b, o),
R = function (t, o) {
for (var r = [], e = 0; 3 > e; e++) {
var n = Math.round((x[e] - q[e]) / t),
a = x[e] + n * (o + 1);
r[e] = a / 256 ? (x[e] - n * (o + 1)) % 256 : (x[e] + n * (o + 1)) % 256
}
return "rgba(" + r[0] + "," + r[1] + "," + r[2] + "," + M.opacity + ")"
};
return M.startColor && (x = f(M.startColor)), M.endColor && (q = f(M.endColor)), i(), C(), t.extend({}, this, {
getRating: e,
setRating: n,
setReadOnly: function (t) {
M.readOnly = t
},
isReadOnly: function () {
return M.readOnly
}
})
}
}(jQuery);