From c2491f31aea43b215c923725d502de39b5c12b08 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 24 Jul 2014 19:59:18 +0000 Subject: [PATCH] When gallery settings are overridden, the JS-generated shortcodes need to check the new defaults before deleting attributes that it suspects are the same as the original default values. `wp.media.collection` has a new method to do this: `setDefaults()`. Also flips the use of `_.extend` to allow this method to be overriden on instance creation. See #28693. git-svn-id: https://develop.svn.wordpress.org/trunk@29284 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-editor.js | 44 ++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 12 deletions(-) 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; + } }); /**