Skip to content

Commit

Permalink
Merge pull request #199 from yskkin/click_half
Browse files Browse the repository at this point in the history
Click callback receive rounded score if half is true.
  • Loading branch information
wbotelhos authored Oct 19, 2020
2 parents fdbf543 + 44b571f commit a829c5b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/jquery.raty.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@
execute = true,
score = (that.opt.half || that.opt.precision) ? that.self.data('score') : (this.alt || $(this).data('alt'));

if (that.opt.half && !that.opt.precision) {
score = methods._roundHalfScore.call(that, score);
}

if (that.opt.click) {
execute = that.opt.click.call(that, +score, evt);
}

if (execute || execute === undefined) {
if (that.opt.half && !that.opt.precision) {
score = methods._roundHalfScore.call(that, score);
}

methods._apply.call(that, +score);
}
});
Expand Down
30 changes: 30 additions & 0 deletions spec/half_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ describe('#half', function() {
// then
expect(this.el.children('input').val()).toEqual('1.5');
});

it ('gives a callback the rounded value', function() {
// given
this.el.raty({
half : true,
halfShow : true,
click : function(score) {
// then
expect(score).toEqual(1.5);
}
});

// when
Helper.click(this.el, 1, 5);
});
});

context('into round area', function() {
Expand All @@ -92,6 +107,21 @@ describe('#half', function() {
// then
expect(this.el.children('input').val()).toEqual('2');
});

it ('gives a callback the rounded value', function() {
// given
this.el.raty({
half: true,
halfShow: true,
click: function(score) {
// then
expect(score).toEqual(2);
}
});

// when
Helper.click(this.el, 1, 9);
});
});

context('into zero position', function() {
Expand Down

0 comments on commit a829c5b

Please sign in to comment.