Вход Регистрация
Файл: Main Website Files/assets/bower_components/jquery/src/deferred.js
Строк: 178
<?php
define
([
    
"./core",
    
"./var/slice",
    
"./callbacks"
], function( jQueryslice ) {

jQuery.extend({

    
Deferred: function( func ) {
        var 
tuples = [
                
// action, add listener, listener list, final state
                
"resolve""done"jQuery.Callbacks("once memory"), "resolved" ],
                [ 
"reject""fail"jQuery.Callbacks("once memory"), "rejected" ],
                [ 
"notify""progress"jQuery.Callbacks("memory") ]
            ],
            
state "pending",
            
promise = {
                
state: function() {
                    return 
state;
                },
                
always: function() {
                    
deferred.donearguments ).failarguments );
                    return 
this;
                },
                
then: function( /* fnDone, fnFail, fnProgress */ ) {
                    var 
fns arguments;
                    return 
jQuery.Deferred(function( newDefer ) {
                        
jQuery.eachtuples, function( ituple ) {
                            var fn = 
jQuery.isFunctionfns] ) && fns];
                            
// deferred[ done | fail | progress ] for forwarding actions to newDefer
                            
deferredtuple[1] ](function() {
                                var 
returned = fn && fn.applythisarguments );
                                if ( 
returned && jQuery.isFunctionreturned.promise ) ) {
                                    
returned.promise()
                                        .
donenewDefer.resolve )
                                        .
failnewDefer.reject )
                                        .
progressnewDefer.notify );
                                } else {
                                    
newDefertuple] + "With" ]( this === promise newDefer.promise() : this, fn ? [ returned ] : arguments );
                                }
                            });
                        });
                        
fns null;
                    }).
promise();
                },
                
// Get a promise for this deferred
                // If obj is provided, the promise aspect is added to the object
                
promise: function( obj ) {
                    return 
obj != null jQuery.extendobjpromise ) : promise;
                }
            },
            
deferred = {};

        
// Keep pipe for back-compat
        
promise.pipe promise.then;

        
// Add list-specific methods
        
jQuery.eachtuples, function( ituple ) {
            var list = 
tuple],
                
stateString tuple];

            
// promise[ done | fail | progress ] = list.add
            
promisetuple[1] ] = list.add;

            
// Handle state
            
if ( stateString ) {
                list.
add(function() {
                    
// state = [ resolved | rejected ]
                    
state stateString;

                
// [ reject_list | resolve_list ].disable; progress_list.lock
                
}, tuples][ ].disabletuples][ ].lock );
            }

            
// deferred[ resolve | reject | notify ]
            
deferredtuple[0] ] = function() {
                
deferredtuple[0] + "With" ]( this === deferred promise thisarguments );
                return 
this;
            };
            
deferredtuple[0] + "With" ] = list.fireWith;
        });

        
// Make the deferred a promise
        
promise.promisedeferred );

        
// Call given func if any
        
if ( func ) {
            
func.calldeferreddeferred );
        }

        
// All done!
        
return deferred;
    },

    
// Deferred helper
    
when: function( subordinate /* , ..., subordinateN */ ) {
        var 
0,
            
resolveValues slice.callarguments ),
            
length resolveValues.length,

            
// the count of uncompleted subordinates
            
remaining length !== || ( subordinate && jQuery.isFunctionsubordinate.promise ) ) ? length 0,

            
// the master Deferred. If resolveValues consist of only a single Deferred, just use that.
            
deferred remaining === subordinate jQuery.Deferred(),

            
// Update function for both resolve and progress values
            
updateFunc = function( icontextsvalues ) {
                return function( 
value ) {
                    
contexts] = this;
                    
values] = arguments.length slice.callarguments ) : value;
                    if ( 
values === progressValues ) {
                        
deferred.notifyWithcontextsvalues );
                    } else if ( !( --
remaining ) ) {
                        
deferred.resolveWithcontextsvalues );
                    }
                };
            },

            
progressValuesprogressContextsresolveContexts;

        
// Add listeners to Deferred subordinates; treat others as resolved
        
if ( length ) {
            
progressValues = new Array( length );
            
progressContexts = new Array( length );
            
resolveContexts = new Array( length );
            for ( ; 
lengthi++ ) {
                if ( 
resolveValues] && jQuery.isFunctionresolveValues].promise ) ) {
                    
resolveValues].promise()
                        .
doneupdateFunciresolveContextsresolveValues ) )
                        .
faildeferred.reject )
                        .
progressupdateFunciprogressContextsprogressValues ) );
                } else {
                    --
remaining;
                }
            }
        }

        
// If we're not waiting on anything, resolve the master
        
if ( !remaining ) {
            
deferred.resolveWithresolveContextsresolveValues );
        }

        return 
deferred.promise();
    }
});

return 
jQuery;
});
?>
Онлайн: 1
Реклама