mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Allows traditional options object for $.Callbacks flags. Fixes #11011. Unit tests added.
This commit is contained in:
parent
a29d482894
commit
7fa0da08b8
@ -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 = [],
|
||||||
|
@ -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 ) {
|
|||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user