Allows traditional options object for $.Callbacks flags. Fixes #11011. Unit tests added.

This commit is contained in:
jaubourg 2012-04-02 01:03:34 +02:00
parent a29d482894
commit 7fa0da08b8
2 changed files with 151 additions and 129 deletions

View File

@ -38,9 +38,9 @@ function createFlags( flags ) {
*/ */
jQuery.Callbacks = function( flags ) { jQuery.Callbacks = function( flags ) {
// Convert flags from String-formatted to Object-formatted // Convert flags from String-formatted to Object-formatted if needed
// (we check in cache first) // (we check in cache first)
flags = flags ? ( flagsCache[ flags ] || createFlags( flags ) ) : {}; flags = typeof flags === "string" ? ( flagsCache[ flags ] || createFlags( flags ) ) : ( flags || {} );
var // Actual callback list var // Actual callback list
list = [], list = [],

View File

@ -33,11 +33,32 @@ var output,
} }
}; };
jQuery.each( tests, function( flags, resultString ) { function showFlags( flags ) {
if ( typeof flags === "string" ) {
return '"' + flags + '"';
}
var output = [], key;
for ( key in flags ) {
output.push( '"' + key + '": ' + flags[ key ] );
}
return "{ " + output.join( ", " ) + " }";
}
jQuery.each( tests, function( strFlags, resultString ) {
var objectFlags = {};
jQuery.each( strFlags.split( " " ), function() {
if ( this.length ) {
objectFlags[ this ] = true;
}
});
jQuery.each( filters, function( filterLabel, filter ) { jQuery.each( filters, function( filterLabel, filter ) {
test( "jQuery.Callbacks( \"" + flags + "\" ) - " + filterLabel, function() { jQuery.each( { "string": strFlags, "object": objectFlags }, function( flagsTypes, flags ) {
test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function() {
expect( 20 ); expect( 20 );
@ -178,6 +199,7 @@ jQuery.each( tests, function( flags, resultString ) {
}); });
}); });
});
}); });
})(); })();