From 9e7a77aedaabb2f7db51ac8770adf894b30ef223 Mon Sep 17 00:00:00 2001 From: Daryl Koopersmith Date: Wed, 26 Sep 2012 21:40:02 +0000 Subject: [PATCH] Limit the featured image workflow to images only. Adds the ability to set the values used to instantiate both the Workflow's library and selection. Renames the Workflows internal `_pending` variable to prevent conflicts with a similarly named internal `Backbone.Model` variable. see #21390, #21776. git-svn-id: http://core.svn.wordpress.org/trunk@22022 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/meta-boxes.php | 7 ++++++- wp-includes/js/media-views.js | 35 ++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index 175c4497ba..98bea084b0 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -1030,7 +1030,12 @@ function post_thumbnail_meta_box( $post ) { event.preventDefault(); if ( ! workflow ) { - workflow = wp.media(); + workflow = wp.media({ + library: { + type: 'image' + } + }); + workflow.selection.on( 'add', function( model ) { var sizes = model.get('sizes'), size; diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 6da5cb366b..f920da92a0 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -16,22 +16,32 @@ */ media.controller.Workflow = Backbone.Model.extend({ defaults: { - multiple: false, - view: 'library' + multiple: false, + view: 'library', + library: {}, + selection: [] }, initialize: function() { this.createSelection(); // Initialize view storage. - this._views = {}; - this._pending = {}; + this._views = {}; + this._pendingViews = {}; // Initialize modal container view. this.modal = new media.view.Modal({ controller: this }); // Add default views. - this.add( 'library', media.view.Workspace.Library, { collection: media.query() } ); + // + // Use the `library` property to initialize the corresponding view, + // then unset the property. + this.add( 'library', media.view.Workspace.Library, { + collection: media.query( this.get('library') ) + } ); + this.unset('library'); + + // Add the gallery view. this.add( 'gallery', media.view.Workspace.Gallery, { collection: this.selection } ); }, @@ -45,7 +55,7 @@ // Triggers the `add` and `add:VIEW_ID` events. add: function( id, constructor, options ) { this.remove( id ); - this._pending[ id ] = { + this._pendingViews[ id ] = { view: constructor, options: options }; @@ -63,11 +73,11 @@ var pending; id = id || this.get('view'); - pending = this._pending[ id ]; + pending = this._pendingViews[ id ]; if ( ! this._views[ id ] && pending ) { this._views[ id ] = new pending.view( _.extend({ controller: this }, pending.options || {} ) ); - delete this._pending[ id ]; + delete this._pendingViews[ id ]; this.trigger( 'init init:' + id, this._views[ id ] ); } @@ -79,7 +89,7 @@ // Triggers the `remove` and `remove:VIEW_ID` events. remove: function( id ) { delete this._views[ id ]; - delete this._pending[ id ]; + delete this._pendingViews[ id ]; this.trigger( 'remove remove:' + id ); return this; }, @@ -96,7 +106,7 @@ view = this.view( id ); if ( ! view ) - return; + return this; view.render(); this.modal.content( view ); @@ -107,7 +117,10 @@ var controller = this; // Initialize workflow-specific models. - this.selection = new Attachments(); + // Use the `selection` property to initialize the Attachments + // collection, then unset the property. + this.selection = new Attachments( this.get('selection') ); + this.unset('selection'); _.extend( this.selection, { // Override the selection's add method.