Skip to content

Commit

Permalink
Modified setInterval to setTimeout. Also changed 'null' to 'undefined'.
Browse files Browse the repository at this point in the history
Closes #3, Closes #4.
  • Loading branch information
fcarriedo committed Feb 6, 2011
1 parent 8ab8ad0 commit 7b46b40
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/jquery.blink.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
$.fn.blink = function( options ) {

var settings = {
maxBlinks : null,
maxBlinks : undefined,
blinkPeriod : 1000,
onMaxBlinks : function() {},
onBlink : function() {},
speed : null
speed : undefined
};

if(options) {
Expand All @@ -28,9 +28,7 @@
var blinkCount = 0;
settings.speed = settings.speed ? settings.speed : settings.blinkPeriod/2;

toggleFade(); // Toggle first fade, then leave it to the interval.

var intervalId = setInterval(toggleFade, settings.blinkPeriod/2);
toggleFade(); // Toggle first fade, then leave it to setTimeout.

function toggleFade() {
if(on){
Expand All @@ -39,11 +37,16 @@
var maxBlinksReached = (settings.maxBlinks && (++blinkCount) >= settings.maxBlinks);
blinkElem.fadeTo(settings.speed, 1, function() {
settings.onBlink.call();
if(maxBlinksReached) settings.onMaxBlinks.call();
if(maxBlinksReached) {
settings.onMaxBlinks.call();
}
});
if(maxBlinksReached) clearInterval(intervalId);
}
on = !on;

if(!maxBlinksReached) {
setTimeout(toggleFade, settings.blinkPeriod/2); // #3
}
}

return this; // Returning 'this' to maintain chainability.
Expand Down

0 comments on commit 7b46b40

Please sign in to comment.