Changeset 20795
- Timestamp:
- 05/15/2012 09:28:21 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/customize-base.dev.js
r20745 r20795 121 121 122 122 /* ===================================================================== 123 * Light two-way binding. 123 * Events mixin. 124 * ===================================================================== */ 125 126 api.Events = { 127 trigger: function( id ) { 128 if ( this.topics && this.topics[ id ] ) 129 this.topics[ id ].fireWith( this, slice.call( arguments, 1 ) ); 130 }, 131 132 bind: function( id, callback ) { 133 this.topics = this.topics || {}; 134 this.topics[ id ] = this.topics[ id ] || $.Callbacks(); 135 this.topics[ id ].add.apply( this.topics[ id ], slice.call( arguments, 1 ) ); 136 }, 137 138 unbind: function( id, callback ) { 139 if ( this.topics && this.topics[ id ] ) 140 this.topics[ id ].remove.apply( this.topics[ id ], slice.call( arguments, 1 ) ); 141 } 142 }; 143 144 /* ===================================================================== 145 * Observable values that support two-way binding. 124 146 * ===================================================================== */ 125 147 … … 227 249 } 228 250 }); 251 252 /* ===================================================================== 253 * A collection of observable values. 254 * ===================================================================== */ 229 255 230 256 api.Values = api.Class.extend({ … … 345 371 }); 346 372 373 374 /* ===================================================================== 375 * An observable value that syncs with an element. 376 * 377 * Handles inputs, selects, and textareas by default. 378 * ===================================================================== */ 379 347 380 api.ensure = function( element ) { 348 381 return typeof element == 'string' ? $( element ) : element; … … 449 482 }); 450 483 451 this.topics = {};452 453 484 this.receive = $.proxy( this.receive, this ); 454 485 $( window ).on( 'message', this.receive ); … … 470 501 message = JSON.parse( event.data ); 471 502 472 if ( message && message.id && typeof message.data !== 'undefined' && this.topics[ message.id ])473 this.t opics[ message.id ].fireWith( this, [ message.data ]);503 if ( message && message.id && typeof message.data !== 'undefined' ) 504 this.trigger( message.id, message.data ); 474 505 }, 475 506 … … 484 515 message = JSON.stringify({ id: id, data: data }); 485 516 this.targetWindow().postMessage( message, this.origin() ); 486 },487 488 bind: function( id, callback ) {489 var topic = this.topics[ id ] || ( this.topics[ id ] = $.Callbacks() );490 topic.add( callback );491 },492 493 unbind: function( id, callback ) {494 if ( this.topics[ id ] )495 this.topics[ id ].remove( callback );496 517 } 497 518 }); 519 520 // Add the Events mixin to api.Messenger. 521 $.extend( api.Messenger.prototype, api.Events ); 498 522 499 523 /* =====================================================================
Note: See TracChangeset
for help on using the changeset viewer.