﻿if (window.jQuery) (function (a) { if (a.browser.msie) try { document.execCommand("BackgroundImageCache", false, true) } catch (b) { } a.fn.rating = function (b) { if (this.length == 0) return this; if (typeof arguments[0] == "string") { if (this.length > 1) { var c = arguments; return this.each(function () { a.fn.rating.apply(a(this), c) }) } a.fn.rating[arguments[0]].apply(this, a.makeArray(arguments).slice(1) || []); return this } var b = a.extend({}, a.fn.rating.options, b || {}); a.fn.rating.calls++; this.not(".star-rating-applied").addClass("star-rating-applied").each(function () { var c, d = a(this); var e = (this.name || "unnamed-rating").replace(/\[|\]/g, "_").replace(/^\_+|\_+$/g, ""); var f = a(this.form || document.body); var g = f.data("rating"); if (!g || g.call != a.fn.rating.calls) g = { count: 0, call: a.fn.rating.calls }; var h = g[e]; if (h) c = h.data("rating"); if (h && c) c.count++; else { c = a.extend({}, b || {}, (a.metadata ? d.metadata() : a.meta ? d.data() : null) || {}, { count: 0, stars: [], inputs: [] }); c.serial = g.count++; h = a('<span class="star-rating-control"/>'); d.before(h); h.addClass("rating-to-be-drawn"); if (d.attr("disabled")) c.readOnly = true; h.append(c.cancel = a('<div class="rating-cancel"><a title="' + c.cancel + '">' + c.cancelValue + "</a></div>").mouseover(function () { a(this).rating("drain"); a(this).addClass("star-rating-hover") }).mouseout(function () { a(this).rating("draw"); a(this).removeClass("star-rating-hover") }).click(function () { a(this).rating("select") }).data("rating", c)) } var i = a('<div class="star-rating rater-' + c.serial + '"><a id="' + this.id + '" title="' + (this.title || this.value) + '">' + this.value + "</a></div>"); h.append(i); if (this.className) i.addClass(this.className); if (c.half) c.split = 2; if (typeof c.split == "number" && c.split > 0) { var j = (a.fn.width ? i.width() : 0) || c.starWidth; var k = c.count % c.split, l = Math.floor(j / c.split); i.width(l).find("a").css({ "margin-left": "-" + k * l + "px" }) } if (c.readOnly) i.addClass("star-rating-readonly"); else i.addClass("star-rating-live").mouseover(function () { a(this).rating("fill"); a(this).rating("focus") }).mouseout(function () { a(this).rating("draw"); a(this).rating("blur") }).click(function () { a(this).rating("select") }); if (this.checked) c.current = i; d.hide(); d.change(function () { a(this).rating("select") }); i.data("rating.input", d.data("rating.star", i)); c.stars[c.stars.length] = i[0]; c.inputs[c.inputs.length] = d[0]; c.rater = g[e] = h; c.context = f; d.data("rating", c); h.data("rating", c); i.data("rating", c); f.data("rating", g) }); a(".rating-to-be-drawn").rating("draw").removeClass("rating-to-be-drawn"); return this }; a.extend(a.fn.rating, { calls: 0, focus: function () { var b = this.data("rating"); if (!b) return this; if (!b.focus) return this; var c = a(this).data("rating.input") || a(this.tagName == "INPUT" ? this : null); if (b.focus) b.focus.apply(c[0], [c.val(), a("a", c.data("rating.star"))[0]]) }, blur: function () { var b = this.data("rating"); if (!b) return this; if (!b.blur) return this; var c = a(this).data("rating.input") || a(this.tagName == "INPUT" ? this : null); if (b.blur) b.blur.apply(c[0], [c.val(), a("a", c.data("rating.star"))[0]]) }, fill: function () { var a = this.data("rating"); if (!a) return this; if (a.readOnly) return; this.rating("drain"); this.prevAll().andSelf().filter(".rater-" + a.serial).addClass("star-rating-hover") }, drain: function () { var a = this.data("rating"); if (!a) return this; if (a.readOnly) return; a.rater.children().filter(".rater-" + a.serial).removeClass("star-rating-on").removeClass("star-rating-hover") }, draw: function () { var b = this.data("rating"); if (!b) return this; this.rating("drain"); if (b.current) { b.current.data("rating.input").attr("checked", "checked"); b.current.prevAll().andSelf().filter(".rater-" + b.serial).addClass("star-rating-on") } else a(b.inputs).removeAttr("checked"); b.cancel[b.readOnly || b.required ? "hide" : "show"](); this.siblings()[b.readOnly ? "addClass" : "removeClass"]("star-rating-readonly") }, select: function (b) { var c = this.data("rating"); if (!c) return this; if (c.readOnly) return; c.current = null; if (typeof b != "undefined") { if (typeof b == "number") return a(c.stars[b]).rating("select"); if (typeof b == "string") a.each(c.stars, function () { if (a(this).data("rating.input").val() == b) a(this).rating("select") }) } else c.current = this[0].tagName == "INPUT" ? this.data("rating.star") : this.is(".rater-" + c.serial) ? this : null; this.data("rating", c); this.rating("draw"); var d = a(c.current ? c.current.data("rating.input") : null); if (c.callback) c.callback.apply(d[0], [d.val(), a("a", c.current)[0]]) }, readOnly: function (b, c) { var d = this.data("rating"); if (!d) return this; d.readOnly = b || b == undefined ? true : false; if (c) a(d.inputs).attr("disabled", "disabled"); else a(d.inputs).removeAttr("disabled"); this.data("rating", d); this.rating("draw") }, disable: function () { this.rating("readOnly", true, true) }, enable: function () { this.rating("readOnly", false, false) } }); a.fn.rating.options = { cancel: "Cancel Rating", cancelValue: "", split: 0, starWidth: 16 }; a(function () { a("input[type=radio].star").rating() }) })(jQuery)
