Changeset 20257
- Timestamp:
- 03/22/2012 06:52:44 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/customize-base.dev.js
r20128 r20257 378 378 initialize: function( options ) { 379 379 api.Value.prototype.initialize.call( this, {}, options || {} ); 380 this._deferreds = {}; 380 381 }, 381 382 382 383 instance: function( id ) { 383 return this.value( id ); 384 if ( arguments.length === 1 ) 385 return this.value( id ); 386 387 return this.when.apply( this, arguments ); 384 388 }, 385 389 … … 398 402 this._value[ id ] = value; 399 403 this._value[ id ]._parent = this._value; 404 405 if ( this._deferreds[ id ] ) 406 this._deferreds[ id ].resolve(); 407 400 408 return this._value[ id ]; 401 409 }, … … 410 418 remove: function( id ) { 411 419 delete this._value[ id ]; 420 delete this._deferreds[ id ]; 412 421 }, 413 422 … … 423 432 value = this.value( id ); 424 433 return value[ fn ].apply( value, args ); 434 }, 435 436 /** 437 * Runs a callback once all requested values exist. 438 * 439 * when( ids*, callback ); 440 * 441 * For example: 442 * when( id1, id2, id3, function( value1, value2, value3 ) {} ); 443 */ 444 when: function() { 445 var self = this, 446 ids = slice.call( arguments ), 447 callback = ids.pop(); 448 449 $.when.apply( $, $.map( ids, function( id ) { 450 if ( self.has( id ) ) 451 return; 452 453 return self._deferreds[ id ] || ( self._deferreds[ id ] = $.Deferred() ); 454 })).done( function() { 455 var values = $.map( ids, function( id ) { 456 return self( id ); 457 }); 458 459 // If a value is missing, we've used at least one expired deferred. 460 // Call Values.when again to update our master deferred. 461 if ( values.length !== ids.length ) { 462 ids.push( callback ); 463 self.when.apply( self, ids ); 464 return; 465 } 466 467 callback.apply( self, values ); 468 }); 425 469 } 426 470 });
Note: See TracChangeset
for help on using the changeset viewer.