+ now: function() {
+ return (new Date()).getTime();
+ },
+
+ // Create a simple deferred (one callbacks list)
+ _Deferred: function() {
+
+ var // callbacks list
+ callbacks = [],
+ // stored [ context , args ]
+ fired,
+ // to avoid firing when already doing so
+ firing,
+ // flag to know if the deferred has been cancelled
+ cancelled,
+ // the deferred itself
+ deferred = {
+
+ // done( f1, f2, ...)
+ done: function () {
+
+ if ( ! cancelled ) {
+
+ var args = arguments,
+ i,
+ length,
+ elem,
+ type,
+ _fired;
+
+ if ( fired ) {
+ _fired = fired;
+ fired = 0;
+ }
+
+ for ( i = 0, length = args.length ; i < length ; i++ ) {
+ elem = args[ i ];
+ type = jQuery.type( elem );
+ if ( type === "array" ) {
+ deferred.done.apply( deferred , elem );
+ } else if ( type === "function" ) {
+ callbacks.push( elem );
+ }
+ }
+
+ if ( _fired ) {
+ deferred.fire( _fired[ 0 ] , _fired[ 1 ] );
+ }
+ }
+
+ return this;
+ },
+
+ // resolve with given context and args
+ fire: function( context , args ) {
+ if ( ! cancelled && ! fired && ! firing ) {
+
+ firing = 1;
+
+ try {
+ while( callbacks[ 0 ] ) {
+ callbacks.shift().apply( context , args );
+ }
+ }
+ finally {
+ fired = [ context , args ];
+ firing = 0;
+ }
+ }
+ return this;
+ },
+
+ // resolve with this as context and given arguments
+ resolve: function() {
+ deferred.fire( jQuery.isFunction( this.promise ) ? this.promise() : this , arguments );
+ return this;
+ },
+
+ // Has this deferred been resolved?
+ isResolved: function() {
+ return !!( firing || fired );
+ },
+
+ // Cancel
+ cancel: function() {
+ cancelled = 1;
+ callbacks = [];
+ return this;
+ }
+ };
+
+ return deferred;
+ },
+
+ // Full fledged deferred (two callbacks list)
+ // Typical success/error system
+ Deferred: function( func ) {
+
+ var deferred = jQuery._Deferred(),
+ failDeferred = jQuery._Deferred();
+
+ // Add errorDeferred methods and redefine cancel
+ jQuery.extend( deferred , {
+
+ then: function( doneCallbacks , failCallbacks ) {
+ deferred.done( doneCallbacks ).fail( failCallbacks );
+ return this;
+ },
+ fail: failDeferred.done,
+ fireReject: failDeferred.fire,
+ reject: failDeferred.resolve,
+ isRejected: failDeferred.isResolved,
+ // Get a promise for this deferred
+ // If obj is provided, the promise aspect is added to the object
+ promise: function( obj ) {
+ obj = obj || {};
+ jQuery.each( "then done fail isResolved isRejected".split( " " ) , function( _ , method ) {
+ obj[ method ] = deferred[ method ];
+ });
+ obj.promise = function() {
+ return obj;
+ };
+ return obj;
+ }
+
+ } );
+
+ // Make sure only one callback list will be used
+ deferred.then( failDeferred.cancel , deferred.cancel );
+
+ // Unexpose cancel
+ delete deferred.cancel;
+
+ // Call given func if any
+ if ( func ) {
+ func.call( deferred , deferred );
+ }
+
+ return deferred;
+ },
+
+ // Deferred helper
+ when: function( object ) {
+ object = object && jQuery.isFunction( object.promise ) ?
+ object :
+ jQuery.Deferred().resolve( object );
+ return object.promise();
+ },
+
+ // Use of jQuery.browser is frowned upon.
+ // More details: http://docs.jquery.com/Utilities/jQuery.browser
+ uaMatch: function( ua ) {
+ ua = ua.toLowerCase();
+
+ var match = rwebkit.exec( ua ) ||
+ ropera.exec( ua ) ||
+ rmsie.exec( ua ) ||
+ ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
+ [];
+
+ return { browser: match[1] || "", version: match[2] || "0" };