Skip to content

Commit

Permalink
Merge pull request #14 from epeli/done_cb_fix
Browse files Browse the repository at this point in the history
Do not call done callback if the color did not change
  • Loading branch information
bebraw committed Jul 11, 2012
2 parents cf65629 + 5d89815 commit 6c341d5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/colorjoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 6c341d5

Please sign in to comment.