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