From 68b514038293c5a8f2d601e04f174b7a4f9a8b88 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Fri, 9 Nov 2012 12:37:21 +0000 Subject: [PATCH] Media: Keep track of gallery display properties in a separate model instead of mixed in with the query parameters. This allows for arbitrary gallery arguments and a more flexible data structure. see #21390. git-svn-id: https://develop.svn.wordpress.org/trunk@22508 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/js/mce-view.js | 35 ++++++++++++++++++++++++++--------- wp-includes/js/media-views.js | 6 +++++- 2 files changed, 31 insertions(+), 10 deletions(-) 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 );