| @@ 3189-3381 (lines=193) @@ | ||
| 3186 | * stopOnFalse: interrupt callings when a callback returns false |
|
| 3187 | * |
|
| 3188 | */ |
|
| 3189 | jQuery.Callbacks = function( options ) { |
|
| 3190 | ||
| 3191 | // Convert options from String-formatted to Object-formatted if needed |
|
| 3192 | // (we check in cache first) |
|
| 3193 | options = typeof options === "string" ? |
|
| 3194 | createOptions( options ) : |
|
| 3195 | jQuery.extend( {}, options ); |
|
| 3196 | ||
| 3197 | var // Flag to know if list is currently firing |
|
| 3198 | firing, |
|
| 3199 | ||
| 3200 | // Last fire value for non-forgettable lists |
|
| 3201 | memory, |
|
| 3202 | ||
| 3203 | // Flag to know if list was already fired |
|
| 3204 | fired, |
|
| 3205 | ||
| 3206 | // Flag to prevent firing |
|
| 3207 | locked, |
|
| 3208 | ||
| 3209 | // Actual callback list |
|
| 3210 | list = [], |
|
| 3211 | ||
| 3212 | // Queue of execution data for repeatable lists |
|
| 3213 | queue = [], |
|
| 3214 | ||
| 3215 | // Index of currently firing callback (modified by add/remove as needed) |
|
| 3216 | firingIndex = -1, |
|
| 3217 | ||
| 3218 | // Fire callbacks |
|
| 3219 | fire = function() { |
|
| 3220 | ||
| 3221 | // Enforce single-firing |
|
| 3222 | locked = options.once; |
|
| 3223 | ||
| 3224 | // Execute callbacks for all pending executions, |
|
| 3225 | // respecting firingIndex overrides and runtime changes |
|
| 3226 | fired = firing = true; |
|
| 3227 | for ( ; queue.length; firingIndex = -1 ) { |
|
| 3228 | memory = queue.shift(); |
|
| 3229 | while ( ++firingIndex < list.length ) { |
|
| 3230 | ||
| 3231 | // Run callback and check for early termination |
|
| 3232 | if ( list[ firingIndex ].apply( memory[ 0 ], memory[ 1 ] ) === false && |
|
| 3233 | options.stopOnFalse ) { |
|
| 3234 | ||
| 3235 | // Jump to end and forget the data so .add doesn't re-fire |
|
| 3236 | firingIndex = list.length; |
|
| 3237 | memory = false; |
|
| 3238 | } |
|
| 3239 | } |
|
| 3240 | } |
|
| 3241 | ||
| 3242 | // Forget the data if we're done with it |
|
| 3243 | if ( !options.memory ) { |
|
| 3244 | memory = false; |
|
| 3245 | } |
|
| 3246 | ||
| 3247 | firing = false; |
|
| 3248 | ||
| 3249 | // Clean up if we're done firing for good |
|
| 3250 | if ( locked ) { |
|
| 3251 | ||
| 3252 | // Keep an empty list if we have data for future add calls |
|
| 3253 | if ( memory ) { |
|
| 3254 | list = []; |
|
| 3255 | ||
| 3256 | // Otherwise, this object is spent |
|
| 3257 | } else { |
|
| 3258 | list = ""; |
|
| 3259 | } |
|
| 3260 | } |
|
| 3261 | }, |
|
| 3262 | ||
| 3263 | // Actual Callbacks object |
|
| 3264 | self = { |
|
| 3265 | ||
| 3266 | // Add a callback or a collection of callbacks to the list |
|
| 3267 | add: function() { |
|
| 3268 | if ( list ) { |
|
| 3269 | ||
| 3270 | // If we have memory from a past run, we should fire after adding |
|
| 3271 | if ( memory && !firing ) { |
|
| 3272 | firingIndex = list.length - 1; |
|
| 3273 | queue.push( memory ); |
|
| 3274 | } |
|
| 3275 | ||
| 3276 | ( function add( args ) { |
|
| 3277 | jQuery.each( args, function( _, arg ) { |
|
| 3278 | if ( jQuery.isFunction( arg ) ) { |
|
| 3279 | if ( !options.unique || !self.has( arg ) ) { |
|
| 3280 | list.push( arg ); |
|
| 3281 | } |
|
| 3282 | } else if ( arg && arg.length && jQuery.type( arg ) !== "string" ) { |
|
| 3283 | ||
| 3284 | // Inspect recursively |
|
| 3285 | add( arg ); |
|
| 3286 | } |
|
| 3287 | } ); |
|
| 3288 | } )( arguments ); |
|
| 3289 | ||
| 3290 | if ( memory && !firing ) { |
|
| 3291 | fire(); |
|
| 3292 | } |
|
| 3293 | } |
|
| 3294 | return this; |
|
| 3295 | }, |
|
| 3296 | ||
| 3297 | // Remove a callback from the list |
|
| 3298 | remove: function() { |
|
| 3299 | jQuery.each( arguments, function( _, arg ) { |
|
| 3300 | var index; |
|
| 3301 | while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { |
|
| 3302 | list.splice( index, 1 ); |
|
| 3303 | ||
| 3304 | // Handle firing indexes |
|
| 3305 | if ( index <= firingIndex ) { |
|
| 3306 | firingIndex--; |
|
| 3307 | } |
|
| 3308 | } |
|
| 3309 | } ); |
|
| 3310 | return this; |
|
| 3311 | }, |
|
| 3312 | ||
| 3313 | // Check if a given callback is in the list. |
|
| 3314 | // If no argument is given, return whether or not list has callbacks attached. |
|
| 3315 | has: function( fn ) { |
|
| 3316 | return fn ? |
|
| 3317 | jQuery.inArray( fn, list ) > -1 : |
|
| 3318 | list.length > 0; |
|
| 3319 | }, |
|
| 3320 | ||
| 3321 | // Remove all callbacks from the list |
|
| 3322 | empty: function() { |
|
| 3323 | if ( list ) { |
|
| 3324 | list = []; |
|
| 3325 | } |
|
| 3326 | return this; |
|
| 3327 | }, |
|
| 3328 | ||
| 3329 | // Disable .fire and .add |
|
| 3330 | // Abort any current/pending executions |
|
| 3331 | // Clear all callbacks and values |
|
| 3332 | disable: function() { |
|
| 3333 | locked = queue = []; |
|
| 3334 | list = memory = ""; |
|
| 3335 | return this; |
|
| 3336 | }, |
|
| 3337 | disabled: function() { |
|
| 3338 | return !list; |
|
| 3339 | }, |
|
| 3340 | ||
| 3341 | // Disable .fire |
|
| 3342 | // Also disable .add unless we have memory (since it would have no effect) |
|
| 3343 | // Abort any pending executions |
|
| 3344 | lock: function() { |
|
| 3345 | locked = true; |
|
| 3346 | if ( !memory ) { |
|
| 3347 | self.disable(); |
|
| 3348 | } |
|
| 3349 | return this; |
|
| 3350 | }, |
|
| 3351 | locked: function() { |
|
| 3352 | return !!locked; |
|
| 3353 | }, |
|
| 3354 | ||
| 3355 | // Call all callbacks with the given context and arguments |
|
| 3356 | fireWith: function( context, args ) { |
|
| 3357 | if ( !locked ) { |
|
| 3358 | args = args || []; |
|
| 3359 | args = [ context, args.slice ? args.slice() : args ]; |
|
| 3360 | queue.push( args ); |
|
| 3361 | if ( !firing ) { |
|
| 3362 | fire(); |
|
| 3363 | } |
|
| 3364 | } |
|
| 3365 | return this; |
|
| 3366 | }, |
|
| 3367 | ||
| 3368 | // Call all the callbacks with the given arguments |
|
| 3369 | fire: function() { |
|
| 3370 | self.fireWith( this, arguments ); |
|
| 3371 | return this; |
|
| 3372 | }, |
|
| 3373 | ||
| 3374 | // To know if the callbacks have already been called at least once |
|
| 3375 | fired: function() { |
|
| 3376 | return !!fired; |
|
| 3377 | } |
|
| 3378 | }; |
|
| 3379 | ||
| 3380 | return self; |
|
| 3381 | }; |
|
| 3382 | ||
| 3383 | ||
| 3384 | jQuery.extend( { |
|
| @@ 3139-3331 (lines=193) @@ | ||
| 3136 | * stopOnFalse: interrupt callings when a callback returns false |
|
| 3137 | * |
|
| 3138 | */ |
|
| 3139 | jQuery.Callbacks = function( options ) { |
|
| 3140 | ||
| 3141 | // Convert options from String-formatted to Object-formatted if needed |
|
| 3142 | // (we check in cache first) |
|
| 3143 | options = typeof options === "string" ? |
|
| 3144 | createOptions( options ) : |
|
| 3145 | jQuery.extend( {}, options ); |
|
| 3146 | ||
| 3147 | var // Flag to know if list is currently firing |
|
| 3148 | firing, |
|
| 3149 | ||
| 3150 | // Last fire value for non-forgettable lists |
|
| 3151 | memory, |
|
| 3152 | ||
| 3153 | // Flag to know if list was already fired |
|
| 3154 | fired, |
|
| 3155 | ||
| 3156 | // Flag to prevent firing |
|
| 3157 | locked, |
|
| 3158 | ||
| 3159 | // Actual callback list |
|
| 3160 | list = [], |
|
| 3161 | ||
| 3162 | // Queue of execution data for repeatable lists |
|
| 3163 | queue = [], |
|
| 3164 | ||
| 3165 | // Index of currently firing callback (modified by add/remove as needed) |
|
| 3166 | firingIndex = -1, |
|
| 3167 | ||
| 3168 | // Fire callbacks |
|
| 3169 | fire = function() { |
|
| 3170 | ||
| 3171 | // Enforce single-firing |
|
| 3172 | locked = options.once; |
|
| 3173 | ||
| 3174 | // Execute callbacks for all pending executions, |
|
| 3175 | // respecting firingIndex overrides and runtime changes |
|
| 3176 | fired = firing = true; |
|
| 3177 | for ( ; queue.length; firingIndex = -1 ) { |
|
| 3178 | memory = queue.shift(); |
|
| 3179 | while ( ++firingIndex < list.length ) { |
|
| 3180 | ||
| 3181 | // Run callback and check for early termination |
|
| 3182 | if ( list[ firingIndex ].apply( memory[ 0 ], memory[ 1 ] ) === false && |
|
| 3183 | options.stopOnFalse ) { |
|
| 3184 | ||
| 3185 | // Jump to end and forget the data so .add doesn't re-fire |
|
| 3186 | firingIndex = list.length; |
|
| 3187 | memory = false; |
|
| 3188 | } |
|
| 3189 | } |
|
| 3190 | } |
|
| 3191 | ||
| 3192 | // Forget the data if we're done with it |
|
| 3193 | if ( !options.memory ) { |
|
| 3194 | memory = false; |
|
| 3195 | } |
|
| 3196 | ||
| 3197 | firing = false; |
|
| 3198 | ||
| 3199 | // Clean up if we're done firing for good |
|
| 3200 | if ( locked ) { |
|
| 3201 | ||
| 3202 | // Keep an empty list if we have data for future add calls |
|
| 3203 | if ( memory ) { |
|
| 3204 | list = []; |
|
| 3205 | ||
| 3206 | // Otherwise, this object is spent |
|
| 3207 | } else { |
|
| 3208 | list = ""; |
|
| 3209 | } |
|
| 3210 | } |
|
| 3211 | }, |
|
| 3212 | ||
| 3213 | // Actual Callbacks object |
|
| 3214 | self = { |
|
| 3215 | ||
| 3216 | // Add a callback or a collection of callbacks to the list |
|
| 3217 | add: function() { |
|
| 3218 | if ( list ) { |
|
| 3219 | ||
| 3220 | // If we have memory from a past run, we should fire after adding |
|
| 3221 | if ( memory && !firing ) { |
|
| 3222 | firingIndex = list.length - 1; |
|
| 3223 | queue.push( memory ); |
|
| 3224 | } |
|
| 3225 | ||
| 3226 | ( function add( args ) { |
|
| 3227 | jQuery.each( args, function( _, arg ) { |
|
| 3228 | if ( jQuery.isFunction( arg ) ) { |
|
| 3229 | if ( !options.unique || !self.has( arg ) ) { |
|
| 3230 | list.push( arg ); |
|
| 3231 | } |
|
| 3232 | } else if ( arg && arg.length && jQuery.type( arg ) !== "string" ) { |
|
| 3233 | ||
| 3234 | // Inspect recursively |
|
| 3235 | add( arg ); |
|
| 3236 | } |
|
| 3237 | } ); |
|
| 3238 | } )( arguments ); |
|
| 3239 | ||
| 3240 | if ( memory && !firing ) { |
|
| 3241 | fire(); |
|
| 3242 | } |
|
| 3243 | } |
|
| 3244 | return this; |
|
| 3245 | }, |
|
| 3246 | ||
| 3247 | // Remove a callback from the list |
|
| 3248 | remove: function() { |
|
| 3249 | jQuery.each( arguments, function( _, arg ) { |
|
| 3250 | var index; |
|
| 3251 | while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { |
|
| 3252 | list.splice( index, 1 ); |
|
| 3253 | ||
| 3254 | // Handle firing indexes |
|
| 3255 | if ( index <= firingIndex ) { |
|
| 3256 | firingIndex--; |
|
| 3257 | } |
|
| 3258 | } |
|
| 3259 | } ); |
|
| 3260 | return this; |
|
| 3261 | }, |
|
| 3262 | ||
| 3263 | // Check if a given callback is in the list. |
|
| 3264 | // If no argument is given, return whether or not list has callbacks attached. |
|
| 3265 | has: function( fn ) { |
|
| 3266 | return fn ? |
|
| 3267 | jQuery.inArray( fn, list ) > -1 : |
|
| 3268 | list.length > 0; |
|
| 3269 | }, |
|
| 3270 | ||
| 3271 | // Remove all callbacks from the list |
|
| 3272 | empty: function() { |
|
| 3273 | if ( list ) { |
|
| 3274 | list = []; |
|
| 3275 | } |
|
| 3276 | return this; |
|
| 3277 | }, |
|
| 3278 | ||
| 3279 | // Disable .fire and .add |
|
| 3280 | // Abort any current/pending executions |
|
| 3281 | // Clear all callbacks and values |
|
| 3282 | disable: function() { |
|
| 3283 | locked = queue = []; |
|
| 3284 | list = memory = ""; |
|
| 3285 | return this; |
|
| 3286 | }, |
|
| 3287 | disabled: function() { |
|
| 3288 | return !list; |
|
| 3289 | }, |
|
| 3290 | ||
| 3291 | // Disable .fire |
|
| 3292 | // Also disable .add unless we have memory (since it would have no effect) |
|
| 3293 | // Abort any pending executions |
|
| 3294 | lock: function() { |
|
| 3295 | locked = queue = []; |
|
| 3296 | if ( !memory ) { |
|
| 3297 | list = memory = ""; |
|
| 3298 | } |
|
| 3299 | return this; |
|
| 3300 | }, |
|
| 3301 | locked: function() { |
|
| 3302 | return !!locked; |
|
| 3303 | }, |
|
| 3304 | ||
| 3305 | // Call all callbacks with the given context and arguments |
|
| 3306 | fireWith: function( context, args ) { |
|
| 3307 | if ( !locked ) { |
|
| 3308 | args = args || []; |
|
| 3309 | args = [ context, args.slice ? args.slice() : args ]; |
|
| 3310 | queue.push( args ); |
|
| 3311 | if ( !firing ) { |
|
| 3312 | fire(); |
|
| 3313 | } |
|
| 3314 | } |
|
| 3315 | return this; |
|
| 3316 | }, |
|
| 3317 | ||
| 3318 | // Call all the callbacks with the given arguments |
|
| 3319 | fire: function() { |
|
| 3320 | self.fireWith( this, arguments ); |
|
| 3321 | return this; |
|
| 3322 | }, |
|
| 3323 | ||
| 3324 | // To know if the callbacks have already been called at least once |
|
| 3325 | fired: function() { |
|
| 3326 | return !!fired; |
|
| 3327 | } |
|
| 3328 | }; |
|
| 3329 | ||
| 3330 | return self; |
|
| 3331 | }; |
|
| 3332 | ||
| 3333 | ||
| 3334 | jQuery.extend( { |
|
| @@ 3040-3202 (lines=163) @@ | ||
| 3037 | * stopOnFalse: interrupt callings when a callback returns false |
|
| 3038 | * |
|
| 3039 | */ |
|
| 3040 | jQuery.Callbacks = function( options ) { |
|
| 3041 | ||
| 3042 | // Convert options from String-formatted to Object-formatted if needed |
|
| 3043 | // (we check in cache first) |
|
| 3044 | options = typeof options === "string" ? |
|
| 3045 | ( optionsCache[ options ] || createOptions( options ) ) : |
|
| 3046 | jQuery.extend( {}, options ); |
|
| 3047 | ||
| 3048 | var // Last fire value (for non-forgettable lists) |
|
| 3049 | memory, |
|
| 3050 | // Flag to know if list was already fired |
|
| 3051 | fired, |
|
| 3052 | // Flag to know if list is currently firing |
|
| 3053 | firing, |
|
| 3054 | // First callback to fire (used internally by add and fireWith) |
|
| 3055 | firingStart, |
|
| 3056 | // End of the loop when firing |
|
| 3057 | firingLength, |
|
| 3058 | // Index of currently firing callback (modified by remove if needed) |
|
| 3059 | firingIndex, |
|
| 3060 | // Actual callback list |
|
| 3061 | list = [], |
|
| 3062 | // Stack of fire calls for repeatable lists |
|
| 3063 | stack = !options.once && [], |
|
| 3064 | // Fire callbacks |
|
| 3065 | fire = function( data ) { |
|
| 3066 | memory = options.memory && data; |
|
| 3067 | fired = true; |
|
| 3068 | firingIndex = firingStart || 0; |
|
| 3069 | firingStart = 0; |
|
| 3070 | firingLength = list.length; |
|
| 3071 | firing = true; |
|
| 3072 | for ( ; list && firingIndex < firingLength; firingIndex++ ) { |
|
| 3073 | if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) { |
|
| 3074 | memory = false; // To prevent further calls using add |
|
| 3075 | break; |
|
| 3076 | } |
|
| 3077 | } |
|
| 3078 | firing = false; |
|
| 3079 | if ( list ) { |
|
| 3080 | if ( stack ) { |
|
| 3081 | if ( stack.length ) { |
|
| 3082 | fire( stack.shift() ); |
|
| 3083 | } |
|
| 3084 | } else if ( memory ) { |
|
| 3085 | list = []; |
|
| 3086 | } else { |
|
| 3087 | self.disable(); |
|
| 3088 | } |
|
| 3089 | } |
|
| 3090 | }, |
|
| 3091 | // Actual Callbacks object |
|
| 3092 | self = { |
|
| 3093 | // Add a callback or a collection of callbacks to the list |
|
| 3094 | add: function() { |
|
| 3095 | if ( list ) { |
|
| 3096 | // First, we save the current length |
|
| 3097 | var start = list.length; |
|
| 3098 | (function add( args ) { |
|
| 3099 | jQuery.each( args, function( _, arg ) { |
|
| 3100 | var type = jQuery.type( arg ); |
|
| 3101 | if ( type === "function" ) { |
|
| 3102 | if ( !options.unique || !self.has( arg ) ) { |
|
| 3103 | list.push( arg ); |
|
| 3104 | } |
|
| 3105 | } else if ( arg && arg.length && type !== "string" ) { |
|
| 3106 | // Inspect recursively |
|
| 3107 | add( arg ); |
|
| 3108 | } |
|
| 3109 | }); |
|
| 3110 | })( arguments ); |
|
| 3111 | // Do we need to add the callbacks to the |
|
| 3112 | // current firing batch? |
|
| 3113 | if ( firing ) { |
|
| 3114 | firingLength = list.length; |
|
| 3115 | // With memory, if we're not firing then |
|
| 3116 | // we should call right away |
|
| 3117 | } else if ( memory ) { |
|
| 3118 | firingStart = start; |
|
| 3119 | fire( memory ); |
|
| 3120 | } |
|
| 3121 | } |
|
| 3122 | return this; |
|
| 3123 | }, |
|
| 3124 | // Remove a callback from the list |
|
| 3125 | remove: function() { |
|
| 3126 | if ( list ) { |
|
| 3127 | jQuery.each( arguments, function( _, arg ) { |
|
| 3128 | var index; |
|
| 3129 | while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { |
|
| 3130 | list.splice( index, 1 ); |
|
| 3131 | // Handle firing indexes |
|
| 3132 | if ( firing ) { |
|
| 3133 | if ( index <= firingLength ) { |
|
| 3134 | firingLength--; |
|
| 3135 | } |
|
| 3136 | if ( index <= firingIndex ) { |
|
| 3137 | firingIndex--; |
|
| 3138 | } |
|
| 3139 | } |
|
| 3140 | } |
|
| 3141 | }); |
|
| 3142 | } |
|
| 3143 | return this; |
|
| 3144 | }, |
|
| 3145 | // Check if a given callback is in the list. |
|
| 3146 | // If no argument is given, return whether or not list has callbacks attached. |
|
| 3147 | has: function( fn ) { |
|
| 3148 | return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length ); |
|
| 3149 | }, |
|
| 3150 | // Remove all callbacks from the list |
|
| 3151 | empty: function() { |
|
| 3152 | list = []; |
|
| 3153 | firingLength = 0; |
|
| 3154 | return this; |
|
| 3155 | }, |
|
| 3156 | // Have the list do nothing anymore |
|
| 3157 | disable: function() { |
|
| 3158 | list = stack = memory = undefined; |
|
| 3159 | return this; |
|
| 3160 | }, |
|
| 3161 | // Is it disabled? |
|
| 3162 | disabled: function() { |
|
| 3163 | return !list; |
|
| 3164 | }, |
|
| 3165 | // Lock the list in its current state |
|
| 3166 | lock: function() { |
|
| 3167 | stack = undefined; |
|
| 3168 | if ( !memory ) { |
|
| 3169 | self.disable(); |
|
| 3170 | } |
|
| 3171 | return this; |
|
| 3172 | }, |
|
| 3173 | // Is it locked? |
|
| 3174 | locked: function() { |
|
| 3175 | return !stack; |
|
| 3176 | }, |
|
| 3177 | // Call all callbacks with the given context and arguments |
|
| 3178 | fireWith: function( context, args ) { |
|
| 3179 | if ( list && ( !fired || stack ) ) { |
|
| 3180 | args = args || []; |
|
| 3181 | args = [ context, args.slice ? args.slice() : args ]; |
|
| 3182 | if ( firing ) { |
|
| 3183 | stack.push( args ); |
|
| 3184 | } else { |
|
| 3185 | fire( args ); |
|
| 3186 | } |
|
| 3187 | } |
|
| 3188 | return this; |
|
| 3189 | }, |
|
| 3190 | // Call all the callbacks with the given arguments |
|
| 3191 | fire: function() { |
|
| 3192 | self.fireWith( this, arguments ); |
|
| 3193 | return this; |
|
| 3194 | }, |
|
| 3195 | // To know if the callbacks have already been called at least once |
|
| 3196 | fired: function() { |
|
| 3197 | return !!fired; |
|
| 3198 | } |
|
| 3199 | }; |
|
| 3200 | ||
| 3201 | return self; |
|
| 3202 | }; |
|
| 3203 | ||
| 3204 | ||
| 3205 | jQuery.extend({ |
|