diff --git a/src/wp-includes/js/media-editor.js b/src/wp-includes/js/media-editor.js index cc1fe41338..a51fb148c5 100644 --- a/src/wp-includes/js/media-editor.js +++ b/src/wp-includes/js/media-editor.js @@ -355,7 +355,7 @@ wp.media.collection = function(attributes) { var collections = {}; - return _.extend( attributes, { + return _.extend( { coerce : wp.media.coerce, /** * Retrieve attachments based on the properties of the passed shortcode @@ -478,13 +478,7 @@ delete attrs.orderby; } - // Remove default attributes from the shortcode. - _.each( this.defaults, function( value, key ) { - attrs[ key ] = self.coerce( attrs, key ); - if ( value === attrs[ key ] ) { - delete attrs[ key ]; - } - }); + attrs = this.setDefaults( attrs ); shortcode = new wp.shortcode({ tag: this.tag, @@ -573,11 +567,24 @@ }).open(); return this.frame; + }, + + setDefaults: function( attrs ) { + var self = this; + // Remove default attributes from the shortcode. + _.each( this.defaults, function( value, key ) { + attrs[ key ] = self.coerce( attrs, key ); + if ( value === attrs[ key ] ) { + delete attrs[ key ]; + } + }); + + return attrs; } - }); + }, attributes ); }; - wp.media.galleryDefaults = { + wp.media._galleryDefaults = { itemtag: 'dl', icontag: 'dt', captiontag: 'dd', @@ -590,14 +597,27 @@ }; if ( wp.media.view.settings.galleryDefaults ) { - _.extend( wp.media.galleryDefaults, wp.media.view.settings.galleryDefaults ); + wp.media.galleryDefaults = _.extend( {}, wp.media._galleryDefaults, wp.media.view.settings.galleryDefaults ); + } else { + wp.media.galleryDefaults = wp.media._galleryDefaults; } wp.media.gallery = new wp.media.collection({ tag: 'gallery', type : 'image', editTitle : wp.media.view.l10n.editGalleryTitle, - defaults : wp.media.galleryDefaults + defaults : wp.media.galleryDefaults, + + setDefaults: function( attrs ) { + var self = this, changed = ! _.isEqual( wp.media.galleryDefaults, wp.media._galleryDefaults ); + _.each( this.defaults, function( value, key ) { + attrs[ key ] = self.coerce( attrs, key ); + if ( value === attrs[ key ] && ( ! changed || value === wp.media._galleryDefaults[ key ] ) ) { + delete attrs[ key ]; + } + } ); + return attrs; + } }); /**