diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index efc051ac94..3078ed7e56 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -600,7 +600,7 @@ window.wp = window.wp || {}; attachments: function( shortcode, parent ) { var shortcodeString = shortcode.string(), result = galleries[ shortcodeString ], - attrs, args, query; + attrs, args, query, others; delete galleries[ shortcodeString ]; @@ -627,15 +627,25 @@ window.wp = window.wp || {}; if ( ! args.post__in ) args.parent = attrs.id || parent; + // Collect the attributes that were not included in `args`. + others = {}; + _.filter( attrs, function( value, key ) { + if ( _.isUndefined( args[ key ] ) ) + others[ key ] = value; + }); + query = media.query( args ); - query.props.set( _.pick( attrs, 'columns', 'link' ) ); + query.gallery = new Backbone.Model( others ); return query; }, shortcode: function( attachments ) { var props = attachments.props.toJSON(), - attrs = _.pick( props, 'include', 'exclude', 'orderby', 'order', 'link', 'columns' ), - shortcode; + attrs = _.pick( props, 'include', 'exclude', 'orderby', 'order' ), + shortcode, clone; + + if ( attachments.gallery ) + _.extend( attrs, attachments.gallery.toJSON() ); attrs.ids = attachments.pluck('id'); @@ -651,9 +661,11 @@ window.wp = window.wp || {}; }); // Use a cloned version of the gallery. - galleries[ shortcode.string() ] = new wp.media.model.Attachments( attachments.models, { + clone = new wp.media.model.Attachments( attachments.models, { props: props }); + clone.gallery = attachments.gallery; + galleries[ shortcode.string() ] = clone; return shortcode; } @@ -705,19 +717,24 @@ window.wp = window.wp || {}; }, edit: function() { + var selection; + if ( ! wp.media.view || this.frame ) return; + selection = new wp.media.model.Selection( this.attachments.models, { + props: this.attachments.props.toJSON(), + multiple: true + }); + selection.gallery = this.attachments.gallery; + this.frame = wp.media({ frame: 'post', state: 'gallery-edit', title: mceview.l10n.editGallery, editing: true, multiple: true, - selection: new wp.media.model.Selection( this.attachments.models, { - props: this.attachments.props.toJSON(), - multiple: true - }) + selection: selection }); // Create a single-use frame. If the frame is closed, diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 01d472c536..2b63c7fc98 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -1031,10 +1031,14 @@ // Sidebars onSidebarGallerySettings: function( options ) { + var library = this.state().get('library'); + + library.gallery = library.gallery || new Backbone.Model(); + this.sidebar.view().add({ gallery: new media.view.Settings.Gallery({ controller: this, - model: this.state().get('library').props, + model: library.gallery, priority: 40 }).render() }, options );