From e2be7ec8248af43b71e1a6dce6478f46c2ba2478 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Fri, 31 Aug 2012 18:38:32 +0000 Subject: [PATCH] Media JS: Attachments collection API improvements. Rename watch() and unwatch() to observe() and unobserve(), respectively, to avoid conflicts with Firefox's proprietary Object.prototype.watch method. Rename validate() to validator(), and changed() to validate(), as the latter will be more frequently used, and better explains its purpose. Also, make the new validate() more concise. see #21390. git-svn-id: http://core.svn.wordpress.org/trunk@21689 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media-models.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/wp-includes/js/media-models.js b/wp-includes/js/media-models.js index 8f10513c28..e397a80ce9 100644 --- a/wp-includes/js/media-models.js +++ b/wp-includes/js/media-models.js @@ -145,34 +145,29 @@ if ( typeof wp === 'undefined' ) this.filters = options.filters || {}; - if ( options.watch ) - this.watch( options.watch ); + if ( options.observe ) + this.observe( options.observe ); if ( options.mirror ) this.mirror( options.mirror ); }, - validate: function( attachment ) { + validator: function( attachment ) { return _.all( this.filters, function( filter ) { return !! filter.call( this, attachment ); }, this ); }, - changed: function( attachment, options ) { - - if ( this.validate( attachment ) ) - this.add( attachment ); - else - this.remove( attachment ); - return this; + validate: function( attachment, options ) { + return this[ this.validator( attachment ) ? 'add' : 'remove' ]( attachment, options ); }, - watch: function( attachments ) { - attachments.on( 'add change', this.changed, this ); + observe: function( attachments ) { + attachments.on( 'add change', this.validate, this ); }, - unwatch: function( attachments ) { - attachments.off( 'add change', this.changed, this ); + unobserve: function( attachments ) { + attachments.off( 'add change', this.validate, this ); }, mirror: function( attachments ) { @@ -318,7 +313,7 @@ if ( typeof wp === 'undefined' ) }; } - this.watch( Attachments.all ); + this.observe( Attachments.all ); }, more: function( options ) {