forked from dobtco/starrr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarrr.min.js
1 lines (1 loc) · 2.55 KB
/
starrr.min.js
1
var __slice=[].slice;!function(a,b){var c;return b.Starrr=c=function(){function b(b,c){var d,e,f;this.options=a.extend({},this.defaults,c),this.$el=b,f=this.defaults;for(d in f)e=f[d],null!=this.$el.data(d.toLowerCase())&&(this.options[d]=this.$el.data(d.toLowerCase()));this.$el.data("connected-input")&&(this.$connectedInput=a('[name="'+this.$el.data("connected-input")+'"]'),this.options.rating=this.$connectedInput.val()?parseInt(this.$connectedInput.val(),10):void 0),this.createStars(),this.syncRating(),this.$connectedInput&&this.$connectedInput.is(":disabled")||(this.$el.on("mouseover.starrr","i",function(a){return function(b){return a.syncRating(a.getStars().index(b.currentTarget)+1)}}(this)),this.$el.on("mouseout.starrr",function(a){return function(){return a.syncRating()}}(this)),this.$el.on("click.starrr","i",function(a){return function(b){return a.setRating(a.getStars().index(b.currentTarget)+1)}}(this)),this.$el.on("starrr:change",this.options.change),null!=this.$connectedInput&&this.$el.on("starrr:change",function(a){return function(b,c){return a.$connectedInput.val(c),a.$connectedInput.trigger("focusout")}}(this)))}return b.prototype.defaults={rating:void 0,numStars:5,emptyStarClass:"fa fa-star-o",fullStarClass:"fa fa-star",change:function(){}},b.prototype.getStars=function(){return this.$el.find("i")},b.prototype.createStars=function(){var a,b,c;for(c=[],a=1,b=this.options.numStars;b>=1?b>=a:a>=b;b>=1?a++:a--)c.push(this.$el.append("<i class='"+this.options.emptyStarClass+"'></i>"));return c},b.prototype.setRating=function(a){return this.options.rating===a&&(a=void 0),this.options.rating=a,this.syncRating(),this.$el.trigger("starrr:change",a)},b.prototype.getRating=function(){return this.options.rating},b.prototype.syncRating=function(a){var b,c,d,e,f;if(a||(a=this.options.rating),a)for(b=c=0,e=a-1;e>=0?e>=c:c>=e;b=e>=0?++c:--c)this.getStars().eq(b).removeClass(this.options.emptyStarClass).addClass(this.options.fullStarClass);if(a&&a<this.options.numStars)for(b=d=a,f=this.options.numStars-1;f>=a?f>=d:d>=f;b=f>=a?++d:--d)this.getStars().eq(b).removeClass(this.options.fullStarClass).addClass(this.options.emptyStarClass);return a?void 0:this.getStars().removeClass(this.options.fullStarClass).addClass(this.options.emptyStarClass)},b}(),a.fn.extend({starrr:function(){var b,d;return d=arguments[0],b=2<=arguments.length?__slice.call(arguments,1):[],this.each(function(){var e;return e=a(this).data("starrr"),e||a(this).data("starrr",e=new c(a(this),d)),"string"==typeof d?e[d].apply(e,b):void 0})}})}(window.jQuery,window),$(function(){return $(".starrr").starrr()});