diff --git a/README.md b/README.md index 693b399..b6f59ac 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,15 @@ Sure! You can set min and max values adding `data-min` and `data-max`: +### Can I set a default value? + +Definitely, just set an integer value in your input that makes sense: + + + ### Can I set a special value for empty ratings? -You can add the attribute `data-empty-value` to indicate which value should send the form when it have an empty rating. This can be used, for example, to have an special value indicating the user didn't seleted anything: +You can add the attribute `data-empty-value` to indicate which value should send the form when it have an empty rating. This can be used, for example, to have an special value indicating the user didn't select anything: diff --git a/build/bootstrap-rating-input.min.js b/build/bootstrap-rating-input.min.js index 726394e..4bcec86 100644 --- a/build/bootstrap-rating-input.min.js +++ b/build/bootstrap-rating-input.min.js @@ -1 +1 @@ -!function(a){var b="rating-clear",c="."+b,d="hidden",e=function(a){return"[data-value"+(a?"="+a:"")+"]"},f=function(a,b,c){var d=c["active-icon"],e=c["inactive-icon"];a.removeClass(b?e:d).addClass(b?d:e)},g=function(c,d){for(var e=d.min,f=d.max,g=d.clearable,h=a('
'),i=e;f>=i;i++)h.append('');return g&&h.append(" ").append(''+g+""),h},h=function(a){var b={};for(option in i)b[option]=a.data(option);return b},i={min:1,max:5,"icon-lib":"glyphicon","active-icon":"glyphicon-star","inactive-icon":"glyphicon-star-empty",clearable:"","clearable-icon":"glyphicon-remove"},j=function(b,c){var e=this.$input=a(b),f=this.options=a.extend({},i,h(e),c),j=this.$el=g(e,f);e.addClass(d).before(j),this.highlight(f.value)};j.VERSION="0.3.0",j.DEFAULTS=i,j.prototype={clear:function(){this.setValue(this.options.min-1)},setValue:function(a){this.highlight(a),this.updateInput(a)},highlight:function(a,b){var g=this.options,h=a-g.min+1,i=this.$el,j=i.find(e(h));h?(f(j.prevAll("i").andSelf(),!0,g),f(j.nextAll("i"),!1,g)):f(j,!1,g),b||i.find(c).toggleClass(d,!h)},updateInput:function(a){var b=a+this.options.min-1,c=this.$input;c.val()!=b&&c.val(b).change()}};var k=a.fn.rating=function(b){return this.each(function(){var d=a(this),f="rating",g=d.data(f),h="object"==typeof b&&b;g||(g=new j(d,h),g.$el.on("mouseenter",e(),function(){g.highlight(a(this).data("value"),!0)}).on("mouseleave",e(),function(){g.highlight(d.val(),!0)}).on("click",e(),function(){g.setValue(a(this).data("value"))}).on("click",c,function(){g.clear()}),d.data(f,g)),"clear"===b?g.clear():"setValue"===b&&g.setValue(arguments[1])})};k.Constructor=j,a(function(){a("input.rating[type=number]").each(function(){a(this).rating()})})}(jQuery); \ No newline at end of file +!function(a){var b="rating-clear",c="."+b,d="hidden",e=function(a){return"[data-value"+(a?"="+a:"")+"]"},f=function(a,b,c){var d=c["active-icon"],e=c["inactive-icon"];a.removeClass(b?e:d).addClass(b?d:e)},g=function(c,d){for(var e=d.min,f=d.max,g=d.clearable,h=a('
'),i=e;f>=i;i++)h.append('');return g&&h.append(" ").append(''+g+""),h},h=function(a){var b={};for(option in i)b[option]=a.data(option);return b},i={min:1,max:5,"empty-value":0,"icon-lib":"glyphicon","active-icon":"glyphicon-star","inactive-icon":"glyphicon-star-empty",clearable:"","clearable-icon":"glyphicon-remove"},j=function(b,c){var e=this.$input=a(b),f=this.options=a.extend({},i,h(e),c),j=this.$el=g(e,f);e.addClass(d).before(j),this.highlight(e.val())};j.VERSION="0.3.0",j.DEFAULTS=i,j.prototype={clear:function(){this.setValue(this.options["empty-value"])},setValue:function(a){this.highlight(a),this.updateInput(a)},highlight:function(a,b){var g=this.options,h=this.$el;if(a>=this.options.min&&a<=this.options.max){var i=h.find(e(a));f(i.prevAll("i").andSelf(),!0,g),f(i.nextAll("i"),!1,g)}else f(h.find(e()),!1,g);b||(a&&a!=this.options["empty-value"]?h.find(c).removeClass(d):h.find(c).addClass(d))},updateInput:function(a){var b=this.$input;b.val()!=a&&b.val(a).change()}};var k=a.fn.rating=function(b){return this.each(function(){var d=a(this),f="rating",g=d.data(f),h="object"==typeof b&&b;g||(g=new j(d,h),g.$el.on("mouseenter",e(),function(){g.highlight(a(this).data("value"),!0)}).on("mouseleave",e(),function(){g.highlight(d.val(),!0)}).on("click",e(),function(){g.setValue(a(this).data("value"))}).on("click",c,function(){g.clear()}),d.data(f,g)),"clear"===b?g.clear():"setValue"===b&&g.setValue(arguments[1])})};k.Constructor=j,a(function(){a("input.rating[type=number]").each(function(){a(this).rating()})})}(jQuery); \ No newline at end of file diff --git a/demo.html b/demo.html index 880fbb1..6387102 100644 --- a/demo.html +++ b/demo.html @@ -5,7 +5,7 @@ - +