From 7ea4eef7f03b9da267306de0acdced2b76b2a363 Mon Sep 17 00:00:00 2001 From: koopersmith Date: Tue, 15 May 2012 22:43:49 +0000 Subject: [PATCH] Theme Customizer: Add the wp.customize.Events mixin to wp.customize.Values. Provide 'add', 'remove', and 'change' events by default. see #19910. git-svn-id: http://core.svn.wordpress.org/trunk@20799 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/customize-base.dev.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/wp-includes/js/customize-base.dev.js b/wp-includes/js/customize-base.dev.js index cf3f168d30..66934ebea6 100644 --- a/wp-includes/js/customize-base.dev.js +++ b/wp-includes/js/customize-base.dev.js @@ -283,7 +283,11 @@ if ( typeof wp === 'undefined' ) return this.value( id ); this._value[ id ] = value; - this._value[ id ].parent = this; + value.parent = this; + if ( value.extended( api.Value ) ) + value.bind( this._change ); + + this.trigger( 'add', value ); if ( this._deferreds[ id ] ) this._deferreds[ id ].resolve(); @@ -305,6 +309,16 @@ if ( typeof wp === 'undefined' ) }, remove: function( id ) { + var value; + + if ( this.has( id ) ) { + value = this.value( id ); + this.trigger( 'remove', value ); + if ( value.extended( api.Value ) ) + value.unbind( this._change ); + delete value.parent; + } + delete this._value[ id ]; delete this._deferreds[ id ]; }, @@ -352,9 +366,15 @@ if ( typeof wp === 'undefined' ) }); return dfd.promise(); + }, + + _change: function() { + this.parent.trigger( 'change', this ); } }); + $.extend( api.Values.prototype, api.Events ); + /* ===================================================================== * An observable value that syncs with an element. *