(function(e){var t=0;var n=5;var r=.5;var i=function(t,n){return typeof t==="undefined"||t===null||t===undefined||t==[]||t===""||n&&e.trim(t)===""};var s=function(e,t,n){var r=i(e.data(t))?e.attr(t):e.data(t);if(r){return r}return n[t]};var o=function(e){var t=(""+e).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);if(!t){return 0}return Math.max(0,(t[1]?t[1].length:0)-(t[2]?+t[2]:0))};var u=function(e,t){return parseFloat(e.toFixed(t))};var a=function(t,n){this.$element=e(t);this.init(n)};a.prototype={constructor:a,_parseAttr:function(e,o){var u=this,a=u.$element;if(a.attr("type")==="range"||a.attr("type")==="number"){var f=s(a,e,o);var l=r;if(e==="min"){l=t}else if(e==="max"){l=n}else if(e==="step"){l=r}var c=i(f)?l:f;return parseFloat(c)}return parseFloat(o[e])},listen:function(){var t=this;t.$rating.on("click",function(e){if(!t.inactive){w=e.pageX-t.$rating.offset().left;t.setStars(w);t.$element.trigger("change");t.$element.trigger("rating.change",[t.$element.val(),t.$caption.html()])}});t.$clear.on("click",function(e){if(!t.inactive){t.clear()}});e(t.$element[0].form).on("reset",function(e){if(!t.inactive){t.reset()}})},initSlider:function(e){var s=this;if(i(s.$element.val())){s.$element.val(0)}s.initialValue=s.$element.val();s.min=typeof e.min!=="undefined"?e.min:s._parseAttr("min",e);s.max=typeof e.max!=="undefined"?e.max:s._parseAttr("max",e);s.step=typeof e.step!=="undefined"?e.step:s._parseAttr("step",e);if(isNaN(s.min)||i(s.min)){s.min=t}if(isNaN(s.max)||i(s.max)){s.max=n}if(isNaN(s.step)||i(s.step)||s.step==0){s.step=r}s.diff=s.max-s.min},init:function(t){var n=this;n.options=t;n.initSlider(t);n.checkDisabled();$element=n.$element;n.containerClass=t.containerClass;n.glyphicon=t.glyphicon;var r=n.glyphicon?"":"★";n.symbol=i(t.symbol)?r:t.symbol;n.rtl=t.rtl||n.$element.attr("dir");if(n.rtl){n.$element.attr("dir","rtl")}n.showClear=t.showClear;n.showCaption=t.showCaption;n.size=t.size;n.stars=t.stars;n.defaultCaption=t.defaultCaption;n.starCaptions=t.starCaptions;n.starCaptionClasses=t.starCaptionClasses;n.clearButton=t.clearButton;n.clearButtonTitle=t.clearButtonTitle;n.clearButtonBaseClass=!i(t.clearButtonBaseClass)?t.clearButtonBaseClass:"clear-rating";n.clearButtonActiveClass=!i(t.clearButtonActiveClass)?t.clearButtonActiveClass:"clear-rating-active";n.clearCaption=t.clearCaption;n.clearCaptionClass=t.clearCaptionClass;n.clearValue=t.clearValue;n.$element.removeClass("form-control").addClass("form-control");n.$clearElement=i(t.clearElement)?null:e(t.clearElement);n.$captionElement=i(t.captionElement)?null:e(t.captionElement);if(typeof n.$rating=="undefined"&&typeof n.$container=="undefined"){n.$rating=e(document.createElement("div")).html('
');n.$container=e(document.createElement("div"));n.$container.before(n.$rating);n.$container.append(n.$rating);n.$element.before(n.$container).appendTo(n.$rating)}n.$stars=n.$rating.find(".rating-stars");n.generateRating();n.$clear=!i(n.$clearElement)?n.$clearElement:n.$container.find("."+n.clearButtonBaseClass);n.$caption=!i(n.$captionElement)?n.$captionElement:n.$container.find(".caption");n.setStars();n.$element.hide();n.listen();if(n.showClear){n.$clear.attr({"class":n.getClearClass()})}n.$element.removeClass("rating-loading")},checkDisabled:function(){var e=this;e.disabled=s(e.$element,"disabled",e.options);e.readonly=s(e.$element,"readonly",e.options);e.inactive=e.disabled||e.readonly},getClearClass:function(){return this.clearButtonBaseClass+" "+(this.inactive?"":this.clearButtonActiveClass)},generateRating:function(){var e=this,t=e.renderClear(),n=e.renderCaption(),r=e.rtl?"rating-container-rtl":"rating-container",s=e.getStars();r+=e.glyphicon?e.symbol==""?" rating-gly-star":" rating-gly":" rating-uni";e.$rating.attr("class",r);e.$rating.attr("data-content",s);e.$stars.attr("data-content",s);var r=e.rtl?"star-rating-rtl":"star-rating";e.$container.attr("class",r+" rating-"+e.size);if(e.inactive){e.$container.removeClass("rating-active").addClass("rating-disabled")}else{e.$container.removeClass("rating-disabled").addClass("rating-active")}if(typeof e.$caption=="undefined"&&typeof e.$clear=="undefined"){if(e.rtl){e.$container.prepend(n).append(t)}else{e.$container.prepend(t).append(n)}}if(!i(e.containerClass)){e.$container.removeClass(e.containerClass).addClass(e.containerClass)}},getStars:function(){var e=this,t=e.stars,n="";for(var r=1;r<=t;r++){n+=e.symbol}return n},renderClear:function(){var e=this;if(!e.showClear){return""}var t=e.getClearClass();if(!i(e.$clearElement)){e.$clearElement.removeClass(t).addClass(t).attr({title:e.clearButtonTitle});e.$clearElement.html(e.clearButton);return""}return'
'+e.clearButton+"
"},renderCaption:function(){var e=this,t=e.$element.val();if(!e.showCaption){return""}var n=e.fetchCaption(t);if(!i(e.$captionElement)){e.$captionElement.removeClass("caption").addClass("caption").attr({title:e.clearCaption});e.$captionElement.html(n);return""}return'
'+n+"
"},fetchCaption:function(e){var t=this;var n=parseFloat(e);var r=i(t.starCaptionClasses[n])?t.clearCaptionClass:t.starCaptionClasses[n];var s=!i(t.starCaptions[n])?t.starCaptions[n]:t.defaultCaption.replace(/\{rating\}/g,n);var o=n==t.clearValue?t.clearCaption:s;return''+o+""},getValueFromPosition:function(e){var t=this,n=o(t.step),r,i,s=t.$rating.width();r=e/s;if(t.rtl){i=t.min+Math.floor(t.diff*r/t.step)*t.step}else{i=t.min+Math.ceil(t.diff*r/t.step)*t.step}if(it.max){i=t.max}i=u(parseFloat(i),n);if(t.rtl){i=t.max-i}return i},setStars:function(e){var t=this,n=t.min,r=t.max,s=t.step,o=arguments.length?t.getValueFromPosition(e):i(t.$element.val())?0:t.$element.val(),u=0,a=t.$rating.width(),f=t.fetchCaption(o);u=(o-n)/r*100;if(t.rtl){u=100-u}t.$element.val(o);u+="%";t.$stars.css("width",u);t.$caption.html(f)},clear:function(){var e=this;var t=''+e.clearCaption+"";e.$stars.removeClass("rated");if(!e.inactive){e.$caption.html(t)}e.$element.val(e.clearValue);e.setStars();e.$element.trigger("rating.clear")},reset:function(){var e=this;e.$element.val(e.initialValue);e.setStars();e.$element.trigger("rating.reset")},update:function(e){if(arguments.length>0){var t=this;t.$element.val(e);t.setStars()}},refresh:function(t){var n=this;if(arguments.length){var r="";n.init(e.extend(n.options,t));if(n.showClear){n.$clear.show()}else{n.$clear.hide()}if(n.showCaption){n.$caption.show()}else{n.$caption.hide()}}}};e.fn.rating=function(t){var n=Array.apply(null,arguments);n.shift();return this.each(function(){var r=e(this),i=r.data("rating"),s=typeof t==="object"&&t;if(!i){r.data("rating",i=new a(this,e.extend({},e.fn.rating.defaults,s,e(this).data())))}if(typeof t==="string"){i[t].apply(i,n)}})};e.fn.rating.defaults={stars:5,glyphicon:true,symbol:null,disabled:false,readonly:false,rtl:false,size:"md",showClear:true,showCaption:true,defaultCaption:"Media {rating}/5",starCaptions:{.5:"Ciofeca",1:"Pessimo",1.5:"Inutile",2:"Evitabile",2.5:"Acquistabile",3:"Sufficiente",3.5:"Buono",4:"Ottimo",4.5:"Speciale",5:"TOP"},starCaptionClasses:{.5:"label label-danger",1:"label label-danger",1.5:"label label-warning",2:"label label-warning",2.5:"label label-info",3:"label label-info",3.5:"label label-primary",4:"label label-primary",4.5:"label label-success",5:"label label-success"},clearButton:'',clearButtonTitle:"Pulisci",clearButtonBaseClass:"clear-rating",clearButtonActiveClass:"clear-rating-active", clearCaption:"Seleziona le Stelle",clearCaptionClass:"label label-default",clearValue:0,captionElement:null,clearElement:null,containerClass:null};e("input.rating").addClass("rating-loading");e(document).ready(function(){var t=e("input.rating"),n=Object.keys(t).length;if(n>0){t.rating()}})})(jQuery)