Skip to content

Commit

Permalink
Provide a way to make callbacks work with the cancel element
Browse files Browse the repository at this point in the history
When cancel is selected, there is no corresponding input element, which means
that this is set to null in the callback function.

The "link" parameter to the callback function is set to the first 'a' child of
null, which translates to the first link on the page.

Fix the link parameter, by setting a rater-cancel-# (where # is the rater
serial number) class on the cancel element, so that we can identify the element
later in the select function.
  • Loading branch information
ksmadsen committed Aug 6, 2014
1 parent f8abe38 commit 8261d7b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions jquery.rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

// Create 'cancel' button
rater.append(
control.cancel = $('<div class="rating-cancel"><a title="' + control.cancel + '">' + control.cancelValue + '</a></div>')
control.cancel = $('<div class="rating-cancel rater-cancel-' + control.serial + '"><a title="' + control.cancel + '">' + control.cancelValue + '</a></div>')
.on('mouseover',function(){
$(this).rating('drain');
$(this).addClass('star-rating-hover');
Expand Down Expand Up @@ -293,7 +293,7 @@
} else {
control.current = this[0].tagName=='INPUT' ?
this.data('rating.star') :
(this.is('.rater-'+ control.serial) ? this : null);
((this.is('.rater-'+ control.serial) || this.is('.rater-cancel-' + control.serial)) ? this : null);
}
// Update rating control state
this.data('rating', control);
Expand Down

1 comment on commit 8261d7b

@fyneworks
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea. Thanks for sharing!

Please sign in to comment.