From 308ae4c88705be31100c38f5e72b089140f8f3eb Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 9 Feb 2015 04:14:26 +0000 Subject: [PATCH] Make sure that `media/views.js` doesn't load Models that already exist in `media/models.js`. See #28510. Built from https://develop.svn.wordpress.org/trunk@31379 git-svn-id: http://core.svn.wordpress.org/trunk@31360 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/media/audio-video.js | 1217 +------------- wp-includes/js/media/audio-video.min.js | 6 +- .../js/media/controllers/collection-add.js | 2 +- .../js/media/controllers/collection-edit.js | 5 +- .../js/media/controllers/featured-image.js | 2 +- .../js/media/controllers/gallery-add.js | 2 +- .../js/media/controllers/gallery-edit.js | 5 +- wp-includes/js/media/controllers/library.js | 3 +- wp-includes/js/media/grid.js | 1207 +------------- wp-includes/js/media/grid.min.js | 6 +- wp-includes/js/media/views.js | 1437 +---------------- wp-includes/js/media/views.min.js | 8 +- .../js/media/views/frame/image-details.js | 6 +- .../js/media/views/frame/media-details.js | 6 +- wp-includes/js/media/views/frame/post.js | 7 +- wp-includes/js/media/views/frame/select.js | 8 +- wp-includes/version.php | 2 +- 17 files changed, 206 insertions(+), 3723 deletions(-) diff --git a/wp-includes/js/media/audio-video.js b/wp-includes/js/media/audio-video.js index 5d888e83db..7e0d06cf33 100644 --- a/wp-includes/js/media/audio-video.js +++ b/wp-includes/js/media/audio-video.js @@ -223,7 +223,7 @@ media.view.VideoDetails = require( './views/video-details.js' ); }(_)); -},{"./controllers/audio-details.js":2,"./controllers/video-details.js":8,"./models/post-media.js":11,"./views/audio-details.js":25,"./views/frame/audio-details.js":29,"./views/frame/media-details.js":30,"./views/frame/video-details.js":32,"./views/media-details.js":35,"./views/video-details.js":54}],2:[function(require,module,exports){ +},{"./controllers/audio-details.js":2,"./controllers/video-details.js":8,"./models/post-media.js":9,"./views/audio-details.js":21,"./views/frame/audio-details.js":25,"./views/frame/media-details.js":26,"./views/frame/video-details.js":28,"./views/media-details.js":31,"./views/video-details.js":50}],2:[function(require,module,exports){ /*globals wp */ /** @@ -293,7 +293,6 @@ module.exports = AudioDetails; * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state. */ var selectionSync = require( '../utils/selection-sync.js' ), - Selection = require( '../models/selection.js' ), State = require( './state.js' ), l10n = wp.media.view.l10n, Library; @@ -338,7 +337,7 @@ Library = State.extend({ props = _.omit( props, 'orderby', 'query' ); } - this.set( 'selection', new Selection( null, { + this.set( 'selection', new wp.media.model.Selection( null, { multiple: this.get('multiple'), props: props }) ); @@ -529,7 +528,7 @@ Library = State.extend({ _.extend( Library.prototype, selectionSync ); module.exports = Library; -},{"../models/selection.js":13,"../utils/selection-sync.js":14,"./state.js":7}],4:[function(require,module,exports){ +},{"../utils/selection-sync.js":10,"./state.js":7}],4:[function(require,module,exports){ /*globals _, wp */ /** @@ -1160,711 +1159,6 @@ VideoDetails = State.extend({ module.exports = VideoDetails; },{"./state.js":7}],9:[function(require,module,exports){ -/*globals jQuery, Backbone, _, wp */ - -/** - * wp.media.model.Attachment - * - * @class - * @augments Backbone.Model - */ -var $ = jQuery, - Attachment; - -Attachment = Backbone.Model.extend({ - /** - * Triggered when attachment details change - * Overrides Backbone.Model.sync - * - * @param {string} method - * @param {wp.media.model.Attachment} model - * @param {Object} [options={}] - * - * @returns {Promise} - */ - sync: function( method, model, options ) { - // If the attachment does not yet have an `id`, return an instantly - // rejected promise. Otherwise, all of our requests will fail. - if ( _.isUndefined( this.id ) ) { - return $.Deferred().rejectWith( this ).promise(); - } - - // Overload the `read` request so Attachment.fetch() functions correctly. - if ( 'read' === method ) { - options = options || {}; - options.context = this; - options.data = _.extend( options.data || {}, { - action: 'get-attachment', - id: this.id - }); - return wp.media.ajax( options ); - - // Overload the `update` request so properties can be saved. - } else if ( 'update' === method ) { - // If we do not have the necessary nonce, fail immeditately. - if ( ! this.get('nonces') || ! this.get('nonces').update ) { - return $.Deferred().rejectWith( this ).promise(); - } - - options = options || {}; - options.context = this; - - // Set the action and ID. - options.data = _.extend( options.data || {}, { - action: 'save-attachment', - id: this.id, - nonce: this.get('nonces').update, - post_id: wp.media.model.settings.post.id - }); - - // Record the values of the changed attributes. - if ( model.hasChanged() ) { - options.data.changes = {}; - - _.each( model.changed, function( value, key ) { - options.data.changes[ key ] = this.get( key ); - }, this ); - } - - return wp.media.ajax( options ); - - // Overload the `delete` request so attachments can be removed. - // This will permanently delete an attachment. - } else if ( 'delete' === method ) { - options = options || {}; - - if ( ! options.wait ) { - this.destroyed = true; - } - - options.context = this; - options.data = _.extend( options.data || {}, { - action: 'delete-post', - id: this.id, - _wpnonce: this.get('nonces')['delete'] - }); - - return wp.media.ajax( options ).done( function() { - this.destroyed = true; - }).fail( function() { - this.destroyed = false; - }); - - // Otherwise, fall back to `Backbone.sync()`. - } else { - /** - * Call `sync` directly on Backbone.Model - */ - return Backbone.Model.prototype.sync.apply( this, arguments ); - } - }, - /** - * Convert date strings into Date objects. - * - * @param {Object} resp The raw response object, typically returned by fetch() - * @returns {Object} The modified response object, which is the attributes hash - * to be set on the model. - */ - parse: function( resp ) { - if ( ! resp ) { - return resp; - } - - resp.date = new Date( resp.date ); - resp.modified = new Date( resp.modified ); - return resp; - }, - /** - * @param {Object} data The properties to be saved. - * @param {Object} options Sync options. e.g. patch, wait, success, error. - * - * @this Backbone.Model - * - * @returns {Promise} - */ - saveCompat: function( data, options ) { - var model = this; - - // If we do not have the necessary nonce, fail immeditately. - if ( ! this.get('nonces') || ! this.get('nonces').update ) { - return $.Deferred().rejectWith( this ).promise(); - } - - return media.post( 'save-attachment-compat', _.defaults({ - id: this.id, - nonce: this.get('nonces').update, - post_id: wp.media.model.settings.post.id - }, data ) ).done( function( resp, status, xhr ) { - model.set( model.parse( resp, xhr ), options ); - }); - } -}, { - /** - * Create a new model on the static 'all' attachments collection and return it. - * - * @static - * @param {Object} attrs - * @returns {wp.media.model.Attachment} - */ - create: function( attrs ) { - var Attachments = require( './attachments.js' ); - return Attachments.all.push( attrs ); - }, - /** - * Create a new model on the static 'all' attachments collection and return it. - * - * If this function has already been called for the id, - * it returns the specified attachment. - * - * @static - * @param {string} id A string used to identify a model. - * @param {Backbone.Model|undefined} attachment - * @returns {wp.media.model.Attachment} - */ - get: _.memoize( function( id, attachment ) { - var Attachments = require( './attachments.js' ); - return Attachments.all.push( attachment || { id: id } ); - }) -}); - -module.exports = Attachment; -},{"./attachments.js":10}],10:[function(require,module,exports){ -/*globals jQuery, Backbone, _, wp */ - -/** - * wp.media.model.Attachments - * - * A collection of attachments. - * - * This collection has no persistence with the server without supplying - * 'options.props.query = true', which will mirror the collection - * to an Attachments Query collection - @see wp.media.model.Attachments.mirror(). - * - * @class - * @augments Backbone.Collection - * - * @param {array} [models] Models to initialize with the collection. - * @param {object} [options] Options hash for the collection. - * @param {string} [options.props] Options hash for the initial query properties. - * @param {string} [options.props.order] Initial order (ASC or DESC) for the collection. - * @param {string} [options.props.orderby] Initial attribute key to order the collection by. - * @param {string} [options.props.query] Whether the collection is linked to an attachments query. - * @param {string} [options.observe] - * @param {string} [options.filters] - * - */ -var Attachment = require( './attachment.js' ), - Attachments; - -Attachments = Backbone.Collection.extend({ - /** - * @type {wp.media.model.Attachment} - */ - model: Attachment, - /** - * @param {Array} [models=[]] Array of models used to populate the collection. - * @param {Object} [options={}] - */ - initialize: function( models, options ) { - options = options || {}; - - this.props = new Backbone.Model(); - this.filters = options.filters || {}; - - // Bind default `change` events to the `props` model. - this.props.on( 'change', this._changeFilteredProps, this ); - - this.props.on( 'change:order', this._changeOrder, this ); - this.props.on( 'change:orderby', this._changeOrderby, this ); - this.props.on( 'change:query', this._changeQuery, this ); - - this.props.set( _.defaults( options.props || {} ) ); - - if ( options.observe ) { - this.observe( options.observe ); - } - }, - /** - * Sort the collection when the order attribute changes. - * - * @access private - */ - _changeOrder: function() { - if ( this.comparator ) { - this.sort(); - } - }, - /** - * Set the default comparator only when the `orderby` property is set. - * - * @access private - * - * @param {Backbone.Model} model - * @param {string} orderby - */ - _changeOrderby: function( model, orderby ) { - // If a different comparator is defined, bail. - if ( this.comparator && this.comparator !== Attachments.comparator ) { - return; - } - - if ( orderby && 'post__in' !== orderby ) { - this.comparator = Attachments.comparator; - } else { - delete this.comparator; - } - }, - /** - * If the `query` property is set to true, query the server using - * the `props` values, and sync the results to this collection. - * - * @access private - * - * @param {Backbone.Model} model - * @param {Boolean} query - */ - _changeQuery: function( model, query ) { - if ( query ) { - this.props.on( 'change', this._requery, this ); - this._requery(); - } else { - this.props.off( 'change', this._requery, this ); - } - }, - /** - * @access private - * - * @param {Backbone.Model} model - */ - _changeFilteredProps: function( model ) { - // If this is a query, updating the collection will be handled by - // `this._requery()`. - if ( this.props.get('query') ) { - return; - } - - var changed = _.chain( model.changed ).map( function( t, prop ) { - var filter = Attachments.filters[ prop ], - term = model.get( prop ); - - if ( ! filter ) { - return; - } - - if ( term && ! this.filters[ prop ] ) { - this.filters[ prop ] = filter; - } else if ( ! term && this.filters[ prop ] === filter ) { - delete this.filters[ prop ]; - } else { - return; - } - - // Record the change. - return true; - }, this ).any().value(); - - if ( ! changed ) { - return; - } - - // If no `Attachments` model is provided to source the searches - // from, then automatically generate a source from the existing - // models. - if ( ! this._source ) { - this._source = new Attachments( this.models ); - } - - this.reset( this._source.filter( this.validator, this ) ); - }, - - validateDestroyed: false, - /** - * Checks whether an attachment is valid. - * - * @param {wp.media.model.Attachment} attachment - * @returns {Boolean} - */ - validator: function( attachment ) { - if ( ! this.validateDestroyed && attachment.destroyed ) { - return false; - } - return _.all( this.filters, function( filter ) { - return !! filter.call( this, attachment ); - }, this ); - }, - /** - * Add or remove an attachment to the collection depending on its validity. - * - * @param {wp.media.model.Attachment} attachment - * @param {Object} options - * @returns {wp.media.model.Attachments} Returns itself to allow chaining - */ - validate: function( attachment, options ) { - var valid = this.validator( attachment ), - hasAttachment = !! this.get( attachment.cid ); - - if ( ! valid && hasAttachment ) { - this.remove( attachment, options ); - } else if ( valid && ! hasAttachment ) { - this.add( attachment, options ); - } - - return this; - }, - - /** - * Add or remove all attachments from another collection depending on each one's validity. - * - * @param {wp.media.model.Attachments} attachments - * @param {object} [options={}] - * - * @fires wp.media.model.Attachments#reset - * - * @returns {wp.media.model.Attachments} Returns itself to allow chaining - */ - validateAll: function( attachments, options ) { - options = options || {}; - - _.each( attachments.models, function( attachment ) { - this.validate( attachment, { silent: true }); - }, this ); - - if ( ! options.silent ) { - this.trigger( 'reset', this, options ); - } - return this; - }, - /** - * Start observing another attachments collection change events - * and replicate them on this collection. - * - * @param {wp.media.model.Attachments} The attachments collection to observe. - * @returns {wp.media.model.Attachments} Returns itself to allow chaining. - */ - observe: function( attachments ) { - this.observers = this.observers || []; - this.observers.push( attachments ); - - attachments.on( 'add change remove', this._validateHandler, this ); - attachments.on( 'reset', this._validateAllHandler, this ); - this.validateAll( attachments ); - return this; - }, - /** - * Stop replicating collection change events from another attachments collection. - * - * @param {wp.media.model.Attachments} The attachments collection to stop observing. - * @returns {wp.media.model.Attachments} Returns itself to allow chaining - */ - unobserve: function( attachments ) { - if ( attachments ) { - attachments.off( null, null, this ); - this.observers = _.without( this.observers, attachments ); - - } else { - _.each( this.observers, function( attachments ) { - attachments.off( null, null, this ); - }, this ); - delete this.observers; - } - - return this; - }, - /** - * @access private - * - * @param {wp.media.model.Attachments} attachment - * @param {wp.media.model.Attachments} attachments - * @param {Object} options - * - * @returns {wp.media.model.Attachments} Returns itself to allow chaining - */ - _validateHandler: function( attachment, attachments, options ) { - // If we're not mirroring this `attachments` collection, - // only retain the `silent` option. - options = attachments === this.mirroring ? options : { - silent: options && options.silent - }; - - return this.validate( attachment, options ); - }, - /** - * @access private - * - * @param {wp.media.model.Attachments} attachments - * @param {Object} options - * @returns {wp.media.model.Attachments} Returns itself to allow chaining - */ - _validateAllHandler: function( attachments, options ) { - return this.validateAll( attachments, options ); - }, - /** - * Start mirroring another attachments collection, clearing out any models already - * in the collection. - * - * @param {wp.media.model.Attachments} The attachments collection to mirror. - * @returns {wp.media.model.Attachments} Returns itself to allow chaining - */ - mirror: function( attachments ) { - if ( this.mirroring && this.mirroring === attachments ) { - return this; - } - - this.unmirror(); - this.mirroring = attachments; - - // Clear the collection silently. A `reset` event will be fired - // when `observe()` calls `validateAll()`. - this.reset( [], { silent: true } ); - this.observe( attachments ); - - return this; - }, - /** - * Stop mirroring another attachments collection. - */ - unmirror: function() { - if ( ! this.mirroring ) { - return; - } - - this.unobserve( this.mirroring ); - delete this.mirroring; - }, - /** - * Retrive more attachments from the server for the collection. - * - * Only works if the collection is mirroring a Query Attachments collection, - * and forwards to its `more` method. This collection class doesn't have - * server persistence by itself. - * - * @param {object} options - * @returns {Promise} - */ - more: function( options ) { - var deferred = jQuery.Deferred(), - mirroring = this.mirroring, - attachments = this; - - if ( ! mirroring || ! mirroring.more ) { - return deferred.resolveWith( this ).promise(); - } - // If we're mirroring another collection, forward `more` to - // the mirrored collection. Account for a race condition by - // checking if we're still mirroring that collection when - // the request resolves. - mirroring.more( options ).done( function() { - if ( this === attachments.mirroring ) - deferred.resolveWith( this ); - }); - - return deferred.promise(); - }, - /** - * Whether there are more attachments that haven't been sync'd from the server - * that match the collection's query. - * - * Only works if the collection is mirroring a Query Attachments collection, - * and forwards to its `hasMore` method. This collection class doesn't have - * server persistence by itself. - * - * @returns {boolean} - */ - hasMore: function() { - return this.mirroring ? this.mirroring.hasMore() : false; - }, - /** - * A custom AJAX-response parser. - * - * See trac ticket #24753 - * - * @param {Object|Array} resp The raw response Object/Array. - * @param {Object} xhr - * @returns {Array} The array of model attributes to be added to the collection - */ - parse: function( resp, xhr ) { - if ( ! _.isArray( resp ) ) { - resp = [resp]; - } - - return _.map( resp, function( attrs ) { - var id, attachment, newAttributes; - - if ( attrs instanceof Backbone.Model ) { - id = attrs.get( 'id' ); - attrs = attrs.attributes; - } else { - id = attrs.id; - } - - attachment = Attachment.get( id ); - newAttributes = attachment.parse( attrs, xhr ); - - if ( ! _.isEqual( attachment.attributes, newAttributes ) ) { - attachment.set( newAttributes ); - } - - return attachment; - }); - }, - /** - * If the collection is a query, create and mirror an Attachments Query collection. - * - * @access private - */ - _requery: function( refresh ) { - var props, Query; - if ( this.props.get('query') ) { - Query = require( './query.js' ); - props = this.props.toJSON(); - props.cache = ( true !== refresh ); - this.mirror( Query.get( props ) ); - } - }, - /** - * If this collection is sorted by `menuOrder`, recalculates and saves - * the menu order to the database. - * - * @returns {undefined|Promise} - */ - saveMenuOrder: function() { - if ( 'menuOrder' !== this.props.get('orderby') ) { - return; - } - - // Removes any uploading attachments, updates each attachment's - // menu order, and returns an object with an { id: menuOrder } - // mapping to pass to the request. - var attachments = this.chain().filter( function( attachment ) { - return ! _.isUndefined( attachment.id ); - }).map( function( attachment, index ) { - // Indices start at 1. - index = index + 1; - attachment.set( 'menuOrder', index ); - return [ attachment.id, index ]; - }).object().value(); - - if ( _.isEmpty( attachments ) ) { - return; - } - - return wp.media.post( 'save-attachment-order', { - nonce: wp.media.model.settings.post.nonce, - post_id: wp.media.model.settings.post.id, - attachments: attachments - }); - } -}, { - /** - * A function to compare two attachment models in an attachments collection. - * - * Used as the default comparator for instances of wp.media.model.Attachments - * and its subclasses. @see wp.media.model.Attachments._changeOrderby(). - * - * @static - * - * @param {Backbone.Model} a - * @param {Backbone.Model} b - * @param {Object} options - * @returns {Number} -1 if the first model should come before the second, - * 0 if they are of the same rank and - * 1 if the first model should come after. - */ - comparator: function( a, b, options ) { - var key = this.props.get('orderby'), - order = this.props.get('order') || 'DESC', - ac = a.cid, - bc = b.cid; - - a = a.get( key ); - b = b.get( key ); - - if ( 'date' === key || 'modified' === key ) { - a = a || new Date(); - b = b || new Date(); - } - - // If `options.ties` is set, don't enforce the `cid` tiebreaker. - if ( options && options.ties ) { - ac = bc = null; - } - - return ( 'DESC' === order ) ? wp.media.compare( a, b, ac, bc ) : wp.media.compare( b, a, bc, ac ); - }, - /** - * @namespace - */ - filters: { - /** - * @static - * Note that this client-side searching is *not* equivalent - * to our server-side searching. - * - * @param {wp.media.model.Attachment} attachment - * - * @this wp.media.model.Attachments - * - * @returns {Boolean} - */ - search: function( attachment ) { - if ( ! this.props.get('search') ) { - return true; - } - - return _.any(['title','filename','description','caption','name'], function( key ) { - var value = attachment.get( key ); - return value && -1 !== value.search( this.props.get('search') ); - }, this ); - }, - /** - * @static - * @param {wp.media.model.Attachment} attachment - * - * @this wp.media.model.Attachments - * - * @returns {Boolean} - */ - type: function( attachment ) { - var type = this.props.get('type'); - return ! type || -1 !== type.indexOf( attachment.get('type') ); - }, - /** - * @static - * @param {wp.media.model.Attachment} attachment - * - * @this wp.media.model.Attachments - * - * @returns {Boolean} - */ - uploadedTo: function( attachment ) { - var uploadedTo = this.props.get('uploadedTo'); - if ( _.isUndefined( uploadedTo ) ) { - return true; - } - - return uploadedTo === attachment.get('uploadedTo'); - }, - /** - * @static - * @param {wp.media.model.Attachment} attachment - * - * @this wp.media.model.Attachments - * - * @returns {Boolean} - */ - status: function( attachment ) { - var status = this.props.get('status'); - if ( _.isUndefined( status ) ) { - return true; - } - - return status === attachment.get('status'); - } - } -}); - -module.exports = Attachments; -},{"./attachment.js":9,"./query.js":12}],11:[function(require,module,exports){ /*globals Backbone, _, wp */ /** @@ -1907,414 +1201,7 @@ var PostMedia = Backbone.Model.extend({ }); module.exports = PostMedia; -},{}],12:[function(require,module,exports){ -/*globals jQuery, _, wp */ - -/** - * wp.media.model.Query - * - * A collection of attachments that match the supplied query arguments. - * - * Note: Do NOT change this.args after the query has been initialized. - * Things will break. - * - * @class - * @augments wp.media.model.Attachments - * @augments Backbone.Collection - * - * @param {array} [models] Models to initialize with the collection. - * @param {object} [options] Options hash. - * @param {object} [options.args] Attachments query arguments. - * @param {object} [options.args.posts_per_page] - */ -var Attachments = require( './attachments.js' ), - Query; - -Query = Attachments.extend({ - /** - * @global wp.Uploader - * - * @param {array} [models=[]] Array of initial models to populate the collection. - * @param {object} [options={}] - */ - initialize: function( models, options ) { - var allowed; - - options = options || {}; - Attachments.prototype.initialize.apply( this, arguments ); - - this.args = options.args; - this._hasMore = true; - this.created = new Date(); - - this.filters.order = function( attachment ) { - var orderby = this.props.get('orderby'), - order = this.props.get('order'); - - if ( ! this.comparator ) { - return true; - } - - // We want any items that can be placed before the last - // item in the set. If we add any items after the last - // item, then we can't guarantee the set is complete. - if ( this.length ) { - return 1 !== this.comparator( attachment, this.last(), { ties: true }); - - // Handle the case where there are no items yet and - // we're sorting for recent items. In that case, we want - // changes that occurred after we created the query. - } else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) { - return attachment.get( orderby ) >= this.created; - - // If we're sorting by menu order and we have no items, - // accept any items that have the default menu order (0). - } else if ( 'ASC' === order && 'menuOrder' === orderby ) { - return attachment.get( orderby ) === 0; - } - - // Otherwise, we don't want any items yet. - return false; - }; - - // Observe the central `wp.Uploader.queue` collection to watch for - // new matches for the query. - // - // Only observe when a limited number of query args are set. There - // are no filters for other properties, so observing will result in - // false positives in those queries. - allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent' ]; - if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) { - this.observe( wp.Uploader.queue ); - } - }, - /** - * Whether there are more attachments that haven't been sync'd from the server - * that match the collection's query. - * - * @returns {boolean} - */ - hasMore: function() { - return this._hasMore; - }, - /** - * Fetch more attachments from the server for the collection. - * - * @param {object} [options={}] - * @returns {Promise} - */ - more: function( options ) { - var query = this; - - // If there is already a request pending, return early with the Deferred object. - if ( this._more && 'pending' === this._more.state() ) { - return this._more; - } - - if ( ! this.hasMore() ) { - return jQuery.Deferred().resolveWith( this ).promise(); - } - - options = options || {}; - options.remove = false; - - return this._more = this.fetch( options ).done( function( resp ) { - if ( _.isEmpty( resp ) || -1 === this.args.posts_per_page || resp.length < this.args.posts_per_page ) { - query._hasMore = false; - } - }); - }, - /** - * Overrides Backbone.Collection.sync - * Overrides wp.media.model.Attachments.sync - * - * @param {String} method - * @param {Backbone.Model} model - * @param {Object} [options={}] - * @returns {Promise} - */ - sync: function( method, model, options ) { - var args, fallback; - - // Overload the read method so Attachment.fetch() functions correctly. - if ( 'read' === method ) { - options = options || {}; - options.context = this; - options.data = _.extend( options.data || {}, { - action: 'query-attachments', - post_id: wp.media.model.settings.post.id - }); - - // Clone the args so manipulation is non-destructive. - args = _.clone( this.args ); - - // Determine which page to query. - if ( -1 !== args.posts_per_page ) { - args.paged = Math.floor( this.length / args.posts_per_page ) + 1; - } - - options.data.query = args; - return wp.media.ajax( options ); - - // Otherwise, fall back to Backbone.sync() - } else { - /** - * Call wp.media.model.Attachments.sync or Backbone.sync - */ - fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone; - return fallback.sync.apply( this, arguments ); - } - } -}, { - /** - * @readonly - */ - defaultProps: { - orderby: 'date', - order: 'DESC' - }, - /** - * @readonly - */ - defaultArgs: { - posts_per_page: 40 - }, - /** - * @readonly - */ - orderby: { - allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ], - /** - * A map of JavaScript orderby values to their WP_Query equivalents. - * @type {Object} - */ - valuemap: { - 'id': 'ID', - 'uploadedTo': 'parent', - 'menuOrder': 'menu_order ID' - } - }, - /** - * A map of JavaScript query properties to their WP_Query equivalents. - * - * @readonly - */ - propmap: { - 'search': 's', - 'type': 'post_mime_type', - 'perPage': 'posts_per_page', - 'menuOrder': 'menu_order', - 'uploadedTo': 'post_parent', - 'status': 'post_status', - 'include': 'post__in', - 'exclude': 'post__not_in' - }, - /** - * Creates and returns an Attachments Query collection given the properties. - * - * Caches query objects and reuses where possible. - * - * @static - * @method - * - * @param {object} [props] - * @param {Object} [props.cache=true] Whether to use the query cache or not. - * @param {Object} [props.order] - * @param {Object} [props.orderby] - * @param {Object} [props.include] - * @param {Object} [props.exclude] - * @param {Object} [props.s] - * @param {Object} [props.post_mime_type] - * @param {Object} [props.posts_per_page] - * @param {Object} [props.menu_order] - * @param {Object} [props.post_parent] - * @param {Object} [props.post_status] - * @param {Object} [options] - * - * @returns {wp.media.model.Query} A new Attachments Query collection. - */ - get: (function(){ - /** - * @static - * @type Array - */ - var queries = []; - - /** - * @returns {Query} - */ - return function( props, options ) { - var args = {}, - orderby = Query.orderby, - defaults = Query.defaultProps, - query, - cache = !! props.cache || _.isUndefined( props.cache ); - - // Remove the `query` property. This isn't linked to a query, - // this *is* the query. - delete props.query; - delete props.cache; - - // Fill default args. - _.defaults( props, defaults ); - - // Normalize the order. - props.order = props.order.toUpperCase(); - if ( 'DESC' !== props.order && 'ASC' !== props.order ) { - props.order = defaults.order.toUpperCase(); - } - - // Ensure we have a valid orderby value. - if ( ! _.contains( orderby.allowed, props.orderby ) ) { - props.orderby = defaults.orderby; - } - - _.each( [ 'include', 'exclude' ], function( prop ) { - if ( props[ prop ] && ! _.isArray( props[ prop ] ) ) { - props[ prop ] = [ props[ prop ] ]; - } - } ); - - // Generate the query `args` object. - // Correct any differing property names. - _.each( props, function( value, prop ) { - if ( _.isNull( value ) ) { - return; - } - - args[ Query.propmap[ prop ] || prop ] = value; - }); - - // Fill any other default query args. - _.defaults( args, Query.defaultArgs ); - - // `props.orderby` does not always map directly to `args.orderby`. - // Substitute exceptions specified in orderby.keymap. - args.orderby = orderby.valuemap[ props.orderby ] || props.orderby; - - // Search the query cache for a matching query. - if ( cache ) { - query = _.find( queries, function( query ) { - return _.isEqual( query.args, args ); - }); - } else { - queries = []; - } - - // Otherwise, create a new query and add it to the cache. - if ( ! query ) { - query = new Query( [], _.extend( options || {}, { - props: props, - args: args - } ) ); - queries.push( query ); - } - - return query; - }; - }()) -}); - -module.exports = Query; -},{"./attachments.js":10}],13:[function(require,module,exports){ -/*globals _ */ - -/** - * wp.media.model.Selection - * - * A selection of attachments. - * - * @class - * @augments wp.media.model.Attachments - * @augments Backbone.Collection - */ -var Attachments = require( './attachments.js' ), - Selection; - -Selection = Attachments.extend({ - /** - * Refresh the `single` model whenever the selection changes. - * Binds `single` instead of using the context argument to ensure - * it receives no parameters. - * - * @param {Array} [models=[]] Array of models used to populate the collection. - * @param {Object} [options={}] - */ - initialize: function( models, options ) { - /** - * call 'initialize' directly on the parent class - */ - Attachments.prototype.initialize.apply( this, arguments ); - this.multiple = options && options.multiple; - - this.on( 'add remove reset', _.bind( this.single, this, false ) ); - }, - - /** - * If the workflow does not support multi-select, clear out the selection - * before adding a new attachment to it. - * - * @param {Array} models - * @param {Object} options - * @returns {wp.media.model.Attachment[]} - */ - add: function( models, options ) { - if ( ! this.multiple ) { - this.remove( this.models ); - } - /** - * call 'add' directly on the parent class - */ - return Attachments.prototype.add.call( this, models, options ); - }, - - /** - * Fired when toggling (clicking on) an attachment in the modal. - * - * @param {undefined|boolean|wp.media.model.Attachment} model - * - * @fires wp.media.model.Selection#selection:single - * @fires wp.media.model.Selection#selection:unsingle - * - * @returns {Backbone.Model} - */ - single: function( model ) { - var previous = this._single; - - // If a `model` is provided, use it as the single model. - if ( model ) { - this._single = model; - } - // If the single model isn't in the selection, remove it. - if ( this._single && ! this.get( this._single.cid ) ) { - delete this._single; - } - - this._single = this._single || this.last(); - - // If single has changed, fire an event. - if ( this._single !== previous ) { - if ( previous ) { - previous.trigger( 'selection:unsingle', previous, this ); - - // If the model was already removed, trigger the collection - // event manually. - if ( ! this.get( previous.cid ) ) { - this.trigger( 'selection:unsingle', previous, this ); - } - } - if ( this._single ) { - this._single.trigger( 'selection:single', this._single, this ); - } - } - - // Return the single model, or the last model as a fallback. - return this._single; - } -}); - -module.exports = Selection; -},{"./attachments.js":10}],14:[function(require,module,exports){ +},{}],10:[function(require,module,exports){ /*globals _ */ /** @@ -2381,7 +1268,7 @@ var selectionSync = { }; module.exports = selectionSync; -},{}],15:[function(require,module,exports){ +},{}],11:[function(require,module,exports){ /*globals _ */ /** @@ -2467,7 +1354,7 @@ AttachmentCompat = View.extend({ }); module.exports = AttachmentCompat; -},{"./view.js":55}],16:[function(require,module,exports){ +},{"./view.js":51}],12:[function(require,module,exports){ /*globals _, jQuery */ /** @@ -2546,7 +1433,7 @@ AttachmentFilters = View.extend({ }); module.exports = AttachmentFilters; -},{"./view.js":55}],17:[function(require,module,exports){ +},{"./view.js":51}],13:[function(require,module,exports){ /*globals _, wp */ /** @@ -2638,7 +1525,7 @@ All = AttachmentFilters.extend({ }); module.exports = All; -},{"../attachment-filters.js":16}],18:[function(require,module,exports){ +},{"../attachment-filters.js":12}],14:[function(require,module,exports){ /*globals _, wp */ /** @@ -2681,7 +1568,7 @@ DateFilter = AttachmentFilters.extend({ }); module.exports = DateFilter; -},{"../attachment-filters.js":16}],19:[function(require,module,exports){ +},{"../attachment-filters.js":12}],15:[function(require,module,exports){ /*globals wp */ /** @@ -2742,7 +1629,7 @@ Uploaded = AttachmentFilters.extend({ }); module.exports = Uploaded; -},{"../attachment-filters.js":16}],20:[function(require,module,exports){ +},{"../attachment-filters.js":12}],16:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -3297,7 +2184,7 @@ _.each({ }); module.exports = Attachment; -},{"./view.js":55}],21:[function(require,module,exports){ +},{"./view.js":51}],17:[function(require,module,exports){ /*globals _, wp */ /** @@ -3438,7 +2325,7 @@ Details = Attachment.extend({ }); module.exports = Details; -},{"../attachment.js":20}],22:[function(require,module,exports){ +},{"../attachment.js":16}],18:[function(require,module,exports){ /** * wp.media.view.Attachment.Library * @@ -3458,7 +2345,7 @@ Library = Attachment.extend({ }); module.exports = Library; -},{"../attachment.js":20}],23:[function(require,module,exports){ +},{"../attachment.js":16}],19:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -3759,7 +2646,7 @@ Attachments = View.extend({ }); module.exports = Attachments; -},{"./attachment.js":20,"./view.js":55}],24:[function(require,module,exports){ +},{"./attachment.js":16,"./view.js":51}],20:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -4219,7 +3106,7 @@ AttachmentsBrowser = View.extend({ }); module.exports = AttachmentsBrowser; -},{"../attachment-compat.js":15,"../attachment-filters/all.js":17,"../attachment-filters/date.js":18,"../attachment-filters/uploaded.js":19,"../attachment/details.js":21,"../attachment/library.js":22,"../attachments.js":23,"../label.js":34,"../search.js":43,"../settings/attachment-display.js":45,"../sidebar.js":46,"../spinner.js":47,"../toolbar.js":48,"../uploader/inline.js":50,"../uploader/status.js":52,"../view.js":55}],25:[function(require,module,exports){ +},{"../attachment-compat.js":11,"../attachment-filters/all.js":13,"../attachment-filters/date.js":14,"../attachment-filters/uploaded.js":15,"../attachment/details.js":17,"../attachment/library.js":18,"../attachments.js":19,"../label.js":30,"../search.js":39,"../settings/attachment-display.js":41,"../sidebar.js":42,"../spinner.js":43,"../toolbar.js":44,"../uploader/inline.js":46,"../uploader/status.js":48,"../view.js":51}],21:[function(require,module,exports){ /*globals wp */ /** @@ -4258,7 +3145,7 @@ AudioDetails = MediaDetails.extend({ }); module.exports = AudioDetails; -},{"./media-details":35}],26:[function(require,module,exports){ +},{"./media-details":31}],22:[function(require,module,exports){ /*globals _, Backbone */ /** @@ -4348,7 +3235,7 @@ Button = View.extend({ }); module.exports = Button; -},{"./view.js":55}],27:[function(require,module,exports){ +},{"./view.js":51}],23:[function(require,module,exports){ /** * wp.media.view.FocusManager * @@ -4396,7 +3283,7 @@ FocusManager = View.extend({ }); module.exports = FocusManager; -},{"./view.js":55}],28:[function(require,module,exports){ +},{"./view.js":51}],24:[function(require,module,exports){ /*globals _, Backbone */ /** @@ -4569,7 +3456,7 @@ Frame = View.extend({ _.extend( Frame.prototype, StateMachine.prototype ); module.exports = Frame; -},{"../controllers/region.js":5,"../controllers/state-machine.js":6,"../controllers/state.js":7,"./view.js":55}],29:[function(require,module,exports){ +},{"../controllers/region.js":5,"../controllers/state-machine.js":6,"../controllers/state.js":7,"./view.js":51}],25:[function(require,module,exports){ /*globals wp */ /** @@ -4647,7 +3534,7 @@ AudioDetails = MediaDetails.extend({ }); module.exports = AudioDetails; -},{"../../controllers/audio-details.js":2,"../../controllers/media-library.js":4,"../audio-details.js":25,"./media-details":30}],30:[function(require,module,exports){ +},{"../../controllers/audio-details.js":2,"../../controllers/media-library.js":4,"../audio-details.js":21,"./media-details":26}],26:[function(require,module,exports){ /*globals wp */ /** @@ -4665,8 +3552,6 @@ module.exports = AudioDetails; var View = require( '../view.js' ), Toolbar = require( '../toolbar.js' ), Select = require( './select.js' ), - Selection = require( '../../models/selection.js' ), - PostMedia = require( '../../models/post-media.js' ), l10n = wp.media.view.l10n, MediaDetails; @@ -4686,8 +3571,8 @@ MediaDetails = Select.extend({ this.cancelText = options.cancelText; this.addText = options.addText; - this.media = new PostMedia( options.metadata ); - this.options.selection = new Selection( this.media.attachment, { multiple: false } ); + this.media = new wp.media.model.PostMedia( options.metadata ); + this.options.selection = new wp.media.model.Selection( this.media.attachment, { multiple: false } ); Select.prototype.initialize.apply( this, arguments ); }, @@ -4782,7 +3667,7 @@ MediaDetails = Select.extend({ }); module.exports = MediaDetails; -},{"../../models/post-media.js":11,"../../models/selection.js":13,"../toolbar.js":48,"../view.js":55,"./select.js":31}],31:[function(require,module,exports){ +},{"../toolbar.js":44,"../view.js":51,"./select.js":27}],27:[function(require,module,exports){ /*globals _, wp */ /** @@ -4801,8 +3686,6 @@ module.exports = MediaDetails; var MediaFrame = require( '../media-frame.js' ), Library = require( '../../controllers/library.js' ), - AttachmentsModel = require( '../../models/attachments.js' ), - SelectionModel = require( '../../models/selection.js' ), AttachmentsBrowser = require( '../attachments/browser.js' ), UploaderInline = require( '../uploader/inline.js' ), ToolbarSelect = require( '../toolbar/select.js' ), @@ -4838,14 +3721,14 @@ Select = MediaFrame.extend({ createSelection: function() { var selection = this.options.selection; - if ( ! (selection instanceof SelectionModel) ) { - this.options.selection = new SelectionModel( selection, { + if ( ! (selection instanceof wp.media.model.Selection) ) { + this.options.selection = new wp.media.model.Selection( selection, { multiple: this.options.multiple }); } this._selection = { - attachments: new AttachmentsModel(), + attachments: new wp.media.model.Attachments(), difference: [] }; }, @@ -4959,7 +3842,7 @@ Select = MediaFrame.extend({ }); module.exports = Select; -},{"../../controllers/library.js":3,"../../models/attachments.js":10,"../../models/selection.js":13,"../attachments/browser.js":24,"../media-frame.js":36,"../toolbar/select.js":49,"../uploader/inline.js":50}],32:[function(require,module,exports){ +},{"../../controllers/library.js":3,"../attachments/browser.js":20,"../media-frame.js":32,"../toolbar/select.js":45,"../uploader/inline.js":46}],28:[function(require,module,exports){ /*globals _, wp */ /** @@ -5097,7 +3980,7 @@ VideoDetails = MediaDetails.extend({ }); module.exports = VideoDetails; -},{"../../controllers/media-library.js":4,"../../controllers/video-details.js":8,"../video-details.js":54,"./media-details":30}],33:[function(require,module,exports){ +},{"../../controllers/media-library.js":4,"../../controllers/video-details.js":8,"../video-details.js":50,"./media-details":26}],29:[function(require,module,exports){ /** * wp.media.view.Iframe * @@ -5123,7 +4006,7 @@ Iframe = View.extend({ }); module.exports = Iframe; -},{"./view.js":55}],34:[function(require,module,exports){ +},{"./view.js":51}],30:[function(require,module,exports){ /** * @class * @augments wp.media.View @@ -5149,7 +4032,7 @@ Label = View.extend({ }); module.exports = Label; -},{"./view.js":55}],35:[function(require,module,exports){ +},{"./view.js":51}],31:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -5301,7 +4184,7 @@ MediaDetails = AttachmentDisplay.extend({ }); module.exports = MediaDetails; -},{"./settings/attachment-display.js":45}],36:[function(require,module,exports){ +},{"./settings/attachment-display.js":41}],32:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -5556,7 +4439,7 @@ _.each(['open','close','attach','detach','escape'], function( method ) { }); module.exports = MediaFrame; -},{"./frame.js":28,"./iframe.js":33,"./menu.js":38,"./modal.js":39,"./router.js":42,"./toolbar.js":48,"./uploader/window.js":53,"./view.js":55}],37:[function(require,module,exports){ +},{"./frame.js":24,"./iframe.js":29,"./menu.js":34,"./modal.js":35,"./router.js":38,"./toolbar.js":44,"./uploader/window.js":49,"./view.js":51}],33:[function(require,module,exports){ /*globals wp, jQuery */ /** @@ -5630,7 +4513,7 @@ MenuItem = View.extend({ }); module.exports = MenuItem; -},{"./view.js":55}],38:[function(require,module,exports){ +},{"./view.js":51}],34:[function(require,module,exports){ /** * wp.media.view.Menu * @@ -5746,7 +4629,7 @@ Menu = PriorityList.extend({ }); module.exports = Menu; -},{"./menu-item.js":37,"./priority-list.js":40}],39:[function(require,module,exports){ +},{"./menu-item.js":33,"./priority-list.js":36}],35:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -5962,7 +4845,7 @@ Modal = View.extend({ }); module.exports = Modal; -},{"./focus-manager.js":27,"./view.js":55}],40:[function(require,module,exports){ +},{"./focus-manager.js":23,"./view.js":51}],36:[function(require,module,exports){ /*globals _, Backbone */ /** @@ -6063,7 +4946,7 @@ PriorityList = View.extend({ }); module.exports = PriorityList; -},{"./view.js":55}],41:[function(require,module,exports){ +},{"./view.js":51}],37:[function(require,module,exports){ /** * wp.media.view.RouterItem * @@ -6089,7 +4972,7 @@ RouterItem = MenuItem.extend({ }); module.exports = RouterItem; -},{"./menu-item.js":37}],42:[function(require,module,exports){ +},{"./menu-item.js":33}],38:[function(require,module,exports){ /** * wp.media.view.Router * @@ -6126,7 +5009,7 @@ Router = Menu.extend({ }); module.exports = Router; -},{"./menu.js":38,"./router-item.js":41}],43:[function(require,module,exports){ +},{"./menu.js":34,"./router-item.js":37}],39:[function(require,module,exports){ /*globals wp */ /** @@ -6176,7 +5059,7 @@ Search = View.extend({ }); module.exports = Search; -},{"./view.js":55}],44:[function(require,module,exports){ +},{"./view.js":51}],40:[function(require,module,exports){ /*globals _, Backbone, jQuery */ /** @@ -6298,7 +5181,7 @@ Settings = View.extend({ }); module.exports = Settings; -},{"./view.js":55}],45:[function(require,module,exports){ +},{"./view.js":51}],41:[function(require,module,exports){ /*globals _, wp */ /** @@ -6393,7 +5276,7 @@ AttachmentDisplay = Settings.extend({ }); module.exports = AttachmentDisplay; -},{"../settings.js":44}],46:[function(require,module,exports){ +},{"../settings.js":40}],42:[function(require,module,exports){ /** * wp.media.view.Sidebar * @@ -6411,7 +5294,7 @@ Sidebar = PriorityList.extend({ }); module.exports = Sidebar; -},{"./priority-list.js":40}],47:[function(require,module,exports){ +},{"./priority-list.js":36}],43:[function(require,module,exports){ /*globals _, wp */ /** @@ -6450,7 +5333,7 @@ Spinner = View.extend({ }); module.exports = Spinner; -},{"./view.js":55}],48:[function(require,module,exports){ +},{"./view.js":51}],44:[function(require,module,exports){ /*globals Backbone, _ */ /** @@ -6613,7 +5496,7 @@ Toolbar = View.extend({ }); module.exports = Toolbar; -},{"./button.js":26,"./priority-list.js":40,"./view.js":55}],49:[function(require,module,exports){ +},{"./button.js":22,"./priority-list.js":36,"./view.js":51}],45:[function(require,module,exports){ /*globals _, wp */ /** @@ -6684,7 +5567,7 @@ Select = Toolbar.extend({ }); module.exports = Select; -},{"../toolbar.js":48}],50:[function(require,module,exports){ +},{"../toolbar.js":44}],46:[function(require,module,exports){ /*globals _, wp */ /** @@ -6817,7 +5700,7 @@ UploaderInline = View.extend({ }); module.exports = UploaderInline; -},{"../view.js":55,"./status.js":52}],51:[function(require,module,exports){ +},{"../view.js":51,"./status.js":48}],47:[function(require,module,exports){ /*globals wp */ /** @@ -6837,7 +5720,7 @@ UploaderStatusError = View.extend({ }); module.exports = UploaderStatusError; -},{"../view.js":55}],52:[function(require,module,exports){ +},{"../view.js":51}],48:[function(require,module,exports){ /*globals _, wp */ /** @@ -6977,7 +5860,7 @@ UploaderStatus = View.extend({ }); module.exports = UploaderStatus; -},{"../view.js":55,"./status-error.js":51}],53:[function(require,module,exports){ +},{"../view.js":51,"./status-error.js":47}],49:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -7090,7 +5973,7 @@ UploaderWindow = View.extend({ }); module.exports = UploaderWindow; -},{"../view.js":55}],54:[function(require,module,exports){ +},{"../view.js":51}],50:[function(require,module,exports){ /*globals wp */ /** @@ -7134,7 +6017,7 @@ VideoDetails = MediaDetails.extend({ }); module.exports = VideoDetails; -},{"./media-details":35}],55:[function(require,module,exports){ +},{"./media-details":31}],51:[function(require,module,exports){ /*globals wp */ /** diff --git a/wp-includes/js/media/audio-video.min.js b/wp-includes/js/media/audio-video.min.js index 2428959f9a..1a64d2daaa 100644 --- a/wp-includes/js/media/audio-video.min.js +++ b/wp-includes/js/media/audio-video.min.js @@ -1,3 +1,3 @@ -!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g=this.created:!0},c=["s","order","orderby","posts_per_page","post_mime_type","post_parent"],wp.Uploader&&_(this.args).chain().keys().difference(c).isEmpty().value()&&this.observe(wp.Uploader.queue)},hasMore:function(){return this._hasMore},more:function(a){var b=this;return this._more&&"pending"===this._more.state()?this._more:this.hasMore()?(a=a||{},a.remove=!1,this._more=this.fetch(a).done(function(a){(_.isEmpty(a)||-1===this.args.posts_per_page||a.length").val(b).html(a.text)[0],priority:a.priority||50}},this).sortBy("priority").pluck("el").value()),this.listenTo(this.model,"change",this.select),this.select()},createFilters:function(){this.filters={}},change:function(){var a=this.filters[this.el.value];a&&this.model.set(a.props)},select:function(){var a=this.model,b="all",c=a.toJSON();_.find(this.filters,function(a,d){var e=_.all(a.props,function(a,b){return a===(_.isUndefined(c[b])?null:c[b])});return e?b=d:void 0}),this.$el.val(b)}}),b.exports=c},{"./view.js":55}],17:[function(a,b){var c,d=a("../attachment-filters.js"),e=wp.media.view.l10n;c=d.extend({createFilters:function(){var a={};_.each(wp.media.view.settings.mimeTypes||{},function(b,c){a[c]={text:b,props:{status:null,type:c,uploadedTo:null,orderby:"date",order:"DESC"}}}),a.all={text:e.allMediaItems,props:{status:null,type:null,uploadedTo:null,orderby:"date",order:"DESC"},priority:10},wp.media.view.settings.post.id&&(a.uploaded={text:e.uploadedToThisPost,props:{status:null,type:null,uploadedTo:wp.media.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20}),a.unattached={text:e.unattached,props:{status:null,uploadedTo:0,type:null,orderby:"menuOrder",order:"ASC"},priority:50},wp.media.view.settings.mediaTrash&&this.controller.isModeActive("grid")&&(a.trash={text:e.trash,props:{uploadedTo:null,status:"trash",type:null,orderby:"date",order:"DESC"},priority:50}),this.filters=a}}),b.exports=c},{"../attachment-filters.js":16}],18:[function(a,b){var c,d=a("../attachment-filters.js"),e=wp.media.view.l10n;c=d.extend({id:"media-attachment-date-filters",createFilters:function(){var a={};_.each(wp.media.view.settings.months||{},function(b,c){a[c]={text:b.text,props:{year:b.year,monthnum:b.month}}}),a.all={text:e.allDates,props:{monthnum:!1,year:!1},priority:10},this.filters=a}}),b.exports=c},{"../attachment-filters.js":16}],19:[function(a,b){var c,d=a("../attachment-filters.js"),e=wp.media.view.l10n;c=d.extend({createFilters:function(){var a,b=this.model.get("type"),c=wp.media.view.settings.mimeTypes;c&&b&&(a=c[b]),this.filters={all:{text:a||e.allMediaItems,props:{uploadedTo:null,orderby:"date",order:"DESC"},priority:10},uploaded:{text:e.uploadedToThisPost,props:{uploadedTo:wp.media.view.settings.post.id,orderby:"menuOrder",order:"ASC"},priority:20},unattached:{text:e.unattached,props:{uploadedTo:0,orderby:"menuOrder",order:"ASC"},priority:50}}}}),b.exports=c},{"../attachment-filters.js":16}],20:[function(a,b){var c,d=a("./view.js"),e=jQuery;c=d.extend({tagName:"li",className:"attachment",template:wp.template("attachment"),attributes:function(){return{tabIndex:0,role:"checkbox","aria-label":this.model.get("title"),"aria-checked":!1,"data-id":this.model.get("id")}},events:{"click .js--select-attachment":"toggleSelectionHandler","change [data-setting]":"updateSetting","change [data-setting] input":"updateSetting","change [data-setting] select":"updateSetting","change [data-setting] textarea":"updateSetting","click .close":"removeFromLibrary","click .check":"checkClickHandler","click a":"preventDefault","keydown .close":"removeFromLibrary",keydown:"toggleSelectionHandler"},buttons:{},initialize:function(){var a=this.options.selection,b=_.defaults(this.options,{rerenderOnModelChange:!0});b.rerenderOnModelChange?this.listenTo(this.model,"change",this.render):this.listenTo(this.model,"change:percent",this.progress),this.listenTo(this.model,"change:title",this._syncTitle),this.listenTo(this.model,"change:caption",this._syncCaption),this.listenTo(this.model,"change:artist",this._syncArtist),this.listenTo(this.model,"change:album",this._syncAlbum),this.listenTo(this.model,"add",this.select),this.listenTo(this.model,"remove",this.deselect),a&&(a.on("reset",this.updateSelect,this),this.listenTo(this.model,"selection:single selection:unsingle",this.details),this.details(this.model,this.controller.state().get("selection"))),this.listenTo(this.controller,"attachment:compat:waiting attachment:compat:ready",this.updateSave)},dispose:function(){var a=this.options.selection;return this.updateAll(),a&&a.off(null,null,this),d.prototype.dispose.apply(this,arguments),this},render:function(){var a=_.defaults(this.model.toJSON(),{orientation:"landscape",uploading:!1,type:"",subtype:"",icon:"",filename:"",caption:"",title:"",dateFormatted:"",width:"",height:"",compat:!1,alt:"",description:""},this.options);return a.buttons=this.buttons,a.describe=this.controller.state().get("describe"),"image"===a.type&&(a.size=this.imageSize()),a.can={},a.nonces&&(a.can.remove=!!a.nonces["delete"],a.can.save=!!a.nonces.update),this.controller.state().get("allowLocalEdits")&&(a.allowLocalEdits=!0),a.uploading&&!a.percent&&(a.percent=0),this.views.detach(),this.$el.html(this.template(a)),this.$el.toggleClass("uploading",a.uploading),a.uploading?this.$bar=this.$(".media-progress-bar div"):delete this.$bar,this.updateSelect(),this.updateSave(),this.views.render(),this},progress:function(){this.$bar&&this.$bar.length&&this.$bar.width(this.model.get("percent")+"%")},toggleSelectionHandler:function(a){var b;if("INPUT"!==a.target.nodeName){if(37===a.keyCode||38===a.keyCode||39===a.keyCode||40===a.keyCode)return void this.controller.trigger("attachment:keydown:arrow",a);if("keydown"!==a.type||13===a.keyCode||32===a.keyCode){if(a.preventDefault(),this.controller.isModeActive("grid")){if(this.controller.isModeActive("edit"))return void this.controller.trigger("edit:attachment",this.model,a.currentTarget);this.controller.isModeActive("select")&&(b="toggle")}a.shiftKey?b="between":(a.ctrlKey||a.metaKey)&&(b="toggle"),this.toggleSelection({method:b}),this.controller.trigger("selection:toggle")}}},toggleSelection:function(a){var b,c,d,e,f=this.collection,g=this.options.selection,h=this.model,i=a&&a.method;if(g){if(b=g.single(),i=_.isUndefined(i)?g.multiple:i,"between"===i&&b&&g.multiple){if(b===h)return;return d=f.indexOf(b),e=f.indexOf(this.model),c=e>d?f.models.slice(d,e+1):f.models.slice(e,d+1),g.add(c),void g.single(h)}if("toggle"===i)return g[this.selected()?"remove":"add"](h),void g.single(h);if("add"===i)return g.add(h),void g.single(h);i||(i="add"),"add"!==i&&(i="reset"),this.selected()?g[b===h?"remove":"single"](h):(g[i](h),g.single(h))}},updateSelect:function(){this[this.selected()?"select":"deselect"]()},selected:function(){var a=this.options.selection;return a?!!a.get(this.model.cid):void 0},select:function(a,b){var c=this.options.selection,d=this.controller;!c||b&&b!==c||this.$el.hasClass("selected")||(this.$el.addClass("selected").attr("aria-checked",!0),d.isModeActive("grid")&&d.isModeActive("select")||this.$(".check").attr("tabindex","0"))},deselect:function(a,b){var c=this.options.selection;!c||b&&b!==c||this.$el.removeClass("selected").attr("aria-checked",!1).find(".check").attr("tabindex","-1")},details:function(a,b){var c,d=this.options.selection;d===b&&(c=d.single(),this.$el.toggleClass("details",c===this.model))},preventDefault:function(a){a.preventDefault()},imageSize:function(a){var b=this.model.get("sizes"),c=!1;return a=a||"medium",b&&(b[a]?c=b[a]:b.large?c=b.large:b.thumbnail?c=b.thumbnail:b.full&&(c=b.full),c)?_.clone(c):{url:this.model.get("url"),width:this.model.get("width"),height:this.model.get("height"),orientation:this.model.get("orientation")}},updateSetting:function(a){var b,c,d=e(a.target).closest("[data-setting]");d.length&&(b=d.data("setting"),c=a.target.value,this.model.get(b)!==c&&this.save(b,c))},save:function(){var a=this,b=this._save=this._save||{status:"ready"},c=this.model.save.apply(this.model,arguments),d=b.requests?e.when(c,b.requests):c;b.savedTimer&&clearTimeout(b.savedTimer),this.updateSave("waiting"),b.requests=d,d.always(function(){b.requests===d&&(a.updateSave("resolved"===d.state()?"complete":"error"),b.savedTimer=setTimeout(function(){a.updateSave("ready"),delete b.savedTimer},2e3))})},updateSave:function(a){var b=this._save=this._save||{status:"ready"};return a&&a!==b.status&&(this.$el.removeClass("save-"+b.status),b.status=a),this.$el.addClass("save-"+b.status),this},updateAll:function(){var a,b=this.$("[data-setting]"),c=this.model;a=_.chain(b).map(function(a){var b,d,f=e("input, textarea, select, [value]",a);if(f.length)return b=e(a).data("setting"),d=f.val(),c.get(b)!==d?[b,d]:void 0}).compact().object().value(),_.isEmpty(a)||c.save(a)},removeFromLibrary:function(a){("keydown"!==a.type||13===a.keyCode||32===a.keyCode)&&(a.stopPropagation(),this.collection.remove(this.model))},checkClickHandler:function(a){var b=this.options.selection;b&&(a.stopPropagation(),b.where({id:this.model.get("id")}).length?(b.remove(this.model),this.$el.focus()):b.add(this.model))}}),_.each({caption:"_syncCaption",title:"_syncTitle",artist:"_syncArtist",album:"_syncAlbum"},function(a,b){c.prototype[a]=function(a,c){var d=this.$('[data-setting="'+b+'"]');return d.length?c===d.find("input, textarea, select, [value]").val()?this:this.render():this}}),b.exports=c},{"./view.js":55}],21:[function(a,b){var c,d=a("../attachment.js"),e=wp.media.view.l10n;c=d.extend({tagName:"div",className:"attachment-details",template:wp.template("attachment-details"),attributes:function(){return{tabIndex:0,"data-id":this.model.get("id")}},events:{"change [data-setting]":"updateSetting","change [data-setting] input":"updateSetting","change [data-setting] select":"updateSetting","change [data-setting] textarea":"updateSetting","click .delete-attachment":"deleteAttachment","click .trash-attachment":"trashAttachment","click .untrash-attachment":"untrashAttachment","click .edit-attachment":"editAttachment","click .refresh-attachment":"refreshAttachment",keydown:"toggleSelectionHandler"},initialize:function(){this.options=_.defaults(this.options,{rerenderOnModelChange:!1}),this.on("ready",this.initialFocus),d.prototype.initialize.apply(this,arguments) -},initialFocus:function(){wp.media.isTouchDevice||this.$(":input").eq(0).focus()},deleteAttachment:function(a){a.preventDefault(),confirm(e.warnDelete)&&(this.model.destroy(),this.controller.modal.focusManager.focus())},trashAttachment:function(a){var b=this.controller.library;a.preventDefault(),wp.media.view.settings.mediaTrash&&"edit-metadata"===this.controller.content.mode()?(this.model.set("status","trash"),this.model.save().done(function(){b._requery(!0)})):this.model.destroy()},untrashAttachment:function(a){var b=this.controller.library;a.preventDefault(),this.model.set("status","inherit"),this.model.save().done(function(){b._requery(!0)})},editAttachment:function(a){var b=this.controller.states.get("edit-image");window.imageEdit&&b?(a.preventDefault(),b.set("image",this.model),this.controller.setState("edit-image")):this.$el.addClass("needs-refresh")},refreshAttachment:function(a){this.$el.removeClass("needs-refresh"),a.preventDefault(),this.model.fetch()},toggleSelectionHandler:function(a){return"keydown"===a.type&&9===a.keyCode&&a.shiftKey&&a.target===this.$(":tabbable").get(0)?(this.controller.trigger("attachment:details:shift-tab",a),!1):37===a.keyCode||38===a.keyCode||39===a.keyCode||40===a.keyCode?void this.controller.trigger("attachment:keydown:arrow",a):void 0}}),b.exports=c},{"../attachment.js":20}],22:[function(a,b){var c,d=a("../attachment.js");c=d.extend({buttons:{check:!0}}),b.exports=c},{"../attachment.js":20}],23:[function(a,b){var c,d=a("./view.js"),e=a("./attachment.js"),f=jQuery;c=d.extend({tagName:"ul",className:"attachments",attributes:{tabIndex:-1},initialize:function(){this.el.id=_.uniqueId("__attachments-view-"),_.defaults(this.options,{refreshSensitivity:wp.media.isTouchDevice?300:200,refreshThreshold:3,AttachmentView:e,sortable:!1,resize:!0,idealColumnWidth:f(window).width()<640?135:150}),this._viewsByCid={},this.$window=f(window),this.resizeEvent="resize.media-modal-columns",this.collection.on("add",function(a){this.views.add(this.createAttachmentView(a),{at:this.collection.indexOf(a)})},this),this.collection.on("remove",function(a){var b=this._viewsByCid[a.cid];delete this._viewsByCid[a.cid],b&&b.remove()},this),this.collection.on("reset",this.render,this),this.listenTo(this.controller,"library:selection:add",this.attachmentFocus),this.scroll=_.chain(this.scroll).bind(this).throttle(this.options.refreshSensitivity).value(),this.options.scrollElement=this.options.scrollElement||this.el,f(this.options.scrollElement).on("scroll",this.scroll),this.initSortable(),_.bindAll(this,"setColumns"),this.options.resize&&(this.on("ready",this.bindEvents),this.controller.on("open",this.setColumns),_.defer(this.setColumns,this))},bindEvents:function(){this.$window.off(this.resizeEvent).on(this.resizeEvent,_.debounce(this.setColumns,50))},attachmentFocus:function(){this.$("li:first").focus()},restoreFocus:function(){this.$("li.selected:first").focus()},arrowEvent:function(a){var b=this.$el.children("li"),c=this.columns,d=b.filter(":focus").index(),e=c>=d+1?1:Math.ceil((d+1)/c);if(-1!==d){if(37===a.keyCode){if(0===d)return;b.eq(d-1).focus()}if(38===a.keyCode){if(1===e)return;b.eq(d-c).focus()}if(39===a.keyCode){if(b.length===d)return;b.eq(d+1).focus()}if(40===a.keyCode){if(Math.ceil(b.length/c)===e)return;b.eq(d+c).focus()}}},dispose:function(){this.collection.props.off(null,null,this),this.options.resize&&this.$window.off(this.resizeEvent),d.prototype.dispose.apply(this,arguments)},setColumns:function(){var a=this.columns,b=this.$el.width();b&&(this.columns=Math.min(Math.round(b/this.options.idealColumnWidth),12)||1,a&&a===this.columns||this.$el.closest(".media-frame-content").attr("data-columns",this.columns))},initSortable:function(){var a=this.collection;!wp.media.isTouchDevice&&this.options.sortable&&f.fn.sortable&&(this.$el.sortable(_.extend({disabled:!!a.comparator,tolerance:"pointer",start:function(a,b){b.item.data("sortableIndexStart",b.item.index())},update:function(b,c){var d=a.at(c.item.data("sortableIndexStart")),e=a.comparator;delete a.comparator,a.remove(d,{silent:!0}),a.add(d,{silent:!0,at:c.item.index()}),a.comparator=e,a.trigger("reset",a),a.saveMenuOrder()}},this.options.sortable)),a.props.on("change:orderby",function(){this.$el.sortable("option","disabled",!!a.comparator)},this),this.collection.props.on("change:orderby",this.refreshSortable,this),this.refreshSortable())},refreshSortable:function(){if(!wp.media.isTouchDevice&&this.options.sortable&&f.fn.sortable){var a=this.collection,b=a.props.get("orderby"),c="menuOrder"===b||!a.comparator;this.$el.sortable("option","disabled",!c)}},createAttachmentView:function(a){var b=new this.options.AttachmentView({controller:this.controller,model:a,collection:this.collection,selection:this.options.selection});return this._viewsByCid[a.cid]=b},prepare:function(){this.collection.length?this.views.set(this.collection.map(this.createAttachmentView,this)):(this.views.unset(),this.collection.more().done(this.scroll))},ready:function(){this.scroll()},scroll:function(){var a,b=this,c=this.options.scrollElement,d=c.scrollTop;c==document&&(c=document.body,d=f(document).scrollTop()),f(c).is(":visible")&&this.collection.hasMore()&&(a=this.views.parent.toolbar,c.scrollHeight-(d+c.clientHeight)'+u.dragInfo+"")[0],priority:-40})),this.options.suggestedWidth&&this.options.suggestedHeight&&this.toolbar.set("suggestedDimensions",new d({el:v('
'+u.suggestedDimensions+" "+this.options.suggestedWidth+" × "+this.options.suggestedHeight+"
")[0],priority:-40}))},updateContent:function(){var a,b=this;a=this.controller.isModeActive("grid")?b.attachmentsNoResults:b.uploader,this.collection.length?(a.$el.addClass("hidden"),b.toolbar.get("spinner").hide()):(this.toolbar.get("spinner").show(),this.dfd=this.collection.more().done(function(){b.collection.length?a.$el.addClass("hidden"):a.$el.removeClass("hidden"),b.toolbar.get("spinner").hide()}))},createUploader:function(){this.uploader=new m({controller:this.controller,status:!1,message:this.controller.isModeActive("grid")?"":u.noItemsFound,canClose:this.controller.isModeActive("grid")}),this.uploader.hide(),this.views.add(this.uploader)},toggleUploader:function(){this.uploader.$el.hasClass("hidden")?this.uploader.show():this.uploader.hide()},createAttachments:function(){this.attachments=new n({controller:this.controller,collection:this.collection,selection:this.options.selection,model:this.model,sortable:this.options.sortable,scrollElement:this.options.scrollElement,idealColumnWidth:this.options.idealColumnWidth,AttachmentView:this.options.AttachmentView}),this.attachments.listenTo(this.controller,"attachment:keydown:arrow",this.attachments.arrowEvent),this.attachments.listenTo(this.controller,"attachment:details:shift-tab",this.attachments.restoreFocus),this.views.add(this.attachments),this.controller.isModeActive("grid")&&(this.attachmentsNoResults=new d({controller:this.controller,tagName:"p"}),this.attachmentsNoResults.$el.addClass("hidden no-media"),this.attachmentsNoResults.$el.html(u.noMedia),this.views.add(this.attachmentsNoResults))},createSidebar:function(){var a=this.options,b=a.selection,c=this.sidebar=new o({controller:this.controller});this.views.add(c),this.controller.uploader&&c.set("uploads",new p({controller:this.controller,priority:40})),b.on("selection:single",this.createSingle,this),b.on("selection:unsingle",this.disposeSingle,this),b.single()&&this.createSingle()},createSingle:function(){var a=this.sidebar,b=this.options.selection.single();a.set("details",new q({controller:this.controller,model:b,priority:80})),a.set("compat",new r({controller:this.controller,model:b,priority:120})),this.options.display&&a.set("display",new s({controller:this.controller,model:this.model.display(b),attachment:b,priority:160,userSettings:this.model.get("displayUserSettings")})),"insert"===this.model.id&&a.$el.addClass("visible")},disposeSingle:function(){var a=this.sidebar;a.unset("details"),a.unset("compat"),a.unset("display"),a.$el.removeClass("visible")}}),b.exports=c},{"../attachment-compat.js":15,"../attachment-filters/all.js":17,"../attachment-filters/date.js":18,"../attachment-filters/uploaded.js":19,"../attachment/details.js":21,"../attachment/library.js":22,"../attachments.js":23,"../label.js":34,"../search.js":43,"../settings/attachment-display.js":45,"../sidebar.js":46,"../spinner.js":47,"../toolbar.js":48,"../uploader/inline.js":50,"../uploader/status.js":52,"../view.js":55}],25:[function(a,b){var c,d=a("./media-details");c=d.extend({className:"audio-details",template:wp.template("audio-details"),setMedia:function(){var a=this.$(".wp-audio-shortcode");return a.find("source").length?(a.is(":hidden")&&a.show(),this.media=d.prepareSrc(a.get(0))):(a.hide(),this.media=!1),this}}),b.exports=c},{"./media-details":35}],26:[function(a,b){var c,d=a("./view.js");c=d.extend({tagName:"a",className:"media-button",attributes:{href:"#"},events:{click:"click"},defaults:{text:"",style:"",size:"large",disabled:!1},initialize:function(){this.model=new Backbone.Model(this.defaults),_.each(this.defaults,function(a,b){var c=this.options[b];_.isUndefined(c)||(this.model.set(b,c),delete this.options[b])},this),this.listenTo(this.model,"change",this.render)},render:function(){var a=["button",this.className],b=this.model.toJSON();return b.style&&a.push("button-"+b.style),b.size&&a.push("button-"+b.size),a=_.uniq(a.concat(this.options.classes)),this.el.className=a.join(" "),this.$el.attr("disabled",b.disabled),this.$el.text(this.model.get("text")),this},click:function(a){"#"===this.attributes.href&&a.preventDefault(),this.options.click&&!this.model.get("disabled")&&this.options.click.apply(this,arguments)}}),b.exports=c},{"./view.js":55}],27:[function(a,b){var c,d=a("./view.js");c=d.extend({events:{keydown:"constrainTabbing"},focus:function(){this.$(".media-menu-item").first().focus()},constrainTabbing:function(a){var b;if(9===a.keyCode)return b=this.$(":tabbable").not('.moxie-shim input[type="file"]'),b.last()[0]!==a.target||a.shiftKey?b.first()[0]===a.target&&a.shiftKey?(b.last().focus(),!1):void 0:(b.first().focus(),!1)}}),b.exports=c},{"./view.js":55}],28:[function(a,b){var c,d=a("../controllers/state-machine.js"),e=a("../controllers/state.js"),f=a("../controllers/region.js"),g=a("./view.js");c=g.extend({initialize:function(){_.defaults(this.options,{mode:["select"]}),this._createRegions(),this._createStates(),this._createModes()},_createRegions:function(){this.regions=this.regions?this.regions.slice():[],_.each(this.regions,function(a){this[a]=new f({view:this,id:a,selector:".media-frame-"+a})},this)},_createStates:function(){this.states=new Backbone.Collection(null,{model:e}),this.states.on("add",function(a){a.frame=this,a.trigger("ready")},this),this.options.states&&this.states.add(this.options.states)},_createModes:function(){this.activeModes=new Backbone.Collection,this.activeModes.on("add remove reset",_.bind(this.triggerModeEvents,this)),_.each(this.options.mode,function(a){this.activateMode(a)},this)},reset:function(){return this.states.invoke("trigger","reset"),this},triggerModeEvents:function(a,b,c){var d,e,f={add:"activate",remove:"deactivate"};_.each(c,function(a,b){a&&(d=b)}),_.has(f,d)&&(e=a.get("id")+":"+f[d],this.trigger(e))},activateMode:function(a){return this.isModeActive(a)?void 0:(this.activeModes.add([{id:a}]),this.$el.addClass("mode-"+a),this)},deactivateMode:function(a){return this.isModeActive(a)?(this.activeModes.remove(this.activeModes.where({id:a})),this.$el.removeClass("mode-"+a),this.trigger(a+":deactivate"),this):this},isModeActive:function(a){return Boolean(this.activeModes.where({id:a}).length)}}),_.extend(c.prototype,d.prototype),b.exports=c},{"../controllers/region.js":5,"../controllers/state-machine.js":6,"../controllers/state.js":7,"./view.js":55}],29:[function(a,b){var c,d=a("./media-details"),e=a("../../controllers/media-library.js"),f=a("../audio-details.js"),g=a("../../controllers/audio-details.js"),h=wp.media.view.l10n;c=d.extend({defaults:{id:"audio",url:"",menu:"audio-details",content:"audio-details",toolbar:"audio-details",type:"link",title:h.audioDetailsTitle,priority:120},initialize:function(a){a.DetailsView=f,a.cancelText=h.audioDetailsCancel,a.addText=h.audioAddSourceTitle,d.prototype.initialize.call(this,a)},bindHandlers:function(){d.prototype.bindHandlers.apply(this,arguments),this.on("toolbar:render:replace-audio",this.renderReplaceToolbar,this),this.on("toolbar:render:add-audio-source",this.renderAddSourceToolbar,this)},createStates:function(){this.states.add([new g({media:this.media}),new e({type:"audio",id:"replace-audio",title:h.audioReplaceTitle,toolbar:"replace-audio",media:this.media,menu:"audio-details"}),new e({type:"audio",id:"add-audio-source",title:h.audioAddSourceTitle,toolbar:"add-audio-source",media:this.media,menu:!1})])}}),b.exports=c},{"../../controllers/audio-details.js":2,"../../controllers/media-library.js":4,"../audio-details.js":25,"./media-details":30}],30:[function(a,b){var c,d=a("../view.js"),e=a("../toolbar.js"),f=a("./select.js"),g=a("../../models/selection.js"),h=a("../../models/post-media.js"),i=wp.media.view.l10n;c=f.extend({defaults:{id:"media",url:"",menu:"media-details",content:"media-details",toolbar:"media-details",type:"link",priority:120},initialize:function(a){this.DetailsView=a.DetailsView,this.cancelText=a.cancelText,this.addText=a.addText,this.media=new h(a.metadata),this.options.selection=new g(this.media.attachment,{multiple:!1}),f.prototype.initialize.apply(this,arguments)},bindHandlers:function(){var a=this.defaults.menu;f.prototype.bindHandlers.apply(this,arguments),this.on("menu:create:"+a,this.createMenu,this),this.on("content:render:"+a,this.renderDetailsContent,this),this.on("menu:render:"+a,this.renderMenu,this),this.on("toolbar:render:"+a,this.renderDetailsToolbar,this)},renderDetailsContent:function(){var a=new this.DetailsView({controller:this,model:this.state().media,attachment:this.state().media.attachment}).render();this.content.set(a)},renderMenu:function(a){var b=this.lastState(),c=b&&b.id,e=this;a.set({cancel:{text:this.cancelText,priority:20,click:function(){c?e.setState(c):e.close()}},separateCancel:new d({className:"separator",priority:40})})},setPrimaryButton:function(a,b){this.toolbar.set(new e({controller:this,items:{button:{style:"primary",text:a,priority:80,click:function(){var a=this.controller;b.call(this,a,a.state()),a.setState(a.options.state),a.reset()}}}}))},renderDetailsToolbar:function(){this.setPrimaryButton(i.update,function(a,b){a.close(),b.trigger("update",a.media.toJSON())})},renderReplaceToolbar:function(){this.setPrimaryButton(i.replace,function(a,b){var c=b.get("selection").single();a.media.changeAttachment(c),b.trigger("replace",a.media.toJSON())})},renderAddSourceToolbar:function(){this.setPrimaryButton(this.addText,function(a,b){var c=b.get("selection").single();a.media.setSource(c),b.trigger("add-source",a.media.toJSON())})}}),b.exports=c},{"../../models/post-media.js":11,"../../models/selection.js":13,"../toolbar.js":48,"../view.js":55,"./select.js":31}],31:[function(a,b){var c,d=a("../media-frame.js"),e=a("../../controllers/library.js"),f=a("../../models/attachments.js"),g=a("../../models/selection.js"),h=a("../attachments/browser.js"),i=a("../uploader/inline.js"),j=a("../toolbar/select.js"),k=wp.media.view.l10n;c=d.extend({initialize:function(){d.prototype.initialize.apply(this,arguments),_.defaults(this.options,{selection:[],library:{},multiple:!1,state:"library"}),this.createSelection(),this.createStates(),this.bindHandlers()},createSelection:function(){var a=this.options.selection;a instanceof g||(this.options.selection=new g(a,{multiple:this.options.multiple})),this._selection={attachments:new f,difference:[]}},createStates:function(){var a=this.options;this.options.states||this.states.add([new e({library:wp.media.query(a.library),multiple:a.multiple,title:a.title,priority:20})])},bindHandlers:function(){this.on("router:create:browse",this.createRouter,this),this.on("router:render:browse",this.browseRouter,this),this.on("content:create:browse",this.browseContent,this),this.on("content:render:upload",this.uploadContent,this),this.on("toolbar:create:select",this.createSelectToolbar,this)},browseRouter:function(a){a.set({upload:{text:k.uploadFilesTitle,priority:20},browse:{text:k.mediaLibraryTitle,priority:40}})},browseContent:function(a){var b=this.state();this.$el.removeClass("hide-toolbar"),a.view=new h({controller:this,collection:b.get("library"),selection:b.get("selection"),model:b,sortable:b.get("sortable"),search:b.get("searchable"),filters:b.get("filterable"),display:b.get(b.has("display")?"display":"displaySettings"),dragInfo:b.get("dragInfo"),idealColumnWidth:b.get("idealColumnWidth"),suggestedWidth:b.get("suggestedWidth"),suggestedHeight:b.get("suggestedHeight"),AttachmentView:b.get("AttachmentView")})},uploadContent:function(){this.$el.removeClass("hide-toolbar"),this.content.set(new i({controller:this}))},createSelectToolbar:function(a,b){b=b||this.options.button||{},b.controller=this,a.view=new j(b)}}),b.exports=c},{"../../controllers/library.js":3,"../../models/attachments.js":10,"../../models/selection.js":13,"../attachments/browser.js":24,"../media-frame.js":36,"../toolbar/select.js":49,"../uploader/inline.js":50}],32:[function(a,b){var c,d=a("./media-details"),e=a("../../controllers/media-library.js"),f=a("../video-details.js"),g=a("../../controllers/video-details.js"),h=wp.media.view.l10n;c=d.extend({defaults:{id:"video",url:"",menu:"video-details",content:"video-details",toolbar:"video-details",type:"link",title:h.videoDetailsTitle,priority:120},initialize:function(a){a.DetailsView=f,a.cancelText=h.videoDetailsCancel,a.addText=h.videoAddSourceTitle,d.prototype.initialize.call(this,a)},bindHandlers:function(){d.prototype.bindHandlers.apply(this,arguments),this.on("toolbar:render:replace-video",this.renderReplaceToolbar,this),this.on("toolbar:render:add-video-source",this.renderAddSourceToolbar,this),this.on("toolbar:render:select-poster-image",this.renderSelectPosterImageToolbar,this),this.on("toolbar:render:add-track",this.renderAddTrackToolbar,this)},createStates:function(){this.states.add([new g({media:this.media}),new e({type:"video",id:"replace-video",title:h.videoReplaceTitle,toolbar:"replace-video",media:this.media,menu:"video-details"}),new e({type:"video",id:"add-video-source",title:h.videoAddSourceTitle,toolbar:"add-video-source",media:this.media,menu:!1}),new e({type:"image",id:"select-poster-image",title:h.videoSelectPosterImageTitle,toolbar:"select-poster-image",media:this.media,menu:"video-details"}),new e({type:"text",id:"add-track",title:h.videoAddTrackTitle,toolbar:"add-track",media:this.media,menu:"video-details"})])},renderSelectPosterImageToolbar:function(){this.setPrimaryButton(h.videoSelectPosterImageTitle,function(a,b){var c=[],d=b.get("selection").single();a.media.set("poster",d.get("url")),b.trigger("set-poster-image",a.media.toJSON()),_.each(wp.media.view.settings.embedExts,function(b){a.media.get(b)&&c.push(a.media.get(b))}),wp.ajax.send("set-attachment-thumbnail",{data:{urls:c,thumbnail_id:d.get("id")}})})},renderAddTrackToolbar:function(){this.setPrimaryButton(h.videoAddTrackTitle,function(a,b){var c=b.get("selection").single(),d=a.media.get("content");-1===d.indexOf(c.get("url"))&&(d+=[''].join(""),a.media.set("content",d)),b.trigger("add-track",a.media.toJSON())})}}),b.exports=c},{"../../controllers/media-library.js":4,"../../controllers/video-details.js":8,"../video-details.js":54,"./media-details":30}],33:[function(a,b){var c,d=a("./view.js");c=d.extend({className:"media-iframe",render:function(){return this.views.detach(),this.$el.html('