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
This commit is contained in:
parent
530328ef59
commit
c2491f31ae
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue