Skip to content
Browse files

Merge pull request #14 from epeli/done_cb_fix

Do not call done callback if the color did not change
  • Loading branch information...
2 parents cf65629 + 5d89815 commit 6c341d5e3390611a191775eb21e99c328c457db2 @bebraw committed Jul 11, 2012
Showing with 10 additions and 3 deletions.
  1. +10 −3 src/colorjoe.js
View
13 src/colorjoe.js
@@ -112,17 +112,24 @@ function setup(o) {
changed();
}
- var col = cbs.init(getColor(o.color), xy, z);
+ // Initial color
+ var previous = getColor(o.color);
+ var col = cbs.init(previous, xy, z);
var listeners = {change: [], done: []};
function changed() {
- for(var i = 0, len = listeners.change.length; i < len; i++)
+ for(var i = 0, len = listeners.change.length; i < len; i++) {
listeners.change[i](col);
+ }
}
function done() {
- for(var i = 0, len = listeners.done.length; i < len; i++)
+ // Do not call done callback if the color did not change
+ if (previous.equals(col)) return;
+ for(var i = 0, len = listeners.done.length; i < len; i++) {
listeners.done[i](col);
+ }
+ previous = col;
}
var ob = {

0 comments on commit 6c341d5

Please sign in to comment.
Something went wrong with that request. Please try again.