Adds disabled and locked. Simplifies logic in fireWith.

This commit is contained in:
jaubourg 2011-05-08 18:38:00 +02:00
parent 3a6b759d3c
commit 946a9204a1

View file

@ -83,6 +83,7 @@ jQuery.Callbacks = function( flags, filter ) {
// if it already exists // if it already exists
if ( flags.relocate ) { if ( flags.relocate ) {
object.remove( elem ); object.remove( elem );
// Skip if we're in unique mode and callback is already in
} else if ( flags.unique && object.has( elem ) ) { } else if ( flags.unique && object.has( elem ) ) {
continue; continue;
} }
@ -155,6 +156,10 @@ jQuery.Callbacks = function( flags, filter ) {
list = stack = memory = undefined; list = stack = memory = undefined;
return this; return this;
}, },
// Is it disabled?
disabled: function() {
return !list;
},
// Lock the list in its current state // Lock the list in its current state
lock: function() { lock: function() {
stack = undefined; stack = undefined;
@ -163,18 +168,24 @@ jQuery.Callbacks = function( flags, filter ) {
} }
return this; return this;
}, },
// Is it locked?
locked: function() {
return !stack;
},
// Call all callbacks with the given context and arguments // Call all callbacks with the given context and arguments
fireWith: function( context, args ) { fireWith: function( context, args ) {
var start = firingStart; if ( list ) {
firingStart = 0;
if ( list && stack && ( !flags.once || !memory && !firing ) ) {
if ( firing ) { if ( firing ) {
if ( !flags.once ) {
stack.push( [ context, args ] ); stack.push( [ context, args ] );
} else { }
} else if ( !( flags.once && memory ) ) {
args = args || []; args = args || [];
memory = !flags.memory || [ context, args ]; memory = [ context, args ];
firing = true; firing = true;
for ( firingIndex = start || 0; list && firingIndex < list.length; firingIndex++ ) { firingIndex = firingStart || 0;
firingStart = 0;
for ( ; list && firingIndex < list.length; firingIndex++ ) {
if ( list[ firingIndex ][ 1 ].apply( context, args ) === false && flags.stopOnFalse ) { if ( list[ firingIndex ][ 1 ].apply( context, args ) === false && flags.stopOnFalse ) {
break; break;
} }
@ -183,7 +194,8 @@ jQuery.Callbacks = function( flags, filter ) {
if ( list ) { if ( list ) {
if ( !flags.once ) { if ( !flags.once ) {
if ( stack && stack.length ) { if ( stack && stack.length ) {
object.fireWith.apply( this, stack.shift() ); memory = stack.shift();
object.fireWith( memory[ 0 ], memory[ 1 ] );
} }
} else if ( !flags.memory ) { } else if ( !flags.memory ) {
object.disable(); object.disable();