Skip to content

Commit

Permalink
Bug fixes in queue.js: type in dequeue could be undefined which lead …
Browse files Browse the repository at this point in the history
…to a wrong data key, which would then have undesirable data left dangling on elements. Also adds missing semicolon in effects unit.
  • Loading branch information
jaubourg committed Apr 11, 2011
1 parent f6f1cc7 commit 2b70893
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 7 additions & 12 deletions src/queue.js
Expand Up @@ -7,7 +7,7 @@ function handleQueueMarkDefer( elem, type, src ) {
defer = jQuery.data( elem, deferDataKey, undefined, true );
if ( defer &&
( src === "queue" || !jQuery.data( elem, queueDataKey, undefined, true ) ) &&
( src === "mark " || !jQuery.data( elem, markDataKey, undefined, true ) ) ) {
( src === "mark" || !jQuery.data( elem, markDataKey, undefined, true ) ) ) {
// Give room for hard-coded callbacks to fire first
// and eventually mark/queue something else on the element
setTimeout( function() {
Expand Down Expand Up @@ -35,13 +35,10 @@ jQuery.extend({
elem = force;
force = false;
}

if ( elem ) {
type = type || "fx";

var key = type + "mark",
count = force ? 0 : ( (jQuery.data( elem, key, undefined, true) || 1 ) - 1 );

if ( count ) {
jQuery.data( elem, key, count, true );
} else {
Expand All @@ -54,21 +51,22 @@ jQuery.extend({
queue: function( elem, type, data ) {
if ( elem ) {
type = (type || "fx") + "queue";
var q = jQuery.data( elem, type, undefined, true ) || [];

var q = jQuery.data( elem, type, undefined, true );
// Speed up dequeue by getting out quickly if this is just a lookup
if ( data ) {
if ( !q.length || jQuery.isArray(data) ) {
if ( !q || jQuery.isArray(data) ) {
q = jQuery.data( elem, type, jQuery.makeArray(data), true );
} else {
q.push( data );
}
}
return q;
return q || [];
}
},

dequeue: function( elem, type ) {
type = type || "fx";

var queue = jQuery.queue( elem, type ),
fn = queue.shift(),
defer;
Expand Down Expand Up @@ -107,7 +105,7 @@ jQuery.fn.extend({
if ( data === undefined ) {
return jQuery.queue( this[0], type );
}
return this.each(function( i ) {
return this.each(function() {
var queue = jQuery.queue( this, type, data );

if ( type === "fx" && queue[0] !== "inprogress" ) {
Expand All @@ -120,7 +118,6 @@ jQuery.fn.extend({
jQuery.dequeue( this, type );
});
},

// Based off of the plugin by Clint Helfers, with permission.
// http://blindsignals.com/index.php/2009/07/jquery-delay/
delay: function( time, type ) {
Expand All @@ -134,11 +131,9 @@ jQuery.fn.extend({
}, time );
});
},

clearQueue: function( type ) {
return this.queue( type || "fx", [] );
},

// Get a promise resolved when queues of a certain type
// are emptied (fx is the type by default)
promise: function( type, object ) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/effects.js
Expand Up @@ -807,7 +807,7 @@ jQuery.checkState = function(){
jQuery.removeData(this, 'olddisplay', true);

start();
}
};

// Chaining Tests
test("Chain fadeOut fadeIn", function() {
Expand Down

0 comments on commit 2b70893

Please sign in to comment.