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
This commit is contained in:
Daryl Koopersmith 2012-05-15 22:43:49 +00:00
parent 1a2375b4ee
commit b010685cd2
1 changed files with 21 additions and 1 deletions

View File

@ -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.
*