!function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof module&&module.exports?module.exports=t(require("jquery")):t(jQuery)}(function(v){var a=function(){function t(){var u=this,d=function(t){return v.isNumeric(t)&&(t=Math.floor(t)),v('option[value="'+t+'"]',u.$elem)},l=function(t){var e=u.$elem.data("barrating");return void 0!==t?e[t]:e},g=function(t,e){null!==e&&"object"==typeof e?u.$elem.data("barrating",e):u.$elem.data("barrating")[t]=e},e=function(){var t,e,n=(e=u.options.initialRating)?d(e):v("option:selected",u.$elem),a=!(t=u.$elem.find('option[value="'+u.options.emptyValue+'"]')).length&&u.options.allowEmpty?(t=v("",{value:u.options.emptyValue})).prependTo(u.$elem):t,i=n.val(),r=n.data("html")?n.data("html"):n.text(),o=null!==u.options.allowEmpty?u.options.allowEmpty:!!a.length,l=a.length?a.val():null,s=a.length?a.text():null;g(null,{userOptions:u.options,ratingValue:i,ratingText:r,originalRatingValue:i,originalRatingText:r,allowEmpty:o,emptyRatingValue:l,emptyRatingText:s,readOnly:u.options.readonly,ratingMade:!1})},o=function(){return l("ratingText")},s=function(){return l("ratingValue")},c=function(){return l("userOptions").reverse?"nextAll":"prevAll"},p=function(t){d(t).prop("selected",!0),l("userOptions").triggerChange&&u.$elem.change()},f=function(t){(t=t||o())==l("emptyRatingText")&&(t=""),u.options.showSelectedRating&&u.$elem.parent().find(".br-current-rating").text(t)},h=function(){u.$widget.find("a").removeClass(function(t,e){return(e.match(/(^|\s)br-\S+/g)||[]).join(" ")})},m=function(){var t,e,n,a=u.$widget.find('a[data-rating-value="'+s()+'"]'),i=l("userOptions").initialRating,r=v.isNumeric(s())?s():0,o=(n=i,Math.round(Math.floor(10*n)/10%1*100));if(h(),a.addClass("br-selected br-current")[c()]().addClass("br-selected"),!l("ratingMade")&&v.isNumeric(i)){if(i<=r||!o)return;t=u.$widget.find("a"),(e=a.length?a[l("userOptions").reverse?"prev":"next"]():t[l("userOptions").reverse?"last":"first"]()).addClass("br-fractional"),e.addClass("br-fractional-"+o)}},n=function(t){t.on("click.barrating",function(t){var e,n,a,i=v(this),r=l("userOptions");return t.preventDefault(),e=i.attr("data-rating-value"),n=i.attr("data-rating-text"),a=i,!(!l("allowEmpty")||!l("userOptions").deselectable)&&s()==a.attr("data-rating-value")&&(e=l("emptyRatingValue"),n=l("emptyRatingText")),g("ratingValue",e),g("ratingText",n),g("ratingMade",!0),p(e),f(n),m(),r.onSelect.call(u,s(),o(),t),!1})},a=function(t){n(t),u.options.hoverState&&(t.on("mouseenter.barrating",function(){var t=v(this);h(),t.addClass("br-active")[c()]().addClass("br-active"),f(t.attr("data-rating-text"))}),u.$widget.on("mouseleave.barrating blur.barrating",function(){f(),m()}))},i=function(t){t.off(".barrating")},r=function(t){var e=u.$widget.find("a");l("userOptions").fastClicks&&e.on("touchstart.barrating",function(t){t.preventDefault(),t.stopPropagation(),v(this).click()}),t?(i(e),e.on("click.barrating",function(t){t.preventDefault()})):a(e)};this.show=function(){var i,t;l()||(t=["br-wrapper"],""!==u.options.theme&&t.push("br-theme-"+u.options.theme),u.$elem.wrap(v("
",{class:t.join(" ")})),e(),u.$widget=(i=v("",{class:"br-widget"}),u.$elem.find("option").each(function(){var t,e,n,a;(t=v(this).val())!==l("emptyRatingValue")&&(e=v(this).text(),(n=v(this).data("html"))&&(e=n),a=v("",{href:"#","data-rating-value":t,"data-rating-text":e,html:u.options.showValues?e:""}),i.append(a))}),u.options.showSelectedRating&&i.append(v("",{text:"",class:"br-current-rating"})),u.options.reverse&&i.addClass("br-reverse"),u.options.readonly&&i.addClass("br-readonly"),i),u.$widget.insertAfter(u.$elem),m(),f(),r(u.options.readonly),u.$elem.hide())},this.readonly=function(t){"boolean"==typeof t&&l("readOnly")!=t&&(r(t),g("readOnly",t),u.$widget.toggleClass("br-readonly"))},this.set=function(t){var e=l("userOptions");0!==u.$elem.find('option[value="'+t+'"]').length&&(g("ratingValue",t),g("ratingText",u.$elem.find('option[value="'+t+'"]').text()),g("ratingMade",!0),p(s()),f(o()),m(),e.silent||e.onSelect.call(this,s(),o()))},this.clear=function(){var t=l("userOptions");g("ratingValue",l("originalRatingValue")),g("ratingText",l("originalRatingText")),g("ratingMade",!1),v("option",u.$elem).prop("selected",function(){return this.defaultSelected}),l("userOptions").triggerChange&&u.$elem.change(),f(o()),m(),t.onClear.call(this,s(),o())},this.destroy=function(){var t=s(),e=o(),n=l("userOptions");i(u.$widget.find("a")),u.$widget.remove(),u.$elem.removeData("barrating"),u.$elem.unwrap(),u.$elem.show(),n.onDestroy.call(this,t,e)}}return t.prototype.init=function(t,e){return this.$elem=v(e),this.options=v.extend({},v.fn.barrating.defaults,t),this.options},t}();v.fn.barrating=function(e,n){return this.each(function(){var t=new a;if(v(this).is("select")||v.error("Sorry, this plugin only works with select fields."),t.hasOwnProperty(e)){if(t.init(n,this),"show"===e)return t.show(n);if(t.$elem.data("barrating"))return t.$widget=v(this).next(".br-widget"),t[e](n)}else{if("object"==typeof e||!e)return n=e,t.init(n,this),t.show();v.error("Method "+e+" does not exist on jQuery.barrating")}})},v.fn.barrating.defaults={theme:"",initialRating:null,allowEmpty:null,emptyValue:"",showValues:!1,showSelectedRating:!0,deselectable:!0,reverse:!1,readonly:!1,fastClicks:!0,hoverState:!0,silent:!1,triggerChange:!0,onSelect:function(t,e,n){},onClear:function(t,e){},onDestroy:function(t,e){}},v.fn.barrating.BarRating=a}); //# sourceMappingURL=jquery.barrating.min.js.map