Commit 7fa0da08 authored by jaubourg's avatar jaubourg

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

parent a29d4828
......@@ -38,9 +38,9 @@ function createFlags( 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)
flags = flags ? ( flagsCache[ flags ] || createFlags( flags ) ) : {};
flags = typeof flags === "string" ? ( flagsCache[ flags ] || createFlags( flags ) ) : ( flags || {} );
var // Actual callback 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 ) {
test( "jQuery.Callbacks( \"" + flags + "\" ) - " + filterLabel, function() {
jQuery.each( { "string": strFlags, "object": objectFlags }, function( flagsTypes, flags ) {
test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function() {
expect( 20 );
......@@ -178,6 +199,7 @@ jQuery.each( tests, function( flags, resultString ) {
});
});
});
});
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment