Message info
 
To:wp-svn@lists.automattic.com From:m@wordpress.org Subject:[wp-svn] [20799] trunk/wp-includes/js/customize-base.dev.js: Theme Customizer: Add the wp.customize.Events mixin to wp.customize.Values. Date:Tue, 15 May 2012 22:43:50 +0000 (UTC)
 

Revision
20799
Author
koopersmith
Date
2012-05-15 22:43:49 +0000 (Tue, 15 May 2012)

Log Message

Theme Customizer: Add the wp.customize.Events mixin to wp.customize.Values. Provide 'add', 'remove', and 'change' events by default. see #19910.

Modified Paths

Diff

Modified: trunk/wp-includes/js/customize-base.dev.js (20798 => 20799)


--- trunk/wp-includes/js/customize-base.dev.js	2012-05-15 22:14:46 UTC (rev 20798)
+++ trunk/wp-includes/js/customize-base.dev.js	2012-05-15 22:43:49 UTC (rev 20799)
@@ -283,8 +283,12 @@
 				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 @@
 		},
 
 		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 @@
 			});
 
 			return dfd.promise();
+		},
+
+		_change: function() {
+			this.parent.trigger( 'change', this );
 		}
 	});
 
+	$.extend( api.Values.prototype, api.Events );
+
 	/* =====================================================================
 	 * An observable value that syncs with an element.
 	 *