From b010685cd287538463acfed740ff2faf9a12a6dd Mon Sep 17 00:00:00 2001 From: Daryl 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: https://develop.svn.wordpress.org/trunk@20799 602fd350-edb4-49c9-b593-d223f7449a82 --- 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. *