Skip to content

Commit

Permalink
Made the running of the callback in the toggle function more graceful.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Caldwell committed Apr 2, 2011
1 parent 9eb609a commit 9067126
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ SparkFn.toggle = function(method, timeframe, easing, callback) {
if(method === 'visibility') {
// Toggle transition with either show or hide
Spark(element).transition(((element.style.display === 'none') ? 'show' : 'hide'), timeframe, easing);

// Set the timeframe to 0
timeframe = 0;
}
else {
// Toggle transition with the calculated method
Expand All @@ -63,8 +60,15 @@ SparkFn.toggle = function(method, timeframe, easing, callback) {
}
}

// Set the callback to be run
setTimeout(callback, timeframe);
// Check how the callback needs to be run
if(method === 'visibility') {
// Run the callback
callback();
}
else {
// Set the callback to be run
setTimeout(callback, timeframe);
}

// Set up the offset for chaining
this.offset += timeframe;
Expand Down

0 comments on commit 9067126

Please sign in to comment.