diff --git a/src/wp-includes/js/customize-base.js b/src/wp-includes/js/customize-base.js
index a1528de4f..94dc25c6e 100644
a
|
b
|
window.wp = window.wp || {}; |
203 | 203 | * Set the value and trigger all bound callbacks. |
204 | 204 | * |
205 | 205 | * @param {object} to New value. |
| 206 | * @param {object} set of optional arguments when setting the value |
206 | 207 | */ |
207 | | set: function( to ) { |
208 | | var from = this._value; |
| 208 | set: function( to, args ) { |
| 209 | var from = this._value, self = this; |
209 | 210 | |
210 | 211 | to = this._setter.apply( this, arguments ); |
211 | 212 | to = this.validate( to ); |
| 213 | args = _.extend( { silent : false }, _.isObject( args ) ? args : {} ); |
212 | 214 | |
213 | 215 | // Bail if the sanitized value is null or unchanged. |
214 | 216 | if ( null === to || _.isEqual( from, to ) ) { |
… |
… |
window.wp = window.wp || {}; |
217 | 219 | |
218 | 220 | this._value = to; |
219 | 221 | this._dirty = true; |
| 222 | if ( args.silent ) { |
| 223 | return this; |
| 224 | } |
220 | 225 | |
221 | 226 | this.callbacks.fireWith( this, [ to, from ] ); |
| 227 | if ( this.topics ) { |
| 228 | _.each( self.topics, function( _cbs ){ |
| 229 | _cbs.fireWith( self, [ to, from ] ); |
| 230 | }); |
| 231 | } |
222 | 232 | |
223 | 233 | return this; |
224 | 234 | }, |
… |
… |
window.wp = window.wp || {}; |
247 | 257 | }, |
248 | 258 | |
249 | 259 | /** |
250 | | * Bind a function to be invoked whenever the value changes. |
| 260 | * Trigger the bound callbacks of a specific topic, or trigger the anonymous callbacks |
251 | 261 | * |
| 262 | * @param {string} the topic id |
| 263 | * @param {to} the optional new value |
| 264 | * @param {from} the optional previous value |
| 265 | */ |
| 266 | trigger: function( id, to, from ) { |
| 267 | to = to || this(); |
| 268 | from = from || this(); |
| 269 | if ( this.topics && this.topics[ id ] ) { |
| 270 | this.topics[ id ].fireWith( this, [ to, from ] ); |
| 271 | } else { |
| 272 | this.callbacks.fireWith( this, [ to, from ] ); |
| 273 | } |
| 274 | return this; |
| 275 | }, |
| 276 | |
| 277 | /** |
| 278 | * Bind a function to be invoked whenever the value changes. |
| 279 | * @param {string} the optional id of the callbacks topic |
252 | 280 | * @param {...Function} A function, or multiple functions, to add to the callback stack. |
253 | 281 | */ |
254 | | bind: function() { |
255 | | this.callbacks.add.apply( this.callbacks, arguments ); |
| 282 | bind: function( id ) { |
| 283 | if ( _.isFunction( id ) ) { |
| 284 | this.callbacks.add.apply( this.callbacks, arguments ); |
| 285 | } else { |
| 286 | this.topics = this.topics || {}; |
| 287 | this.topics[ id ] = this.topics[ id ] || $.Callbacks(); |
| 288 | this.topics[ id ].add.apply( this.topics[ id ], slice.call( arguments, 1 ) ); |
| 289 | } |
256 | 290 | return this; |
257 | 291 | }, |
258 | 292 | |
259 | 293 | /** |
260 | 294 | * Unbind a previously bound function. |
261 | 295 | * |
| 296 | * @param {string} the optional id of the callbacks topic |
262 | 297 | * @param {...Function} A function, or multiple functions, to remove from the callback stack. |
263 | 298 | */ |
264 | | unbind: function() { |
265 | | this.callbacks.remove.apply( this.callbacks, arguments ); |
| 299 | unbind: function( id ) { |
| 300 | if ( _.isFunction( id ) ) { |
| 301 | this.callbacks.remove.apply( this.callbacks, arguments ); |
| 302 | } else if ( this.topics && this.topics[ id ] ) { |
| 303 | this.topics[ id ].remove.apply( this.topics[ id ], slice.call( arguments, 1 ) ); |
| 304 | } |
| 305 | return this; |
| 306 | }, |
| 307 | |
| 308 | /** |
| 309 | * Unbind all previously bound function of a callbacks topic if specified |
| 310 | * Or unbind all functions if no topic is specified |
| 311 | * |
| 312 | * @param {string} optional topic id |
| 313 | */ |
| 314 | unbindAll: function( id ) { |
| 315 | if ( this.topics && this.topics[ id ] ) { |
| 316 | this.topics[ id ] = $.Callbacks(); |
| 317 | } else if ( this.topics ) { |
| 318 | this.topics = {}; |
| 319 | } else { |
| 320 | this.callbacks = $.Callbacks(); |
| 321 | } |
266 | 322 | return this; |
267 | 323 | }, |
268 | 324 | |