Skip to content

Commit 9aa1572

Browse files
committed
Check the completed timer has not been removed already so other timers do not get accidentally removed. Fixes #6641.
1 parent 19b949c commit 9aa1572

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/effects.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,15 @@ jQuery.fx.prototype = {
537537

538538
jQuery.extend( jQuery.fx, {
539539
tick: function() {
540-
for ( var timers = jQuery.timers, i = 0; i < timers.length; i++ ) {
541-
if ( !timers[ i ]() ) {
542-
timers.splice(i--, 1);
540+
var timer,
541+
timers = jQuery.timers,
542+
i = 0;
543+
544+
for ( ; i < timers.length; i++ ) {
545+
timer = timers[ i ];
546+
// Checks the timer has not already been removed
547+
if ( !timer() && timers[ i ] === timer ) {
548+
timers.splice( i--, 1 );
543549
}
544550
}
545551

test/unit/effects.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -432,19 +432,19 @@ test("animate duration 0", function() {
432432
$elem.remove();
433433
});
434434

435-
test("animate hyphenated properties", function(){
435+
test("animate hyphenated properties", function() {
436436
expect(1);
437437
stop();
438438

439439
jQuery("#foo")
440440
.css("font-size", 10)
441-
.animate({"font-size": 20}, 200, function(){
441+
.animate({"font-size": 20}, 200, function() {
442442
equals( this.style.fontSize, "20px", "The font-size property was animated." );
443443
start();
444444
});
445445
});
446446

447-
test("animate non-element", function(){
447+
test("animate non-element", function() {
448448
expect(1);
449449
stop();
450450

@@ -457,28 +457,42 @@ test("animate non-element", function(){
457457
});
458458

459459
test("stop()", function() {
460-
expect(3);
460+
expect(4);
461461
stop();
462462

463463
var $foo = jQuery("#foo");
464464
var w = 0;
465-
$foo.hide().width(200).width();
466465

467-
$foo.animate({ width: "show" }, 1000);
468-
setTimeout(function(){
466+
$foo.hide().width(200)
467+
.animate({ width: "show" }, 1000);
468+
469+
setTimeout(function() {
469470
var nw = $foo.width();
470471
notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
471472
$foo.stop();
472473

473474
nw = $foo.width();
474475
notEqual( nw, w, "Stop didn't reset the animation " + nw + "px " + w + "px");
475-
setTimeout(function(){
476+
setTimeout(function() {
476477
$foo.removeData();
477478
$foo.removeData(undefined, true);
478479
equals( nw, $foo.width(), "The animation didn't continue" );
479480
start();
480481
}, 100);
481482
}, 100);
483+
484+
var $one = jQuery("#fadein");
485+
var $two = jQuery("#show");
486+
$one.fadeTo(100, 0, function() {
487+
$one.stop();
488+
});
489+
setTimeout(function() {
490+
$two.fadeTo(100, 0, function() {
491+
equal( $two.css("opacity"), "0", "Stop does not interfere with animations on other elements (#6641)" );
492+
// Reset styles
493+
$one.add( $two ).css("opacity", "");
494+
});
495+
}, 50);
482496
});
483497

484498
test("stop() - several in queue", function() {

0 commit comments

Comments
 (0)