Skip to content
Permalink
Browse files

Pulsate: Rewrote pulsate effect.

Fixes #4718 - pulsate pulses one extra time.
  • Loading branch information
scottgonzalez committed Nov 16, 2009
1 parent 6fdc4b5 commit 31a5ee94a9ac8cfb2a7194aba130481abe9c9f22
Showing with 27 additions and 32 deletions.
  1. +27 −32 ui/jquery.effects.pulsate.js
@@ -13,44 +13,39 @@
(function($) {

$.effects.pulsate = function(o) {

return this.queue(function() {
var elem = $(this),
mode = $.effects.setMode(elem, o.options.mode || 'show');
times = ((o.options.times || 5) * 2) - 1;
duration = o.duration ? o.duration / 2 : $.fx.speeds._default / 2,
isVisible = elem.is(':visible'),
animateTo = 0;

if (!isVisible) {
elem.css('opacity', 0).show();
animateTo = 1;
}

// Create element
var el = $(this);

// Set options
var mode = $.effects.setMode(el, o.options.mode || 'show'); // Set Mode
var times = o.options.times || 5; // Default # of times
var duration = o.duration ? o.duration / 2 : $.fx.speeds._default / 2;
if ((mode == 'hide' && isVisible) || (mode == 'show' && !isVisible)) {
times--;
}

// Adjust
if (mode == 'hide') times--;
if (el.is(':hidden')) { // Show fadeIn
el.css('opacity', 0);
el.show(); // Show
el.animate({opacity: 1}, duration, o.options.easing);
times = times-2;
for (var i = 0; i < times; i++) {
elem.animate({ opacity: animateTo }, duration, o.options.easing);
animateTo = (animateTo + 1) % 2;
}

// Animate
for (var i = 0; i < times; i++) { // Pulsate
el.animate({opacity: 0}, duration, o.options.easing).animate({opacity: 1}, duration, o.options.easing);
};
if (mode == 'hide') { // Last Pulse
el.animate({opacity: 0}, duration, o.options.easing, function(){
el.hide(); // Hide
if(o.callback) o.callback.apply(this, arguments); // Callback
});
} else {
el.animate({opacity: 0}, duration, o.options.easing).animate({opacity: 1}, duration, o.options.easing, function(){
if(o.callback) o.callback.apply(this, arguments); // Callback
});
};
el.queue('fx', function() { el.dequeue(); });
el.dequeue();
});
elem.animate({ opacity: animateTo }, duration, o.options.easing, function() {
if (animateTo == 0) {
elem.hide();
}
(o.callback && o.callback.apply(this, arguments));
});

elem
.queue('fx', function() { elem.dequeue(); })
.dequeue();
});
};

})(jQuery);

0 comments on commit 31a5ee9

Please sign in to comment.
You can’t perform that action at this time.