Changeset 20797
- Timestamp:
- 05/15/2012 10:01:36 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/customize-base.dev.js
r20795 r20797 332 332 * Runs a callback once all requested values exist. 333 333 * 334 * when( ids*, callback);334 * when( ids*, [callback] ); 335 335 * 336 336 * For example: 337 337 * when( id1, id2, id3, function( value1, value2, value3 ) {} ); 338 * 339 * @returns $.Deferred.promise(); 338 340 */ 339 341 when: function() { 340 342 var self = this, 341 ids = slice.call( arguments ), 342 callback = ids.pop(); 343 ids = slice.call( arguments ), 344 dfd = $.Deferred(); 345 346 // If the last argument is a callback, bind it to .done() 347 if ( $.isFunction( ids[ ids.length - 1 ] ) ) 348 dfd.done( ids.pop() ); 343 349 344 350 $.when.apply( $, $.map( ids, function( id ) { … … 346 352 return; 347 353 348 return self._deferreds[ id ] || ( self._deferreds[ id ] = $.Deferred());354 return self._deferreds[ id ] = self._deferreds[ id ] || $.Deferred(); 349 355 })).done( function() { 350 356 var values = $.map( ids, function( id ) { … … 353 359 354 360 // If a value is missing, we've used at least one expired deferred. 355 // Call Values.when again to update our masterdeferred.361 // Call Values.when again to generate a new deferred. 356 362 if ( values.length !== ids.length ) { 357 ids.push( callback ); 358 self.when.apply( self, ids ); 363 // ids.push( callback ); 364 self.when.apply( self, ids ).done( function() { 365 dfd.resolveWith( self, values ); 366 }); 359 367 return; 360 368 } 361 369 362 callback.apply( self, values );370 dfd.resolveWith( self, values ); 363 371 }); 372 373 return dfd.promise(); 364 374 } 365 375 });
Note: See TracChangeset
for help on using the changeset viewer.