Make WordPress Core

Changeset 29284


Ignore:
Timestamp:
07/24/2014 07:59:18 PM (12 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/media-editor.js

    r28990 r29284  
    356356                var collections = {};
    357357
    358                 return _.extend( attributes, {
     358                return _.extend( {
    359359                        coerce : wp.media.coerce,
    360360                        /**
     
    479479                                }
    480480
    481                                 // Remove default attributes from the shortcode.
    482                                 _.each( this.defaults, function( value, key ) {
    483                                         attrs[ key ] = self.coerce( attrs, key );
    484                                         if ( value === attrs[ key ] ) {
    485                                                 delete attrs[ key ];
    486                                         }
    487                                 });
     481                                attrs = this.setDefaults( attrs );
    488482
    489483                                shortcode = new wp.shortcode({
     
    574568
    575569                                return this.frame;
    576                         }
    577                 });
     570                        },
     571
     572                        setDefaults: function( attrs ) {
     573                                var self = this;
     574                                // Remove default attributes from the shortcode.
     575                                _.each( this.defaults, function( value, key ) {
     576                                        attrs[ key ] = self.coerce( attrs, key );
     577                                        if ( value === attrs[ key ] ) {
     578                                                delete attrs[ key ];
     579                                        }
     580                                });
     581
     582                                return attrs;
     583                        }
     584                }, attributes );
    578585        };
    579586
    580         wp.media.galleryDefaults = {
     587        wp.media._galleryDefaults = {
    581588                itemtag: 'dl',
    582589                icontag: 'dt',
     
    591598
    592599        if ( wp.media.view.settings.galleryDefaults ) {
    593                 _.extend( wp.media.galleryDefaults, wp.media.view.settings.galleryDefaults );
     600                wp.media.galleryDefaults = _.extend( {}, wp.media._galleryDefaults, wp.media.view.settings.galleryDefaults );
     601        } else {
     602                wp.media.galleryDefaults = wp.media._galleryDefaults;
    594603        }
    595604
     
    598607                type : 'image',
    599608                editTitle : wp.media.view.l10n.editGalleryTitle,
    600                 defaults : wp.media.galleryDefaults
     609                defaults : wp.media.galleryDefaults,
     610
     611                setDefaults: function( attrs ) {
     612                        var self = this, changed = ! _.isEqual( wp.media.galleryDefaults, wp.media._galleryDefaults );
     613                        _.each( this.defaults, function( value, key ) {
     614                                attrs[ key ] = self.coerce( attrs, key );
     615                                if ( value === attrs[ key ] && ( ! changed || value === wp.media._galleryDefaults[ key ] ) ) {
     616                                        delete attrs[ key ];
     617                                }
     618                        } );
     619                        return attrs;
     620                }
    601621        });
    602622
Note: See TracChangeset for help on using the changeset viewer.