X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/wordpress.git/blobdiff_plain/61343b82c4f0da4c68e4c6373daafff4a81efdd1..874d2a2f468a0d1e69aab49b1fe2d9d79d3e1142:/wp-includes/js/media-views.js diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index a14a57b0..e334b207 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -1,9 +1,8 @@ -(function($){ - var media = wp.media, - Attachment = media.model.Attachment, - Attachments = media.model.Attachments, - Query = media.model.Query, - l10n; +/* global _wpMediaViewsL10n, confirm, getUserSetting, setUserSetting */ +( function( $, _ ) { + var l10n, + media = wp.media, + isTouchDevice = ( 'ontouchend' in document ); // Link any localized strings. l10n = media.view.l10n = typeof _wpMediaViewsL10n === 'undefined' ? {} : _wpMediaViewsL10n; @@ -34,15 +33,29 @@ }; }()); - // Makes it easier to bind events using transitions. + /** + * A shared event bus used to provide events into + * the media workflows that 3rd-party devs can use to hook + * in. + */ + media.events = _.extend( {}, Backbone.Events ); + + /** + * Makes it easier to bind events using transitions. + * + * @param {string} selector + * @param {Number} sensitivity + * @returns {Promise} + */ media.transition = function( selector, sensitivity ) { var deferred = $.Deferred(); sensitivity = sensitivity || 2000; if ( $.support.transition ) { - if ( ! (selector instanceof $) ) + if ( ! (selector instanceof $) ) { selector = $( selector ); + } // Resolve the deferred when the first element finishes animating. selector.first().one( $.support.transition.end, deferred.resolve ); @@ -66,6 +79,11 @@ /** * wp.media.controller.Region + * + * @constructor + * @augments Backbone.Model + * + * @param {Object} [options={}] */ media.controller.Region = function( options ) { _.extend( this, _.pick( options || {}, 'id', 'view', 'selector' ) ); @@ -75,61 +93,138 @@ media.controller.Region.extend = Backbone.Model.extend; _.extend( media.controller.Region.prototype, { + /** + * Activate a mode. + * + * @param {string} mode + * + * @fires this.view#{this.id}:activate:{this._mode} + * @fires this.view#{this.id}:activate + * @fires this.view#{this.id}:deactivate:{this._mode} + * @fires this.view#{this.id}:deactivate + * + * @returns {wp.media.controller.Region} Returns itself to allow chaining. + */ mode: function( mode ) { - if ( ! mode ) + if ( ! mode ) { return this._mode; - + } // Bail if we're trying to change to the current mode. - if ( mode === this._mode ) + if ( mode === this._mode ) { return this; + } + /** + * Region mode deactivation event. + * + * @event this.view#{this.id}:deactivate:{this._mode} + * @event this.view#{this.id}:deactivate + */ this.trigger('deactivate'); + this._mode = mode; this.render( mode ); + + /** + * Region mode activation event. + * + * @event this.view#{this.id}:activate:{this._mode} + * @event this.view#{this.id}:activate + */ this.trigger('activate'); return this; }, - + /** + * Render a mode. + * + * @param {string} mode + * + * @fires this.view#{this.id}:create:{this._mode} + * @fires this.view#{this.id}:create + * @fires this.view#{this.id}:render:{this._mode} + * @fires this.view#{this.id}:render + * + * @returns {wp.media.controller.Region} Returns itself to allow chaining + */ render: function( mode ) { - // If no mode is provided, just re-render the current mode. - // If the provided mode isn't active, perform a full switch. - if ( mode && mode !== this._mode ) + // If the mode isn't active, activate it. + if ( mode && mode !== this._mode ) { return this.mode( mode ); + } var set = { view: null }, view; + /** + * Create region view event. + * + * Region view creation takes place in an event callback on the frame. + * + * @event this.view#{this.id}:create:{this._mode} + * @event this.view#{this.id}:create + */ this.trigger( 'create', set ); view = set.view; + + /** + * Render region view event. + * + * Region view creation takes place in an event callback on the frame. + * + * @event this.view#{this.id}:create:{this._mode} + * @event this.view#{this.id}:create + */ this.trigger( 'render', view ); - if ( view ) + if ( view ) { this.set( view ); + } return this; }, + /** + * Get the region's view. + * + * @returns {wp.media.View} + */ get: function() { return this.view.views.first( this.selector ); }, + /** + * Set the region's view as a subview of the frame. + * + * @param {Array|Object} views + * @param {Object} [options={}] + * @returns {wp.Backbone.Subviews} Subviews is returned to allow chaining + */ set: function( views, options ) { - if ( options ) + if ( options ) { options.add = false; + } return this.view.views.set( this.selector, views, options ); }, + /** + * Trigger regional view events on the frame. + * + * @param {string} event + * @returns {undefined|wp.media.controller.Region} Returns itself to allow chaining. + */ trigger: function( event ) { - var base; - if ( ! this._mode ) + var base, args; + + if ( ! this._mode ) { return; + } - var args = _.toArray( arguments ); + args = _.toArray( arguments ); base = this.id + ':' + event; - // Trigger `region:action:mode` event. + // Trigger `{this.id}:{event}:{this._mode}` event on the frame. args[0] = base + ':' + this._mode; this.view.trigger.apply( this.view, args ); - // Trigger `region:action` event. + // Trigger `{this.id}:{event}` event on the frame. args[0] = base; this.view.trigger.apply( this.view, args ); return this; @@ -138,6 +233,13 @@ /** * wp.media.controller.StateMachine + * + * @constructor + * @augments Backbone.Model + * @mixin + * @mixes Backbone.Events + * + * @param {Array} states */ media.controller.StateMachine = function( states ) { this.states = new Backbone.Collection( states ); @@ -146,36 +248,53 @@ // Use Backbone's self-propagating `extend` inheritance method. media.controller.StateMachine.extend = Backbone.Model.extend; - // Add events to the `StateMachine`. _.extend( media.controller.StateMachine.prototype, Backbone.Events, { - - // Fetch a state. - // - // If no `id` is provided, returns the active state. - // - // Implicitly creates states. + /** + * Fetch a state. + * + * If no `id` is provided, returns the active state. + * + * Implicitly creates states. + * + * Ensure that the `states` collection exists so the `StateMachine` + * can be used as a mixin. + * + * @param {string} id + * @returns {wp.media.controller.State} Returns a State model + * from the StateMachine collection + */ state: function( id ) { - // Ensure that the `states` collection exists so the `StateMachine` - // can be used as a mixin. this.states = this.states || new Backbone.Collection(); // Default to the active state. id = id || this._state; - if ( id && ! this.states.get( id ) ) + if ( id && ! this.states.get( id ) ) { this.states.add({ id: id }); + } return this.states.get( id ); }, - // Sets the active state. + /** + * Sets the active state. + * + * Bail if we're trying to select the current state, if we haven't + * created the `states` collection, or are trying to select a state + * that does not exist. + * + * @param {string} id + * + * @fires wp.media.controller.State#deactivate + * @fires wp.media.controller.State#activate + * + * @returns {wp.media.controller.StateMachine} Returns itself to allow chaining + */ setState: function( id ) { var previous = this.state(); - // Bail if we're trying to select the current state, if we haven't - // created the `states` collection, or are trying to select a state - // that does not exist. - if ( ( previous && id === previous.id ) || ! this.states || ! this.states.get( id ) ) + if ( ( previous && id === previous.id ) || ! this.states || ! this.states.get( id ) ) { return this; + } if ( previous ) { previous.trigger('deactivate'); @@ -188,18 +307,27 @@ return this; }, - // Returns the previous active state. - // - // Call the `state()` method with no parameters to retrieve the current - // active state. + /** + * Returns the previous active state. + * + * Call the `state()` method with no parameters to retrieve the current + * active state. + * + * @returns {wp.media.controller.State} Returns a State model + * from the StateMachine collection + */ lastState: function() { - if ( this._lastState ) + if ( this._lastState ) { return this.state( this._lastState ); + } } }); - // Map methods from the `states` collection to the `StateMachine` itself. + // Map all event binding and triggering on a StateMachine to its `states` collection. _.each([ 'on', 'off', 'trigger' ], function( method ) { + /** + * @returns {wp.media.controller.StateMachine} Returns itself to allow chaining. + */ media.controller.StateMachine.prototype[ method ] = function() { // Ensure that the `states` collection exists so the `StateMachine` // can be used as a mixin. @@ -210,9 +338,16 @@ }; }); - - // wp.media.controller.State - // --------------------------- + /** + * wp.media.controller.State + * + * A state is a step in a workflow that when set will trigger the controllers + * for the regions to be updated as specified in the frame. This is the base + * class that the various states used in wp.media extend. + * + * @constructor + * @augments Backbone.Model + */ media.controller.State = Backbone.Model.extend({ constructor: function() { this.on( 'activate', this._preActivate, this ); @@ -223,23 +358,43 @@ this.on( 'reset', this.reset, this ); this.on( 'ready', this._ready, this ); this.on( 'ready', this.ready, this ); + /** + * Call parent constructor with passed arguments + */ Backbone.Model.apply( this, arguments ); this.on( 'change:menu', this._updateMenu, this ); }, - + /** + * @abstract + */ ready: function() {}, + /** + * @abstract + */ activate: function() {}, + /** + * @abstract + */ deactivate: function() {}, + /** + * @abstract + */ reset: function() {}, - + /** + * @access private + */ _ready: function() { this._updateMenu(); }, - + /** + * @access private + */ _preActivate: function() { this.active = true; }, - + /** + * @access private + */ _postActivate: function() { this.on( 'change:menu', this._menu, this ); this.on( 'change:titleMode', this._title, this ); @@ -254,8 +409,9 @@ this._content(); this._router(); }, - - + /** + * @access private + */ _deactivate: function() { this.active = false; @@ -266,57 +422,76 @@ this.off( 'change:content', this._content, this ); this.off( 'change:toolbar', this._toolbar, this ); }, - + /** + * @access private + */ _title: function() { this.frame.title.render( this.get('titleMode') || 'default' ); }, - + /** + * @access private + */ _renderTitle: function( view ) { view.$el.text( this.get('title') || '' ); }, - + /** + * @access private + */ _router: function() { var router = this.frame.router, mode = this.get('router'), view; this.frame.$el.toggleClass( 'hide-router', ! mode ); - if ( ! mode ) + if ( ! mode ) { return; + } this.frame.router.render( mode ); view = router.get(); - if ( view && view.select ) + if ( view && view.select ) { view.select( this.frame.content.mode() ); + } }, - + /** + * @access private + */ _menu: function() { var menu = this.frame.menu, mode = this.get('menu'), view; - if ( ! mode ) + this.frame.$el.toggleClass( 'hide-menu', ! mode ); + if ( ! mode ) { return; + } menu.mode( mode ); view = menu.get(); - if ( view && view.select ) + if ( view && view.select ) { view.select( this.id ); + } }, - + /** + * @access private + */ _updateMenu: function() { var previous = this.previous('menu'), menu = this.get('menu'); - if ( previous ) + if ( previous ) { this.frame.off( 'menu:render:' + previous, this._renderMenu, this ); + } - if ( menu ) + if ( menu ) { this.frame.on( 'menu:render:' + menu, this._renderMenu, this ); + } }, - + /** + * @access private + */ _renderMenu: function( view ) { var menuItem = this.get('menuItem'), title = this.get('title'), @@ -325,58 +500,122 @@ if ( ! menuItem && title ) { menuItem = { text: title }; - if ( priority ) + if ( priority ) { menuItem.priority = priority; + } } - if ( ! menuItem ) + if ( ! menuItem ) { return; + } view.set( this.id, menuItem ); } }); _.each(['toolbar','content'], function( region ) { + /** + * @access private + */ media.controller.State.prototype[ '_' + region ] = function() { var mode = this.get( region ); - if ( mode ) + if ( mode ) { this.frame[ region ].render( mode ); + } }; }); - // wp.media.controller.Library - // --------------------------- + media.selectionSync = { + syncSelection: function() { + var selection = this.get('selection'), + manager = this.frame._selection; + + if ( ! this.get('syncSelection') || ! manager || ! selection ) { + return; + } + + // If the selection supports multiple items, validate the stored + // attachments based on the new selection's conditions. Record + // the attachments that are not included; we'll maintain a + // reference to those. Other attachments are considered in flux. + if ( selection.multiple ) { + selection.reset( [], { silent: true }); + selection.validateAll( manager.attachments ); + manager.difference = _.difference( manager.attachments.models, selection.models ); + } + + // Sync the selection's single item with the master. + selection.single( manager.single ); + }, + + /** + * Record the currently active attachments, which is a combination + * of the selection's attachments and the set of selected + * attachments that this specific selection considered invalid. + * Reset the difference and record the single attachment. + */ + recordSelection: function() { + var selection = this.get('selection'), + manager = this.frame._selection; + + if ( ! this.get('syncSelection') || ! manager || ! selection ) { + return; + } + + if ( selection.multiple ) { + manager.attachments.reset( selection.toArray().concat( manager.difference ) ); + manager.difference = []; + } else { + manager.attachments.add( selection.toArray() ); + } + + manager.single = selection._single; + } + }; + + /** + * A state for choosing an attachment from the media library. + * + * @constructor + * @augments wp.media.controller.State + * @augments Backbone.Model + */ media.controller.Library = media.controller.State.extend({ defaults: { - id: 'library', - multiple: false, // false, 'add', 'reset' - describe: false, - toolbar: 'select', - sidebar: 'settings', - content: 'upload', - router: 'browse', - menu: 'default', - searchable: true, - filterable: false, - sortable: true, - title: l10n.mediaLibraryTitle, - + id: 'library', + title: l10n.mediaLibraryTitle, + // Selection defaults. @see media.model.Selection + multiple: false, + // Initial region modes. + content: 'upload', + menu: 'default', + router: 'browse', + toolbar: 'select', + // Attachments browser defaults. @see media.view.AttachmentsBrowser + searchable: true, + filterable: false, + sortable: true, + + autoSelect: true, + describe: false, // Uses a user setting to override the content mode. contentUserSetting: true, - // Sync the selection from the last state when 'multiple' matches. - syncSelection: true + syncSelection: true }, + /** + * If a library isn't provided, query all media items. + * If a selection instance isn't provided, create one. + */ initialize: function() { var selection = this.get('selection'), props; - // If a library isn't provided, query all media items. - if ( ! this.get('library') ) + if ( ! this.get('library') ) { this.set( 'library', media.query() ); + } - // If a selection instance isn't provided, create one. if ( ! (selection instanceof media.model.Selection) ) { props = selection; @@ -395,12 +634,6 @@ }) ); } - if ( ! this.get('edge') ) - this.set( 'edge', 120 ); - - if ( ! this.get('gutter') ) - this.set( 'gutter', 8 ); - this.resetDisplays(); }, @@ -411,7 +644,7 @@ this.get('selection').on( 'add remove reset', this.refreshContent, this ); - if ( this.get('contentUserSetting') ) { + if ( this.get( 'router' ) && this.get('contentUserSetting') ) { this.frame.on( 'content:activate', this.saveContentMode, this ); this.set( 'content', getUserSetting( 'libraryContent', this.get('content') ) ); } @@ -445,133 +678,166 @@ }; }, + /** + * @param {wp.media.model.Attachment} attachment + * @returns {Backbone.Model} + */ display: function( attachment ) { var displays = this._displays; - if ( ! displays[ attachment.cid ] ) + if ( ! displays[ attachment.cid ] ) { displays[ attachment.cid ] = new Backbone.Model( this.defaultDisplaySettings( attachment ) ); - + } return displays[ attachment.cid ]; }, + /** + * @param {wp.media.model.Attachment} attachment + * @returns {Object} + */ defaultDisplaySettings: function( attachment ) { - settings = this._defaultDisplaySettings; - if ( settings.canEmbed = this.canEmbed( attachment ) ) + var settings = this._defaultDisplaySettings; + if ( settings.canEmbed = this.canEmbed( attachment ) ) { settings.link = 'embed'; + } return settings; }, + /** + * @param {wp.media.model.Attachment} attachment + * @returns {Boolean} + */ canEmbed: function( attachment ) { // If uploading, we know the filename but not the mime type. if ( ! attachment.get('uploading') ) { var type = attachment.get('type'); - if ( type !== 'audio' && type !== 'video' ) + if ( type !== 'audio' && type !== 'video' ) { return false; + } } return _.contains( media.view.settings.embedExts, attachment.get('filename').split('.').pop() ); }, - syncSelection: function() { - var selection = this.get('selection'), - manager = this.frame._selection; - - if ( ! this.get('syncSelection') || ! manager || ! selection ) - return; - - // If the selection supports multiple items, validate the stored - // attachments based on the new selection's conditions. Record - // the attachments that are not included; we'll maintain a - // reference to those. Other attachments are considered in flux. - if ( selection.multiple ) { - selection.reset( [], { silent: true }); - selection.validateAll( manager.attachments ); - manager.difference = _.difference( manager.attachments.models, selection.models ); - } - - // Sync the selection's single item with the master. - selection.single( manager.single ); - }, - - recordSelection: function() { - var selection = this.get('selection'), - manager = this.frame._selection, - filtered; - - if ( ! this.get('syncSelection') || ! manager || ! selection ) - return; - - // Record the currently active attachments, which is a combination - // of the selection's attachments and the set of selected - // attachments that this specific selection considered invalid. - // Reset the difference and record the single attachment. - if ( selection.multiple ) { - manager.attachments.reset( selection.toArray().concat( manager.difference ) ); - manager.difference = []; - } else { - manager.attachments.add( selection.toArray() ); - } - - manager.single = selection._single; - }, + /** + * If the state is active, no items are selected, and the current + * content mode is not an option in the state's router (provided + * the state has a router), reset the content mode to the default. + */ refreshContent: function() { var selection = this.get('selection'), frame = this.frame, router = frame.router.get(), mode = frame.content.mode(); - // If the state is active, no items are selected, and the current - // content mode is not an option in the state's router (provided - // the state has a router), reset the content mode to the default. - if ( this.active && ! selection.length && router && ! router.get( mode ) ) + if ( this.active && ! selection.length && router && ! router.get( mode ) ) { this.frame.content.render( this.get('content') ); + } }, + /** + * If the uploader was selected, navigate to the browser. + * + * Automatically select any uploading attachments. + * + * Selections that don't support multiple attachments automatically + * limit themselves to one attachment (in this case, the last + * attachment in the upload queue). + * + * @param {wp.media.model.Attachment} attachment + */ uploading: function( attachment ) { var content = this.frame.content; - // If the uploader was selected, navigate to the browser. - if ( 'upload' === content.mode() ) + if ( 'upload' === content.mode() ) { this.frame.content.mode('browse'); + } - // Automatically select any uploading attachments. - // - // Selections that don't support multiple attachments automatically - // limit themselves to one attachment (in this case, the last - // attachment in the upload queue). - this.get('selection').add( attachment ); + if ( this.get( 'autoSelect' ) ) { + this.get('selection').add( attachment ); + this.frame.trigger( 'library:selection:add' ); + } }, + /** + * Only track the browse router on library states. + */ saveContentMode: function() { - // Only track the browse router on library states. - if ( 'browse' !== this.get('router') ) + if ( 'browse' !== this.get('router') ) { return; + } var mode = this.frame.content.mode(), view = this.frame.router.get(); - if ( view && view.get( mode ) ) + if ( view && view.get( mode ) ) { setUserSetting( 'libraryContent', mode ); + } + } + }); + + _.extend( media.controller.Library.prototype, media.selectionSync ); + + /** + * A state for editing the settings of an image within a content editor. + * + * @constructor + * @augments wp.media.controller.State + * @augments Backbone.Model + */ + media.controller.ImageDetails = media.controller.State.extend({ + defaults: _.defaults({ + id: 'image-details', + title: l10n.imageDetailsTitle, + // Initial region modes. + content: 'image-details', + menu: false, + router: false, + toolbar: 'image-details', + + editing: false, + priority: 60 + }, media.controller.Library.prototype.defaults ), + + initialize: function( options ) { + this.image = options.image; + media.controller.State.prototype.initialize.apply( this, arguments ); + }, + + activate: function() { + this.frame.modal.$el.addClass('image-details'); } }); - // wp.media.controller.GalleryEdit - // ------------------------------- + /** + * A state for editing a gallery's images and settings. + * + * @constructor + * @augments wp.media.controller.Library + * @augments wp.media.controller.State + * @augments Backbone.Model + */ media.controller.GalleryEdit = media.controller.Library.extend({ defaults: { - id: 'gallery-edit', - multiple: false, - describe: true, - edge: 199, - editing: false, - sortable: true, - searchable: false, - toolbar: 'gallery-edit', - content: 'browse', - title: l10n.editGalleryTitle, - priority: 60, - dragInfo: true, + id: 'gallery-edit', + title: l10n.editGalleryTitle, + // Selection defaults. @see media.model.Selection + multiple: false, + // Attachments browser defaults. @see media.view.AttachmentsBrowser + searchable: false, + sortable: true, + display: false, + // Initial region modes. + content: 'browse', + toolbar: 'gallery-edit', + + describe: true, + displaySettings: true, + dragInfo: true, + idealColumnWidth: 170, + editing: false, + priority: 60, // Don't sync the selection, as the Edit Gallery library // *is* the selection. @@ -613,10 +879,15 @@ }, gallerySettings: function( browser ) { + if ( ! this.get('displaySettings') ) { + return; + } + var library = this.get('library'); - if ( ! library || ! browser ) + if ( ! library || ! browser ) { return; + } library.gallery = library.gallery || new Backbone.Model(); @@ -639,18 +910,27 @@ } }); - // wp.media.controller.GalleryAdd - // --------------------------------- + /** + * A state for adding an image to a gallery. + * + * @constructor + * @augments wp.media.controller.Library + * @augments wp.media.controller.State + * @augments Backbone.Model + */ media.controller.GalleryAdd = media.controller.Library.extend({ defaults: _.defaults({ - id: 'gallery-library', - filterable: 'uploaded', - multiple: 'add', - menu: 'gallery', - toolbar: 'gallery-add', - title: l10n.addToGalleryTitle, - priority: 100, - + id: 'gallery-library', + title: l10n.addToGalleryTitle, + // Selection defaults. @see media.model.Selection + multiple: 'add', + // Attachments browser defaults. @see media.view.AttachmentsBrowser + filterable: 'uploaded', + // Initial region modes. + menu: 'gallery', + toolbar: 'gallery-add', + + priority: 100, // Don't sync the selection, as the Edit Gallery library // *is* the selection. syncSelection: false @@ -688,103 +968,460 @@ } }); - // wp.media.controller.FeaturedImage - // --------------------------------- - media.controller.FeaturedImage = media.controller.Library.extend({ - defaults: _.defaults({ - id: 'featured-image', - filterable: 'uploaded', - multiple: false, - toolbar: 'featured-image', - title: l10n.setFeaturedImageTitle, - priority: 60, - + /** + * wp.media.controller.CollectionEdit + * + * @constructor + * @augments wp.media.controller.Library + * @augments wp.media.controller.State + * @augments Backbone.Model + */ + media.controller.CollectionEdit = media.controller.Library.extend({ + defaults: { + // Selection defaults. @see media.model.Selection + multiple: false, + // Attachments browser defaults. @see media.view.AttachmentsBrowser + sortable: true, + searchable: false, + // Region mode defaults. + content: 'browse', + + describe: true, + dragInfo: true, + idealColumnWidth: 170, + editing: false, + priority: 60, + SettingsView: false, + + // Don't sync the selection, as the Edit {Collection} library + // *is* the selection. syncSelection: false - }, media.controller.Library.prototype.defaults ), + }, initialize: function() { - var library, comparator; + var collectionType = this.get('collectionType'); - // If we haven't been provided a `library`, create a `Selection`. - if ( ! this.get('library') ) - this.set( 'library', media.query({ type: 'image' }) ); + if ( 'video' === this.get( 'type' ) ) { + collectionType = 'video-' + collectionType; + } + + this.set( 'id', collectionType + '-edit' ); + this.set( 'toolbar', collectionType + '-edit' ); + // If we haven't been provided a `library`, create a `Selection`. + if ( ! this.get('library') ) { + this.set( 'library', new media.model.Selection() ); + } + // The single `Attachment` view to be used in the `Attachments` view. + if ( ! this.get('AttachmentView') ) { + this.set( 'AttachmentView', media.view.Attachment.EditLibrary ); + } media.controller.Library.prototype.initialize.apply( this, arguments ); + }, - library = this.get('library'); - comparator = library.comparator; + activate: function() { + var library = this.get('library'); - // Overload the library's comparator to push items that are not in - // the mirrored query to the front of the aggregate collection. - library.comparator = function( a, b ) { - var aInQuery = !! this.mirroring.get( a.cid ), - bInQuery = !! this.mirroring.get( b.cid ); + // Limit the library to images only. + library.props.set( 'type', this.get( 'type' ) ); - if ( ! aInQuery && bInQuery ) - return -1; - else if ( aInQuery && ! bInQuery ) - return 1; - else - return comparator.apply( this, arguments ); - }; + // Watch for uploaded attachments. + this.get('library').observe( wp.Uploader.queue ); - // Add all items in the selection to the library, so any featured - // images that are not initially loaded still appear. - library.observe( this.get('selection') ); - }, + this.frame.on( 'content:render:browse', this.renderSettings, this ); - activate: function() { - this.updateSelection(); - this.frame.on( 'open', this.updateSelection, this ); media.controller.Library.prototype.activate.apply( this, arguments ); }, deactivate: function() { - this.frame.off( 'open', this.updateSelection, this ); + // Stop watching for uploaded attachments. + this.get('library').unobserve( wp.Uploader.queue ); + + this.frame.off( 'content:render:browse', this.renderSettings, this ); + media.controller.Library.prototype.deactivate.apply( this, arguments ); }, - updateSelection: function() { - var selection = this.get('selection'), - id = media.view.settings.post.featuredImageId, - attachment; + renderSettings: function( browser ) { + var library = this.get('library'), + collectionType = this.get('collectionType'), + dragInfoText = this.get('dragInfoText'), + SettingsView = this.get('SettingsView'), + obj = {}; - if ( '' !== id && -1 !== id ) { - attachment = Attachment.get( id ); - attachment.fetch(); + if ( ! library || ! browser ) { + return; } - selection.reset( attachment ? [ attachment ] : [] ); + library[ collectionType ] = library[ collectionType ] || new Backbone.Model(); + + obj[ collectionType ] = new SettingsView({ + controller: this, + model: library[ collectionType ], + priority: 40 + }); + + browser.sidebar.set( obj ); + + if ( dragInfoText ) { + browser.toolbar.set( 'dragInfo', new media.View({ + el: $( '