Skip to content

Instantly share code, notes, and snippets.

@olleolleolle
Created October 15, 2010 11:07
Show Gist options
  • Save olleolleolle/628017 to your computer and use it in GitHub Desktop.
Save olleolleolle/628017 to your computer and use it in GitHub Desktop.
Makes the onclick handler have a "this" that is the useful star element.
diff --git a/js/jquery.raty.js b/js/jquery.raty.js
index cefc128..7b09b81 100755
--- a/js/jquery.raty.js
+++ b/js/jquery.raty.js
@@ -140,7 +140,7 @@
.live('click', function() {
$('input#' + containerId + '-score').val(0);
if (onClick) {
- onClick(0);
+ onClick.apply($this, [0]);
}
});
} else {
@@ -162,7 +162,7 @@
.live('click', function() {
$('input#' + containerId + '-score').val(this.alt);
if (onClick) {
- onClick(this.alt);
+ onClick.apply($this, [this.alt]);
}
});
@@ -241,7 +241,7 @@
var star = (score >= options.number) ? options.number : score;
initialize(star);
if (options.onClick) {
- options.onClick(star);
+ options.onClick.apply($this, [star]);
} else {
debug('You should add the "onClick: function() {}" option.');
}
@wbotelhos
Copy link

Hi Jonsson,

I didn't know about the "apply", it's cool.
Feel free to other contributions, I would be very happy.

Thank you. (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment