Landing pull request 514. 1.7 - queue refactoring to handle delay stop - Fixes #6150.

More Details:
 - https://github.com/jquery/jquery/pull/514
 - http://bugs.jquery.com/ticket/6150
This commit is contained in:
Corey Frang
2011-09-28 11:55:29 -04:00
committed by timmywil
parent a74cbb2b91
commit a3b59d7f92
4 changed files with 150 additions and 30 deletions

66
src/effects.js vendored
View File

@@ -200,6 +200,7 @@ jQuery.fn.extend({
val = prop[ p ];
if ( rfxtypes.test( val ) ) {
// Tracks whether to show or hide based on private
// data attached to the element
method = jQuery._data( this, "toggle" + p ) || (val === "toggle" ? hidden ? "show" : "hide" : 0);
@@ -244,42 +245,62 @@ jQuery.fn.extend({
return optall.queue === false ?
this.each( doAnimation ) :
this.queue( optall.queue || "fx", doAnimation );
this.queue( optall.queue, doAnimation );
},
stop: function( clearQueue, gotoEnd ) {
if ( clearQueue ) {
this.queue([]);
stop: function( clearQueue, gotoEnd, type ) {
if ( clearQueue && type !== false ) {
this.queue( type || "fx", [] );
}
this.each(function() {
var timers = jQuery.timers,
i = timers.length;
return this.each(function() {
var i,
hadTimers = false,
timers = jQuery.timers,
data = jQuery._data( this );
// clear marker counters if we know they won't be
if ( !gotoEnd ) {
jQuery._unmark( true, this );
}
while ( i-- ) {
if ( timers[ i ].elem === this ) {
function stopQueue( elem, data, i ) {
var runner = data[ i ];
jQuery.removeData( elem, i, true );
runner.stop( gotoEnd );
}
if ( type == null ) {
for ( i in data ) {
if ( data[ i ].stop && i.indexOf(".run") === i.length - 4 ) {
stopQueue( this, data, i );
}
}
} else if ( data[ i = type + ".run" ] && data[ i ].stop ){
stopQueue( this, data, i );
}
for ( i = timers.length; i--; ) {
if ( timers[ i ].elem === this && (type == null || timers[ i ].queue === type) ) {
if ( gotoEnd ) {
// force the next step to be the last
timers[ i ]( true );
} else {
timers[ i ].saveState();
}
hadTimers = true;
timers.splice( i, 1 );
}
}
// start the next in the queue if the last step wasn't forced
// timers currently will call their complete callbacks, which will dequeue
// but only if they were gotoEnd
if ( !( gotoEnd && hadTimers ) ) {
jQuery.dequeue( this, type );
}
});
// start the next in the queue if the last step wasn't forced
if ( !gotoEnd ) {
this.dequeue();
}
return this;
}
});
@@ -331,15 +352,21 @@ jQuery.extend({
opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
// if undefined, set to fx
if ( opt.queue == null ) {
opt.queue = "fx";
}
// Queueing
opt.old = opt.complete;
opt.complete = function( noUnmark ) {
if ( jQuery.isFunction( opt.old ) ) {
opt.old.call( this );
}
if ( opt.queue !== false ) {
jQuery.dequeue( this, opt.queue || "fx" );
if ( opt.queue ) {
jQuery.dequeue( this, opt.queue );
} else if ( noUnmark !== false ) {
jQuery._unmark( this );
}
@@ -408,6 +435,7 @@ jQuery.fx.prototype = {
return self.step( gotoEnd );
}
t.queue = this.options.queue;
t.elem = this.elem;
t.saveState = function() {
if ( self.options.hide && jQuery._data( self.elem, "fxshow" + self.prop ) === undefined ) {

View File

@@ -70,7 +70,8 @@ jQuery.extend({
type = type || "fx";
var queue = jQuery.queue( elem, type ),
fn = queue.shift();
fn = queue.shift(),
runner = {};
// If the fx queue is dequeued, always remove the progress sentinel
if ( fn === "inprogress" ) {
@@ -81,16 +82,17 @@ jQuery.extend({
// Add a progress sentinel to prevent the fx queue from being
// automatically dequeued
if ( type === "fx" ) {
queue.unshift("inprogress");
queue.unshift( "inprogress" );
}
fn.call(elem, function() {
jQuery._data( elem, type + ".run", runner );
fn.call( elem, function() {
jQuery.dequeue( elem, type );
});
}, runner );
}
if ( !queue.length ) {
jQuery.removeData( elem, type + "queue", true );
jQuery.removeData( elem, type + "queue " + type + ".run", true );
handleQueueMarkDefer( elem, type, "queue" );
}
}
@@ -125,11 +127,11 @@ jQuery.fn.extend({
time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
type = type || "fx";
return this.queue( type, function() {
var elem = this;
setTimeout(function() {
jQuery.dequeue( elem, type );
}, time );
return this.queue( type, function( next, runner ) {
var timeout = setTimeout( next, time );
runner.stop = function() {
clearTimeout( timeout );
};
});
},
clearQueue: function( type ) {