"use strict";!function(e){var t={split:1,numStars:5};function s(s,n){var o=this;o.elem=e(s),o.opts=e.extend({},t,n),o.init()}s.prototype._toFixed=function(e){return e=Number(e),Number(e.toFixed(this._prec))},s.prototype.init=function(){var t,s,n=this;n.elem.is("input")?n.elem.removeClass("jqStars").addClass("jqStarsInput").wrap("<div class='jqStars jqStarsInited' />"):n.elem=n.elem.children("input"),n.mapping={},n.opts.values&&(n.opts.values.constructor===String?n.opts.values=n.opts.values.split(/\s*,\s*/):n.opts.values.constructor===Array&&(s=[],e.each(n.opts.values,(function(e,o){if(o.constructor===Object)for(t in o)n.mapping[o[t]]=t,s.push(o[t]);else s.push(o)})),n.opts.values=s),n.opts.numStars=n.opts.values.length-1,n.opts.split=1),n._prec=0,n.opts.split>1&&n._prec++,n.opts.split>10&&n._prec++,n.opts.split>100&&n._prec++,n.blockMouseMove=!1,n.timeoutId=void 0,n.elem.hide(),n.container=e("<div />").addClass("jqStarsContainer").insertAfter(n.elem),n.labelElem=e("<span />").addClass("jqStarsLabel").insertAfter(n.container),n.onElem=e("<div />").addClass("jqStarsOn").appendTo(n.container),n.widthStar=parseInt(n.container.css("background-size"),10),n.width=n.opts.numStars*n.widthStar,n.container.width(n.width),n.elem.is(":disabled")?n.container.addClass("jqStarsReadOnly"):(n.deleteElem=e("<div />").addClass("jqStarsDelete").insertAfter(n.elem),n.container.on("mousemove",(function(e){n.blockMouseMove||n.displayAtIndex((e.pageX-n.container.offset().left)/n.widthStar)})),n.container.on("mouseleave",(function(){n.blockMouseMove&&(void 0!==n.timeoutId&&window.clearTimeout(n.timeoutId),n.timeoutId=window.setTimeout((function(){n.blockMouseMove=!1,n.timeoutId=void 0}),1e3)),n.display(n.elem.val()),n.container.removeClass("jqStarsSelected")})),n.container.on("mouseenter",(function(){n.elem.trigger("focus"),n.blockMouseMove=!1})),n.container.on("click",(function(e){return n.displayAtIndex((e.pageX-n.container.offset().left)/n.widthStar),n.container.addClass("jqStarsSelected"),n.blockMouseMove=!0,n.selectAtIndex(n._tmpIndex),!1})),n.deleteElem.hover((function(){n.display()}),(function(){n.display(n.elem.val())})),n.deleteElem.on("click",(function(){return n.selectAtIndex(0),!1})),n.container.on("mousewheel",(function(e){var t=1/n.opts.split;return e.deltaY>0?(n._tmpIndex+=t,n._tmpIndex>n.opts.numStars&&(n._tmpIndex=n.opts.numStars)):(n._tmpIndex-=t,n._tmpIndex<0&&(n._tmpIndex=0)),n._tmpIndex=n._toFixed(n._tmpIndex),n.selectAtIndex(n._tmpIndex),n.container.addClass("jqStarsSelected"),n.blockMouseMove=!0,!1})),e(document).on("keydown",(function(e){if(n.container.is(":hover")){var t=1/n.opts.split,s=!1;switch(e.keyCode){case 38:case 33:n._tmpIndex=Math.floor(n._tmpIndex+1),s=!0;break;case 40:case 34:n._tmpIndex=Math.ceil(n._tmpIndex-1),s=!0;break;case 35:n._tmpIndex=n.opts.numStars,s=!0;break;case 36:n._tmpIndex=0,s=!0;break;case 37:n._tmpIndex-=t,s=!0;break;case 39:n._tmpIndex+=t,s=!0;break;default:s=!1}if(s)return n._tmpIndex>n.opts.numStars&&(n._tmpIndex=n.opts.numStars),n._tmpIndex<0&&(n._tmpIndex=0),n._tmpIndex=n._toFixed(n._tmpIndex),n.selectAtIndex(n._tmpIndex),!1}}))),n.display(n.elem.val())},s.prototype.getDisplayVal=function(e){var t,s=this;return s.opts.values?(t=s.opts.values[e],void 0!==s.mapping[t]&&(t=s.mapping[t])):t=sprintf("%."+s._prec+"f",e),t},s.prototype.displayAtIndex=function(e){var t,s,n=this;e=Math.ceil(e*n.opts.split)/n.opts.split,e=n._toFixed(e),t=n.widthStar*e,s=n.getDisplayVal(e),e!==n._tmpIndex&&(n.onElem.width(t),n.labelElem.html(s),n._tmpIndex=e,n.elem.trigger("display.stars",e,s))},s.prototype.display=function(e){var t,s=this;return t=void 0===e||""===e?0:void 0!==s.opts.values?s.opts.values.indexOf(e):e,s.displayAtIndex(t),t},s.prototype.selectAtIndex=function(e){var t,s=this;s._tmpIndex=void 0,e=e||0,t=void 0!==s.opts.values?s.opts.values[e]:e,s.displayAtIndex(e),s.elem.val(t)},e.fn.stars=function(t){return this.each((function(){e.data(this,"_stars")||e.data(this,"_stars",new s(this,t))}))},e((function(){e(".jqStars:not(.jqStarsInited)").livequery((function(){var t=e(this),s=e.extend({},t.data());t.stars(s)}))}))}(jQuery);
