Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adds forceRoundUp
  • Loading branch information
Ignacio Chavez authored and Ignacio Chavez committed Dec 18, 2017
1 parent bb896c9 commit 2062f08
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -85,6 +85,7 @@ http://nashio.github.io/star-rating-svg/demo
| strokeColor | black | Defines the color for the border |
| starShape | 'straight' or 'rounded' | Change the star shape type |
| baseUrl | false | when enabled (true), enables compatibility with the base tag in your head section |
| forceRoundUp | false | if true, forces rounding the initial rating to the nearest upper half even if the value is closer to the lower (1.1 -> 1.5 rather than 1.1 -> 1.0) |

## Methods

Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Expand Up @@ -194,7 +194,7 @@ <h4>On hover event</h4>

// basic use comes with defaults values
$(".my-rating").starRating({
initialRating: 2,
initialRating: 4.0,
starSize: 25
});

Expand Down
10 changes: 8 additions & 2 deletions dist/jquery.star-rating-svg.js
Expand Up @@ -42,15 +42,21 @@
// The actual plugin constructor
var Plugin = function( element, options ) {
var _rating;
var newRating;
var roundFn;

this.element = element;
this.$el = $(element);
this.settings = $.extend( {}, defaults, options );

// grab rating if defined on the element
_rating = this.$el.data('rating') || this.settings.initialRating;

// round to the nearest half
roundFn = this.settings.forceRoundUp ? Math.ceil : Math.round;
newRating = (roundFn( _rating * 2 ) / 2).toFixed(1);
this._state = {
// round to the nearest half
rating: (Math.round( _rating * 2 ) / 2).toFixed(1)
rating: newRating
};

// create unique id for stars
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.star-rating-svg.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/jquery.star-rating-svg.js
Expand Up @@ -42,15 +42,21 @@
// The actual plugin constructor
var Plugin = function( element, options ) {
var _rating;
var newRating;
var roundFn;

this.element = element;
this.$el = $(element);
this.settings = $.extend( {}, defaults, options );

// grab rating if defined on the element
_rating = this.$el.data('rating') || this.settings.initialRating;

// round to the nearest half
roundFn = this.settings.forceRoundUp ? Math.ceil : Math.round;
newRating = (roundFn( _rating * 2 ) / 2).toFixed(1);
this._state = {
// round to the nearest half
rating: (Math.round( _rating * 2 ) / 2).toFixed(1)
rating: newRating
};

// create unique id for stars
Expand Down

0 comments on commit 2062f08

Please sign in to comment.