From 1c9874a7f27a69bcd4bf0a0d585bcf615582c429 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 9 Feb 2015 04:13:38 +0000 Subject: [PATCH] Make sure that `media/views.js` doesn't load Models that already exist in `media/models.js`. See #28510. git-svn-id: https://develop.svn.wordpress.org/trunk@31379 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media/audio-video.js | 1217 +------------- .../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 +- .../js/media/controllers/library.js | 3 +- src/wp-includes/js/media/grid.js | 1207 +------------- src/wp-includes/js/media/views.js | 1437 +---------------- .../js/media/views/frame/image-details.js | 6 +- .../js/media/views/frame/media-details.js | 6 +- src/wp-includes/js/media/views/frame/post.js | 7 +- .../js/media/views/frame/select.js | 8 +- 13 files changed, 195 insertions(+), 3712 deletions(-) diff --git a/src/wp-includes/js/media/audio-video.js b/src/wp-includes/js/media/audio-video.js index 5d888e83db..7e0d06cf33 100644 --- a/src/wp-includes/js/media/audio-video.js +++ b/src/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/src/wp-includes/js/media/controllers/collection-add.js b/src/wp-includes/js/media/controllers/collection-add.js index e2dfb14b08..edf373813d 100644 --- a/src/wp-includes/js/media/controllers/collection-add.js +++ b/src/wp-includes/js/media/controllers/collection-add.js @@ -33,7 +33,7 @@ * @param {string} attributes.type The collection's media type. (e.g. 'video'). * @param {string} attributes.collectionType The collection type. (e.g. 'playlist'). */ -var Selection = require( '../models/selection.js' ), +var Selection = wp.media.model.Selection, Library = require( './library.js' ), CollectionAdd; diff --git a/src/wp-includes/js/media/controllers/collection-edit.js b/src/wp-includes/js/media/controllers/collection-edit.js index b5297a0a54..1b90995e06 100644 --- a/src/wp-includes/js/media/controllers/collection-edit.js +++ b/src/wp-includes/js/media/controllers/collection-edit.js @@ -34,8 +34,7 @@ * @param {string} attributes.type The collection's media type. (e.g. 'video'). * @param {string} attributes.collectionType The collection type. (e.g. 'playlist'). */ -var Selection = require( '../models/selection.js' ), - Library = require( './library.js' ), +var Library = require( './library.js' ), View = require( '../views/view.js' ), EditLibraryView = require( '../views/attachment/edit-library.js' ), l10n = wp.media.view.l10n, @@ -72,7 +71,7 @@ CollectionEdit = Library.extend({ // If we haven't been provided a `library`, create a `Selection`. if ( ! this.get('library') ) { - this.set( 'library', new Selection() ); + this.set( 'library', new wp.media.model.Selection() ); } // The single `Attachment` view to be used in the `Attachments` view. if ( ! this.get('AttachmentView') ) { diff --git a/src/wp-includes/js/media/controllers/featured-image.js b/src/wp-includes/js/media/controllers/featured-image.js index da354ae771..67380549c3 100644 --- a/src/wp-includes/js/media/controllers/featured-image.js +++ b/src/wp-includes/js/media/controllers/featured-image.js @@ -31,7 +31,7 @@ * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user. * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state. */ -var Attachment = require( '../models/attachment.js' ), +var Attachment = wp.media.model.Attachment, Library = require( './library.js' ), l10n = wp.media.view.l10n, FeaturedImage; diff --git a/src/wp-includes/js/media/controllers/gallery-add.js b/src/wp-includes/js/media/controllers/gallery-add.js index 9f554e5534..6686cf3b6c 100644 --- a/src/wp-includes/js/media/controllers/gallery-add.js +++ b/src/wp-includes/js/media/controllers/gallery-add.js @@ -29,7 +29,7 @@ * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state. * Defaults to false because for this state, because the library of the Edit Gallery state is the selection. */ -var Selection = require( '../models/selection.js' ), +var Selection = wp.media.model.Selection, Library = require( './library.js' ), l10n = wp.media.view.l10n, GalleryAdd; diff --git a/src/wp-includes/js/media/controllers/gallery-edit.js b/src/wp-includes/js/media/controllers/gallery-edit.js index 9dd4a4cb91..8f55dc9ffc 100644 --- a/src/wp-includes/js/media/controllers/gallery-edit.js +++ b/src/wp-includes/js/media/controllers/gallery-edit.js @@ -31,8 +31,7 @@ * @param {view} [attributes.AttachmentView] The single `Attachment` view to be used in the `Attachments`. * If none supplied, defaults to wp.media.view.Attachment.EditLibrary. */ -var Selection = require( '../models/selection.js' ), - Library = require( './library.js' ), +var Library = require( './library.js' ), EditLibraryView = require( '../views/attachment/edit-library.js' ), GallerySettingsView = require( '../views/settings/gallery.js' ), l10n = wp.media.view.l10n, @@ -63,7 +62,7 @@ GalleryEdit = Library.extend({ initialize: function() { // If we haven't been provided a `library`, create a `Selection`. if ( ! this.get('library') ) - this.set( 'library', new Selection() ); + this.set( 'library', new wp.media.model.Selection() ); // The single `Attachment` view to be used in the `Attachments` view. if ( ! this.get('AttachmentView') ) diff --git a/src/wp-includes/js/media/controllers/library.js b/src/wp-includes/js/media/controllers/library.js index 9980384ea3..2b0288060a 100644 --- a/src/wp-includes/js/media/controllers/library.js +++ b/src/wp-includes/js/media/controllers/library.js @@ -35,7 +35,6 @@ * @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; @@ -80,7 +79,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 }) ); diff --git a/src/wp-includes/js/media/grid.js b/src/wp-includes/js/media/grid.js index 946531c7f2..74b86ca18c 100644 --- a/src/wp-includes/js/media/grid.js +++ b/src/wp-includes/js/media/grid.js @@ -107,7 +107,7 @@ EditImage = State.extend({ }); module.exports = EditImage; -},{"../views/toolbar.js":50,"./state.js":6}],3:[function(require,module,exports){ +},{"../views/toolbar.js":46,"./state.js":6}],3:[function(require,module,exports){ /*globals _, wp, Backbone, getUserSetting, setUserSetting */ /** @@ -145,7 +145,6 @@ module.exports = EditImage; * @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; @@ -190,7 +189,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 }) ); @@ -381,7 +380,7 @@ Library = State.extend({ _.extend( Library.prototype, selectionSync ); module.exports = Library; -},{"../models/selection.js":11,"../utils/selection-sync.js":13,"./state.js":6}],4:[function(require,module,exports){ +},{"../utils/selection-sync.js":9,"./state.js":6}],4:[function(require,module,exports){ /*globals _, Backbone */ /** @@ -944,1119 +943,7 @@ module.exports = State; media.view.DeleteSelectedPermanentlyButton = require( './views/button/delete-selected-permanently.js' ); }(wp)); -},{"./controllers/edit-attachment-metadata.js":1,"./routers/manage.js":12,"./views/attachment/details-two-column.js":20,"./views/button/delete-selected-permanently.js":26,"./views/button/delete-selected.js":27,"./views/button/select-mode-toggle.js":28,"./views/edit-image-details.js":29,"./views/frame/edit-attachments.js":33,"./views/frame/manage.js":34}],8:[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":9}],9:[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":8,"./query.js":10}],10:[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":9}],11:[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":9}],12:[function(require,module,exports){ +},{"./controllers/edit-attachment-metadata.js":1,"./routers/manage.js":8,"./views/attachment/details-two-column.js":16,"./views/button/delete-selected-permanently.js":22,"./views/button/delete-selected.js":23,"./views/button/select-mode-toggle.js":24,"./views/edit-image-details.js":25,"./views/frame/edit-attachments.js":29,"./views/frame/manage.js":30}],8:[function(require,module,exports){ /*globals jQuery, Backbone */ /** @@ -2103,7 +990,7 @@ var Router = Backbone.Router.extend({ }); module.exports = Router; -},{}],13:[function(require,module,exports){ +},{}],9:[function(require,module,exports){ /*globals _ */ /** @@ -2170,7 +1057,7 @@ var selectionSync = { }; module.exports = selectionSync; -},{}],14:[function(require,module,exports){ +},{}],10:[function(require,module,exports){ /*globals _ */ /** @@ -2256,7 +1143,7 @@ AttachmentCompat = View.extend({ }); module.exports = AttachmentCompat; -},{"./view.js":55}],15:[function(require,module,exports){ +},{"./view.js":51}],11:[function(require,module,exports){ /*globals _, jQuery */ /** @@ -2335,7 +1222,7 @@ AttachmentFilters = View.extend({ }); module.exports = AttachmentFilters; -},{"./view.js":55}],16:[function(require,module,exports){ +},{"./view.js":51}],12:[function(require,module,exports){ /*globals _, wp */ /** @@ -2427,7 +1314,7 @@ All = AttachmentFilters.extend({ }); module.exports = All; -},{"../attachment-filters.js":15}],17:[function(require,module,exports){ +},{"../attachment-filters.js":11}],13:[function(require,module,exports){ /*globals _, wp */ /** @@ -2470,7 +1357,7 @@ DateFilter = AttachmentFilters.extend({ }); module.exports = DateFilter; -},{"../attachment-filters.js":15}],18:[function(require,module,exports){ +},{"../attachment-filters.js":11}],14:[function(require,module,exports){ /*globals wp */ /** @@ -2531,7 +1418,7 @@ Uploaded = AttachmentFilters.extend({ }); module.exports = Uploaded; -},{"../attachment-filters.js":15}],19:[function(require,module,exports){ +},{"../attachment-filters.js":11}],15:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -3086,7 +1973,7 @@ _.each({ }); module.exports = Attachment; -},{"./view.js":55}],20:[function(require,module,exports){ +},{"./view.js":51}],16:[function(require,module,exports){ /*globals wp */ /** @@ -3129,7 +2016,7 @@ TwoColumn = Details.extend({ }); module.exports = TwoColumn; -},{"../media-details.js":37,"./details.js":21}],21:[function(require,module,exports){ +},{"../media-details.js":33,"./details.js":17}],17:[function(require,module,exports){ /*globals _, wp */ /** @@ -3270,7 +2157,7 @@ Details = Attachment.extend({ }); module.exports = Details; -},{"../attachment.js":19}],22:[function(require,module,exports){ +},{"../attachment.js":15}],18:[function(require,module,exports){ /** * wp.media.view.Attachment.Library * @@ -3290,7 +2177,7 @@ Library = Attachment.extend({ }); module.exports = Library; -},{"../attachment.js":19}],23:[function(require,module,exports){ +},{"../attachment.js":15}],19:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -3591,7 +2478,7 @@ Attachments = View.extend({ }); module.exports = Attachments; -},{"./attachment.js":19,"./view.js":55}],24:[function(require,module,exports){ +},{"./attachment.js":15,"./view.js":51}],20:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -4051,7 +2938,7 @@ AttachmentsBrowser = View.extend({ }); module.exports = AttachmentsBrowser; -},{"../attachment-compat.js":14,"../attachment-filters/all.js":16,"../attachment-filters/date.js":17,"../attachment-filters/uploaded.js":18,"../attachment/details.js":21,"../attachment/library.js":22,"../attachments.js":23,"../label.js":36,"../search.js":45,"../settings/attachment-display.js":47,"../sidebar.js":48,"../spinner.js":49,"../toolbar.js":50,"../uploader/inline.js":51,"../uploader/status.js":53,"../view.js":55}],25:[function(require,module,exports){ +},{"../attachment-compat.js":10,"../attachment-filters/all.js":12,"../attachment-filters/date.js":13,"../attachment-filters/uploaded.js":14,"../attachment/details.js":17,"../attachment/library.js":18,"../attachments.js":19,"../label.js":32,"../search.js":41,"../settings/attachment-display.js":43,"../sidebar.js":44,"../spinner.js":45,"../toolbar.js":46,"../uploader/inline.js":47,"../uploader/status.js":49,"../view.js":51}],21:[function(require,module,exports){ /*globals _, Backbone */ /** @@ -4141,7 +3028,7 @@ Button = View.extend({ }); module.exports = Button; -},{"./view.js":55}],26:[function(require,module,exports){ +},{"./view.js":51}],22:[function(require,module,exports){ /** * When MEDIA_TRASH is true, a button that handles bulk Delete Permanently logic * @@ -4185,7 +3072,7 @@ DeleteSelectedPermanently = DeleteSelected.extend({ }); module.exports = DeleteSelectedPermanently; -},{"../button.js":25,"./delete-selected.js":27}],27:[function(require,module,exports){ +},{"../button.js":21,"./delete-selected.js":23}],23:[function(require,module,exports){ /*globals wp */ /** @@ -4237,7 +3124,7 @@ DeleteSelected = Button.extend({ }); module.exports = DeleteSelected; -},{"../button.js":25}],28:[function(require,module,exports){ +},{"../button.js":21}],24:[function(require,module,exports){ /*globals wp */ var Button = require( '../button.js' ), @@ -4293,7 +3180,7 @@ SelectModeToggle = Button.extend({ }); module.exports = SelectModeToggle; -},{"../button.js":25}],29:[function(require,module,exports){ +},{"../button.js":21}],25:[function(require,module,exports){ var View = require( './view.js' ), EditImage = require( './edit-image.js' ), Details; @@ -4320,7 +3207,7 @@ Details = EditImage.extend({ }); module.exports = Details; -},{"./edit-image.js":30,"./view.js":55}],30:[function(require,module,exports){ +},{"./edit-image.js":26,"./view.js":51}],26:[function(require,module,exports){ /*globals _, wp */ var View = require( './view.js' ), @@ -4375,7 +3262,7 @@ EditImage = View.extend({ }); module.exports = EditImage; -},{"./view.js":55}],31:[function(require,module,exports){ +},{"./view.js":51}],27:[function(require,module,exports){ /** * wp.media.view.FocusManager * @@ -4423,7 +3310,7 @@ FocusManager = View.extend({ }); module.exports = FocusManager; -},{"./view.js":55}],32:[function(require,module,exports){ +},{"./view.js":51}],28:[function(require,module,exports){ /*globals _, Backbone */ /** @@ -4596,7 +3483,7 @@ Frame = View.extend({ _.extend( Frame.prototype, StateMachine.prototype ); module.exports = Frame; -},{"../controllers/region.js":4,"../controllers/state-machine.js":5,"../controllers/state.js":6,"./view.js":55}],33:[function(require,module,exports){ +},{"../controllers/region.js":4,"../controllers/state-machine.js":5,"../controllers/state.js":6,"./view.js":51}],29:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -4845,7 +3732,7 @@ EditAttachments = MediaFrame.extend({ }); module.exports = EditAttachments; -},{"../../controllers/edit-attachment-metadata.js":1,"../../controllers/edit-image.js":2,"../attachment-compat.js":14,"../attachment/details-two-column.js":20,"../edit-image-details.js":29,"../frame.js":32,"../media-frame.js":38,"../modal.js":41}],34:[function(require,module,exports){ +},{"../../controllers/edit-attachment-metadata.js":1,"../../controllers/edit-image.js":2,"../attachment-compat.js":10,"../attachment/details-two-column.js":16,"../edit-image-details.js":25,"../frame.js":28,"../media-frame.js":34,"../modal.js":37}],30:[function(require,module,exports){ /*globals _, Backbone, wp, jQuery */ /** @@ -5093,7 +3980,7 @@ Manage = MediaFrame.extend({ }); module.exports = Manage; -},{"../../controllers/library.js":3,"../../routers/manage.js":12,"../attachments/browser.js":24,"../media-frame.js":38,"../uploader/window.js":54}],35:[function(require,module,exports){ +},{"../../controllers/library.js":3,"../../routers/manage.js":8,"../attachments/browser.js":20,"../media-frame.js":34,"../uploader/window.js":50}],31:[function(require,module,exports){ /** * wp.media.view.Iframe * @@ -5119,7 +4006,7 @@ Iframe = View.extend({ }); module.exports = Iframe; -},{"./view.js":55}],36:[function(require,module,exports){ +},{"./view.js":51}],32:[function(require,module,exports){ /** * @class * @augments wp.media.View @@ -5145,7 +4032,7 @@ Label = View.extend({ }); module.exports = Label; -},{"./view.js":55}],37:[function(require,module,exports){ +},{"./view.js":51}],33:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -5297,7 +4184,7 @@ MediaDetails = AttachmentDisplay.extend({ }); module.exports = MediaDetails; -},{"./settings/attachment-display.js":47}],38:[function(require,module,exports){ +},{"./settings/attachment-display.js":43}],34:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -5552,7 +4439,7 @@ _.each(['open','close','attach','detach','escape'], function( method ) { }); module.exports = MediaFrame; -},{"./frame.js":32,"./iframe.js":35,"./menu.js":40,"./modal.js":41,"./router.js":44,"./toolbar.js":50,"./uploader/window.js":54,"./view.js":55}],39:[function(require,module,exports){ +},{"./frame.js":28,"./iframe.js":31,"./menu.js":36,"./modal.js":37,"./router.js":40,"./toolbar.js":46,"./uploader/window.js":50,"./view.js":51}],35:[function(require,module,exports){ /*globals wp, jQuery */ /** @@ -5626,7 +4513,7 @@ MenuItem = View.extend({ }); module.exports = MenuItem; -},{"./view.js":55}],40:[function(require,module,exports){ +},{"./view.js":51}],36:[function(require,module,exports){ /** * wp.media.view.Menu * @@ -5742,7 +4629,7 @@ Menu = PriorityList.extend({ }); module.exports = Menu; -},{"./menu-item.js":39,"./priority-list.js":42}],41:[function(require,module,exports){ +},{"./menu-item.js":35,"./priority-list.js":38}],37:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -5958,7 +4845,7 @@ Modal = View.extend({ }); module.exports = Modal; -},{"./focus-manager.js":31,"./view.js":55}],42:[function(require,module,exports){ +},{"./focus-manager.js":27,"./view.js":51}],38:[function(require,module,exports){ /*globals _, Backbone */ /** @@ -6059,7 +4946,7 @@ PriorityList = View.extend({ }); module.exports = PriorityList; -},{"./view.js":55}],43:[function(require,module,exports){ +},{"./view.js":51}],39:[function(require,module,exports){ /** * wp.media.view.RouterItem * @@ -6085,7 +4972,7 @@ RouterItem = MenuItem.extend({ }); module.exports = RouterItem; -},{"./menu-item.js":39}],44:[function(require,module,exports){ +},{"./menu-item.js":35}],40:[function(require,module,exports){ /** * wp.media.view.Router * @@ -6122,7 +5009,7 @@ Router = Menu.extend({ }); module.exports = Router; -},{"./menu.js":40,"./router-item.js":43}],45:[function(require,module,exports){ +},{"./menu.js":36,"./router-item.js":39}],41:[function(require,module,exports){ /*globals wp */ /** @@ -6172,7 +5059,7 @@ Search = View.extend({ }); module.exports = Search; -},{"./view.js":55}],46:[function(require,module,exports){ +},{"./view.js":51}],42:[function(require,module,exports){ /*globals _, Backbone, jQuery */ /** @@ -6294,7 +5181,7 @@ Settings = View.extend({ }); module.exports = Settings; -},{"./view.js":55}],47:[function(require,module,exports){ +},{"./view.js":51}],43:[function(require,module,exports){ /*globals _, wp */ /** @@ -6389,7 +5276,7 @@ AttachmentDisplay = Settings.extend({ }); module.exports = AttachmentDisplay; -},{"../settings.js":46}],48:[function(require,module,exports){ +},{"../settings.js":42}],44:[function(require,module,exports){ /** * wp.media.view.Sidebar * @@ -6407,7 +5294,7 @@ Sidebar = PriorityList.extend({ }); module.exports = Sidebar; -},{"./priority-list.js":42}],49:[function(require,module,exports){ +},{"./priority-list.js":38}],45:[function(require,module,exports){ /*globals _, wp */ /** @@ -6446,7 +5333,7 @@ Spinner = View.extend({ }); module.exports = Spinner; -},{"./view.js":55}],50:[function(require,module,exports){ +},{"./view.js":51}],46:[function(require,module,exports){ /*globals Backbone, _ */ /** @@ -6609,7 +5496,7 @@ Toolbar = View.extend({ }); module.exports = Toolbar; -},{"./button.js":25,"./priority-list.js":42,"./view.js":55}],51:[function(require,module,exports){ +},{"./button.js":21,"./priority-list.js":38,"./view.js":51}],47:[function(require,module,exports){ /*globals _, wp */ /** @@ -6742,7 +5629,7 @@ UploaderInline = View.extend({ }); module.exports = UploaderInline; -},{"../view.js":55,"./status.js":53}],52:[function(require,module,exports){ +},{"../view.js":51,"./status.js":49}],48:[function(require,module,exports){ /*globals wp */ /** @@ -6762,7 +5649,7 @@ UploaderStatusError = View.extend({ }); module.exports = UploaderStatusError; -},{"../view.js":55}],53:[function(require,module,exports){ +},{"../view.js":51}],49:[function(require,module,exports){ /*globals _, wp */ /** @@ -6902,7 +5789,7 @@ UploaderStatus = View.extend({ }); module.exports = UploaderStatus; -},{"../view.js":55,"./status-error.js":52}],54:[function(require,module,exports){ +},{"../view.js":51,"./status-error.js":48}],50:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -7015,7 +5902,7 @@ UploaderWindow = View.extend({ }); module.exports = UploaderWindow; -},{"../view.js":55}],55:[function(require,module,exports){ +},{"../view.js":51}],51:[function(require,module,exports){ /*globals wp */ /** diff --git a/src/wp-includes/js/media/views.js b/src/wp-includes/js/media/views.js index 5e3212d16f..1f04776e2d 100644 --- a/src/wp-includes/js/media/views.js +++ b/src/wp-includes/js/media/views.js @@ -34,7 +34,7 @@ * @param {string} attributes.type The collection's media type. (e.g. 'video'). * @param {string} attributes.collectionType The collection type. (e.g. 'playlist'). */ -var Selection = require( '../models/selection.js' ), +var Selection = wp.media.model.Selection, Library = require( './library.js' ), CollectionAdd; @@ -100,7 +100,7 @@ CollectionAdd = Library.extend({ }); module.exports = CollectionAdd; -},{"../models/selection.js":20,"./library.js":10}],2:[function(require,module,exports){ +},{"./library.js":10}],2:[function(require,module,exports){ /*globals wp, jQuery, Backbone */ /** @@ -137,8 +137,7 @@ module.exports = CollectionAdd; * @param {string} attributes.type The collection's media type. (e.g. 'video'). * @param {string} attributes.collectionType The collection type. (e.g. 'playlist'). */ -var Selection = require( '../models/selection.js' ), - Library = require( './library.js' ), +var Library = require( './library.js' ), View = require( '../views/view.js' ), EditLibraryView = require( '../views/attachment/edit-library.js' ), l10n = wp.media.view.l10n, @@ -175,7 +174,7 @@ CollectionEdit = Library.extend({ // If we haven't been provided a `library`, create a `Selection`. if ( ! this.get('library') ) { - this.set( 'library', new Selection() ); + this.set( 'library', new wp.media.model.Selection() ); } // The single `Attachment` view to be used in the `Attachments` view. if ( ! this.get('AttachmentView') ) { @@ -264,7 +263,7 @@ CollectionEdit = Library.extend({ }); module.exports = CollectionEdit; -},{"../models/selection.js":20,"../views/attachment/edit-library.js":30,"../views/view.js":76,"./library.js":10}],3:[function(require,module,exports){ +},{"../views/attachment/edit-library.js":25,"../views/view.js":71,"./library.js":10}],3:[function(require,module,exports){ /*globals _, wp, Backbone */ /** @@ -382,7 +381,7 @@ Cropper = State.extend({ }); module.exports = Cropper; -},{"../views/cropper.js":39,"../views/toolbar.js":68,"./state.js":15}],4:[function(require,module,exports){ +},{"../views/cropper.js":34,"../views/toolbar.js":63,"./state.js":15}],4:[function(require,module,exports){ /*globals _, wp */ /** @@ -461,7 +460,7 @@ EditImage = State.extend({ }); module.exports = EditImage; -},{"../views/toolbar.js":68,"./state.js":15}],5:[function(require,module,exports){ +},{"../views/toolbar.js":63,"./state.js":15}],5:[function(require,module,exports){ /*globals _, wp, jQuery, Backbone */ /** @@ -633,7 +632,7 @@ module.exports = Embed; * @param {boolean} [attributes.contentUserSetting=true] Whether the content region's mode should be set and persisted per user. * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state. */ -var Attachment = require( '../models/attachment.js' ), +var Attachment = wp.media.model.Attachment, Library = require( './library.js' ), l10n = wp.media.view.l10n, FeaturedImage; @@ -722,7 +721,7 @@ FeaturedImage = Library.extend({ }); module.exports = FeaturedImage; -},{"../models/attachment.js":16,"./library.js":10}],7:[function(require,module,exports){ +},{"./library.js":10}],7:[function(require,module,exports){ /*globals _, wp */ /** @@ -754,7 +753,7 @@ module.exports = FeaturedImage; * @param {boolean} [attributes.syncSelection=false] Whether the Attachments selection should be persisted from the last state. * Defaults to false because for this state, because the library of the Edit Gallery state is the selection. */ -var Selection = require( '../models/selection.js' ), +var Selection = wp.media.model.Selection, Library = require( './library.js' ), l10n = wp.media.view.l10n, GalleryAdd; @@ -810,7 +809,7 @@ GalleryAdd = Library.extend({ }); module.exports = GalleryAdd; -},{"../models/selection.js":20,"./library.js":10}],8:[function(require,module,exports){ +},{"./library.js":10}],8:[function(require,module,exports){ /*globals wp, Backbone */ /** @@ -844,8 +843,7 @@ module.exports = GalleryAdd; * @param {view} [attributes.AttachmentView] The single `Attachment` view to be used in the `Attachments`. * If none supplied, defaults to wp.media.view.Attachment.EditLibrary. */ -var Selection = require( '../models/selection.js' ), - Library = require( './library.js' ), +var Library = require( './library.js' ), EditLibraryView = require( '../views/attachment/edit-library.js' ), GallerySettingsView = require( '../views/settings/gallery.js' ), l10n = wp.media.view.l10n, @@ -876,7 +874,7 @@ GalleryEdit = Library.extend({ initialize: function() { // If we haven't been provided a `library`, create a `Selection`. if ( ! this.get('library') ) - this.set( 'library', new Selection() ); + this.set( 'library', new wp.media.model.Selection() ); // The single `Attachment` view to be used in the `Attachments` view. if ( ! this.get('AttachmentView') ) @@ -951,7 +949,7 @@ GalleryEdit = Library.extend({ }); module.exports = GalleryEdit; -},{"../models/selection.js":20,"../views/attachment/edit-library.js":30,"../views/settings/gallery.js":64,"./library.js":10}],9:[function(require,module,exports){ +},{"../views/attachment/edit-library.js":25,"../views/settings/gallery.js":59,"./library.js":10}],9:[function(require,module,exports){ /*globals _, wp */ /** @@ -1052,7 +1050,6 @@ module.exports = ImageDetails; * @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; @@ -1097,7 +1094,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 }) ); @@ -1288,7 +1285,7 @@ Library = State.extend({ _.extend( Library.prototype, selectionSync ); module.exports = Library; -},{"../models/selection.js":20,"../utils/selection-sync.js":21,"./state.js":15}],11:[function(require,module,exports){ +},{"../utils/selection-sync.js":16,"./state.js":15}],11:[function(require,module,exports){ /*globals _, wp */ /** @@ -1996,1275 +1993,6 @@ _.each(['toolbar','content'], function( region ) { module.exports = State; },{}],16:[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":17}],17:[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":16,"./query.js":19}],18:[function(require,module,exports){ -/*globals jQuery, Backbone */ - -/** - * wp.media.model.PostImage - * - * An instance of an image that's been embedded into a post. - * - * Used in the embedded image attachment display settings modal - @see wp.media.view.MediaFrame.ImageDetails. - * - * @class - * @augments Backbone.Model - * - * @param {int} [attributes] Initial model attributes. - * @param {int} [attributes.attachment_id] ID of the attachment. - **/ -var Attachment = require( './attachment' ), - PostImage; - -PostImage = Backbone.Model.extend({ - - initialize: function( attributes ) { - this.attachment = false; - - if ( attributes.attachment_id ) { - this.attachment = Attachment.get( attributes.attachment_id ); - if ( this.attachment.get( 'url' ) ) { - this.dfd = jQuery.Deferred(); - this.dfd.resolve(); - } else { - this.dfd = this.attachment.fetch(); - } - this.bindAttachmentListeners(); - } - - // keep url in sync with changes to the type of link - this.on( 'change:link', this.updateLinkUrl, this ); - this.on( 'change:size', this.updateSize, this ); - - this.setLinkTypeFromUrl(); - this.setAspectRatio(); - - this.set( 'originalUrl', attributes.url ); - }, - - bindAttachmentListeners: function() { - this.listenTo( this.attachment, 'sync', this.setLinkTypeFromUrl ); - this.listenTo( this.attachment, 'sync', this.setAspectRatio ); - this.listenTo( this.attachment, 'change', this.updateSize ); - }, - - changeAttachment: function( attachment, props ) { - this.stopListening( this.attachment ); - this.attachment = attachment; - this.bindAttachmentListeners(); - - this.set( 'attachment_id', this.attachment.get( 'id' ) ); - this.set( 'caption', this.attachment.get( 'caption' ) ); - this.set( 'alt', this.attachment.get( 'alt' ) ); - this.set( 'size', props.get( 'size' ) ); - this.set( 'align', props.get( 'align' ) ); - this.set( 'link', props.get( 'link' ) ); - this.updateLinkUrl(); - this.updateSize(); - }, - - setLinkTypeFromUrl: function() { - var linkUrl = this.get( 'linkUrl' ), - type; - - if ( ! linkUrl ) { - this.set( 'link', 'none' ); - return; - } - - // default to custom if there is a linkUrl - type = 'custom'; - - if ( this.attachment ) { - if ( this.attachment.get( 'url' ) === linkUrl ) { - type = 'file'; - } else if ( this.attachment.get( 'link' ) === linkUrl ) { - type = 'post'; - } - } else { - if ( this.get( 'url' ) === linkUrl ) { - type = 'file'; - } - } - - this.set( 'link', type ); - }, - - updateLinkUrl: function() { - var link = this.get( 'link' ), - url; - - switch( link ) { - case 'file': - if ( this.attachment ) { - url = this.attachment.get( 'url' ); - } else { - url = this.get( 'url' ); - } - this.set( 'linkUrl', url ); - break; - case 'post': - this.set( 'linkUrl', this.attachment.get( 'link' ) ); - break; - case 'none': - this.set( 'linkUrl', '' ); - break; - } - }, - - updateSize: function() { - var size; - - if ( ! this.attachment ) { - return; - } - - if ( this.get( 'size' ) === 'custom' ) { - this.set( 'width', this.get( 'customWidth' ) ); - this.set( 'height', this.get( 'customHeight' ) ); - this.set( 'url', this.get( 'originalUrl' ) ); - return; - } - - size = this.attachment.get( 'sizes' )[ this.get( 'size' ) ]; - - if ( ! size ) { - return; - } - - this.set( 'url', size.url ); - this.set( 'width', size.width ); - this.set( 'height', size.height ); - }, - - setAspectRatio: function() { - var full; - - if ( this.attachment && this.attachment.get( 'sizes' ) ) { - full = this.attachment.get( 'sizes' ).full; - - if ( full ) { - this.set( 'aspectRatio', full.width / full.height ); - return; - } - } - - this.set( 'aspectRatio', this.get( 'customWidth' ) / this.get( 'customHeight' ) ); - } -}); - -module.exports = PostImage; -},{"./attachment":16}],19:[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":17}],20:[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":17}],21:[function(require,module,exports){ /*globals _ */ /** @@ -3331,7 +2059,7 @@ var selectionSync = { }; module.exports = selectionSync; -},{}],22:[function(require,module,exports){ +},{}],17:[function(require,module,exports){ /* global _wpMediaViewsL10n, confirm, getUserSetting, setUserSetting */ ( function( $, _ ) { var l10n, @@ -3480,7 +2208,7 @@ module.exports = selectionSync; media.view.Spinner = require( './views/spinner.js' ); }(jQuery, _)); -},{"./controllers/collection-add.js":1,"./controllers/collection-edit.js":2,"./controllers/cropper.js":3,"./controllers/edit-image.js":4,"./controllers/embed.js":5,"./controllers/featured-image.js":6,"./controllers/gallery-add.js":7,"./controllers/gallery-edit.js":8,"./controllers/image-details.js":9,"./controllers/library.js":10,"./controllers/media-library.js":11,"./controllers/region.js":12,"./controllers/replace-image.js":13,"./controllers/state-machine.js":14,"./controllers/state.js":15,"./utils/selection-sync.js":21,"./views/attachment-compat.js":23,"./views/attachment-filters.js":24,"./views/attachment-filters/all.js":25,"./views/attachment-filters/date.js":26,"./views/attachment-filters/uploaded.js":27,"./views/attachment.js":28,"./views/attachment/details.js":29,"./views/attachment/edit-library.js":30,"./views/attachment/edit-selection.js":31,"./views/attachment/library.js":32,"./views/attachment/selection.js":33,"./views/attachments.js":34,"./views/attachments/browser.js":35,"./views/attachments/selection.js":36,"./views/button-group.js":37,"./views/button.js":38,"./views/cropper.js":39,"./views/edit-image.js":40,"./views/embed.js":41,"./views/embed/image.js":42,"./views/embed/link.js":43,"./views/embed/url.js":44,"./views/focus-manager.js":45,"./views/frame/image-details.js":47,"./views/frame/post.js":48,"./views/frame/select.js":49,"./views/iframe.js":50,"./views/image-details.js":51,"./views/label.js":52,"./views/media-frame.js":53,"./views/menu-item.js":54,"./views/menu.js":55,"./views/modal.js":56,"./views/priority-list.js":57,"./views/router-item.js":58,"./views/router.js":59,"./views/search.js":60,"./views/selection.js":61,"./views/settings.js":62,"./views/settings/attachment-display.js":63,"./views/settings/gallery.js":64,"./views/settings/playlist.js":65,"./views/sidebar.js":66,"./views/spinner.js":67,"./views/toolbar.js":68,"./views/toolbar/embed.js":69,"./views/toolbar/select.js":70,"./views/uploader/editor.js":71,"./views/uploader/inline.js":72,"./views/uploader/status-error.js":73,"./views/uploader/status.js":74,"./views/uploader/window.js":75,"./views/view.js":76}],23:[function(require,module,exports){ +},{"./controllers/collection-add.js":1,"./controllers/collection-edit.js":2,"./controllers/cropper.js":3,"./controllers/edit-image.js":4,"./controllers/embed.js":5,"./controllers/featured-image.js":6,"./controllers/gallery-add.js":7,"./controllers/gallery-edit.js":8,"./controllers/image-details.js":9,"./controllers/library.js":10,"./controllers/media-library.js":11,"./controllers/region.js":12,"./controllers/replace-image.js":13,"./controllers/state-machine.js":14,"./controllers/state.js":15,"./utils/selection-sync.js":16,"./views/attachment-compat.js":18,"./views/attachment-filters.js":19,"./views/attachment-filters/all.js":20,"./views/attachment-filters/date.js":21,"./views/attachment-filters/uploaded.js":22,"./views/attachment.js":23,"./views/attachment/details.js":24,"./views/attachment/edit-library.js":25,"./views/attachment/edit-selection.js":26,"./views/attachment/library.js":27,"./views/attachment/selection.js":28,"./views/attachments.js":29,"./views/attachments/browser.js":30,"./views/attachments/selection.js":31,"./views/button-group.js":32,"./views/button.js":33,"./views/cropper.js":34,"./views/edit-image.js":35,"./views/embed.js":36,"./views/embed/image.js":37,"./views/embed/link.js":38,"./views/embed/url.js":39,"./views/focus-manager.js":40,"./views/frame/image-details.js":42,"./views/frame/post.js":43,"./views/frame/select.js":44,"./views/iframe.js":45,"./views/image-details.js":46,"./views/label.js":47,"./views/media-frame.js":48,"./views/menu-item.js":49,"./views/menu.js":50,"./views/modal.js":51,"./views/priority-list.js":52,"./views/router-item.js":53,"./views/router.js":54,"./views/search.js":55,"./views/selection.js":56,"./views/settings.js":57,"./views/settings/attachment-display.js":58,"./views/settings/gallery.js":59,"./views/settings/playlist.js":60,"./views/sidebar.js":61,"./views/spinner.js":62,"./views/toolbar.js":63,"./views/toolbar/embed.js":64,"./views/toolbar/select.js":65,"./views/uploader/editor.js":66,"./views/uploader/inline.js":67,"./views/uploader/status-error.js":68,"./views/uploader/status.js":69,"./views/uploader/window.js":70,"./views/view.js":71}],18:[function(require,module,exports){ /*globals _ */ /** @@ -3566,7 +2294,7 @@ AttachmentCompat = View.extend({ }); module.exports = AttachmentCompat; -},{"./view.js":76}],24:[function(require,module,exports){ +},{"./view.js":71}],19:[function(require,module,exports){ /*globals _, jQuery */ /** @@ -3645,7 +2373,7 @@ AttachmentFilters = View.extend({ }); module.exports = AttachmentFilters; -},{"./view.js":76}],25:[function(require,module,exports){ +},{"./view.js":71}],20:[function(require,module,exports){ /*globals _, wp */ /** @@ -3737,7 +2465,7 @@ All = AttachmentFilters.extend({ }); module.exports = All; -},{"../attachment-filters.js":24}],26:[function(require,module,exports){ +},{"../attachment-filters.js":19}],21:[function(require,module,exports){ /*globals _, wp */ /** @@ -3780,7 +2508,7 @@ DateFilter = AttachmentFilters.extend({ }); module.exports = DateFilter; -},{"../attachment-filters.js":24}],27:[function(require,module,exports){ +},{"../attachment-filters.js":19}],22:[function(require,module,exports){ /*globals wp */ /** @@ -3841,7 +2569,7 @@ Uploaded = AttachmentFilters.extend({ }); module.exports = Uploaded; -},{"../attachment-filters.js":24}],28:[function(require,module,exports){ +},{"../attachment-filters.js":19}],23:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -4396,7 +3124,7 @@ _.each({ }); module.exports = Attachment; -},{"./view.js":76}],29:[function(require,module,exports){ +},{"./view.js":71}],24:[function(require,module,exports){ /*globals _, wp */ /** @@ -4537,7 +3265,7 @@ Details = Attachment.extend({ }); module.exports = Details; -},{"../attachment.js":28}],30:[function(require,module,exports){ +},{"../attachment.js":23}],25:[function(require,module,exports){ /** * wp.media.view.Attachment.EditLibrary * @@ -4557,7 +3285,7 @@ EditLibrary = Attachment.extend({ }); module.exports = EditLibrary; -},{"../attachment.js":28}],31:[function(require,module,exports){ +},{"../attachment.js":23}],26:[function(require,module,exports){ /** * wp.media.view.Attachments.EditSelection * @@ -4578,7 +3306,7 @@ EditSelection = Selection.extend({ }); module.exports = EditSelection; -},{"./selection.js":33}],32:[function(require,module,exports){ +},{"./selection.js":28}],27:[function(require,module,exports){ /** * wp.media.view.Attachment.Library * @@ -4598,7 +3326,7 @@ Library = Attachment.extend({ }); module.exports = Library; -},{"../attachment.js":28}],33:[function(require,module,exports){ +},{"../attachment.js":23}],28:[function(require,module,exports){ /** * wp.media.view.Attachment.Selection * @@ -4622,7 +3350,7 @@ Selection = Attachment.extend({ }); module.exports = Selection; -},{"../attachment.js":28}],34:[function(require,module,exports){ +},{"../attachment.js":23}],29:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -4923,7 +3651,7 @@ Attachments = View.extend({ }); module.exports = Attachments; -},{"./attachment.js":28,"./view.js":76}],35:[function(require,module,exports){ +},{"./attachment.js":23,"./view.js":71}],30:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -5383,7 +4111,7 @@ AttachmentsBrowser = View.extend({ }); module.exports = AttachmentsBrowser; -},{"../attachment-compat.js":23,"../attachment-filters/all.js":25,"../attachment-filters/date.js":26,"../attachment-filters/uploaded.js":27,"../attachment/details.js":29,"../attachment/library.js":32,"../attachments.js":34,"../label.js":52,"../search.js":60,"../settings/attachment-display.js":63,"../sidebar.js":66,"../spinner.js":67,"../toolbar.js":68,"../uploader/inline.js":72,"../uploader/status.js":74,"../view.js":76}],36:[function(require,module,exports){ +},{"../attachment-compat.js":18,"../attachment-filters/all.js":20,"../attachment-filters/date.js":21,"../attachment-filters/uploaded.js":22,"../attachment/details.js":24,"../attachment/library.js":27,"../attachments.js":29,"../label.js":47,"../search.js":55,"../settings/attachment-display.js":58,"../sidebar.js":61,"../spinner.js":62,"../toolbar.js":63,"../uploader/inline.js":67,"../uploader/status.js":69,"../view.js":71}],31:[function(require,module,exports){ /*globals _ */ /** @@ -5415,7 +4143,7 @@ Selection = Attachments.extend({ }); module.exports = Selection; -},{"../attachment/selection.js":33,"../attachments.js":34}],37:[function(require,module,exports){ +},{"../attachment/selection.js":28,"../attachments.js":29}],32:[function(require,module,exports){ /*globals _, Backbone, jQuery */ /** @@ -5464,7 +4192,7 @@ ButtonGroup = View.extend({ }); module.exports = ButtonGroup; -},{"./button.js":38,"./view.js":76}],38:[function(require,module,exports){ +},{"./button.js":33,"./view.js":71}],33:[function(require,module,exports){ /*globals _, Backbone */ /** @@ -5554,7 +4282,7 @@ Button = View.extend({ }); module.exports = Button; -},{"./view.js":76}],39:[function(require,module,exports){ +},{"./view.js":71}],34:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -5623,7 +4351,7 @@ Cropper = View.extend({ }); module.exports = Cropper; -},{"./uploader/status-error.js":73,"./uploader/status.js":74,"./view.js":76}],40:[function(require,module,exports){ +},{"./uploader/status-error.js":68,"./uploader/status.js":69,"./view.js":71}],35:[function(require,module,exports){ /*globals _, wp */ var View = require( './view.js' ), @@ -5678,7 +4406,7 @@ EditImage = View.extend({ }); module.exports = EditImage; -},{"./view.js":76}],41:[function(require,module,exports){ +},{"./view.js":71}],36:[function(require,module,exports){ /** * wp.media.view.Embed * @@ -5747,7 +4475,7 @@ Embed = View.extend({ }); module.exports = Embed; -},{"./embed/image.js":42,"./embed/link.js":43,"./embed/url.js":44,"./view.js":76}],42:[function(require,module,exports){ +},{"./embed/image.js":37,"./embed/link.js":38,"./embed/url.js":39,"./view.js":71}],37:[function(require,module,exports){ /*globals wp */ /** @@ -5781,7 +4509,7 @@ EmbedImage = AttachmentDisplay.extend({ }); module.exports = EmbedImage; -},{"../settings/attachment-display.js":63}],43:[function(require,module,exports){ +},{"../settings/attachment-display.js":58}],38:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -5849,7 +4577,7 @@ EmbedLink = Settings.extend({ }); module.exports = EmbedLink; -},{"../settings.js":62}],44:[function(require,module,exports){ +},{"../settings.js":57}],39:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -5931,7 +4659,7 @@ EmbedUrl = View.extend({ }); module.exports = EmbedUrl; -},{"../view.js":76}],45:[function(require,module,exports){ +},{"../view.js":71}],40:[function(require,module,exports){ /** * wp.media.view.FocusManager * @@ -5979,7 +4707,7 @@ FocusManager = View.extend({ }); module.exports = FocusManager; -},{"./view.js":76}],46:[function(require,module,exports){ +},{"./view.js":71}],41:[function(require,module,exports){ /*globals _, Backbone */ /** @@ -6152,7 +4880,7 @@ Frame = View.extend({ _.extend( Frame.prototype, StateMachine.prototype ); module.exports = Frame; -},{"../controllers/region.js":12,"../controllers/state-machine.js":14,"../controllers/state.js":15,"./view.js":76}],47:[function(require,module,exports){ +},{"../controllers/region.js":12,"../controllers/state-machine.js":14,"../controllers/state.js":15,"./view.js":71}],42:[function(require,module,exports){ /*globals wp */ /** @@ -6172,8 +4900,6 @@ module.exports = Frame; */ var Select = require( './select.js' ), Toolbar = require( '../toolbar.js' ), - PostImage = require( '../../models/post-image.js' ), - Selection = require( '../../models/selection.js' ), ImageDetailsController = require( '../../controllers/image-details.js' ), ReplaceImageController = require( '../../controllers/replace-image.js' ), EditImageController = require( '../../controllers/edit-image.js' ), @@ -6195,8 +4921,8 @@ ImageDetails = Select.extend({ }, initialize: function( options ) { - this.image = new PostImage( options.metadata ); - this.options.selection = new Selection( this.image.attachment, { multiple: false } ); + this.image = new wp.media.model.PostImage( options.metadata ); + this.options.selection = new wp.media.model.Selection( this.image.attachment, { multiple: false } ); Select.prototype.initialize.apply( this, arguments ); }, @@ -6338,7 +5064,7 @@ ImageDetails = Select.extend({ }); module.exports = ImageDetails; -},{"../../controllers/edit-image.js":4,"../../controllers/image-details.js":9,"../../controllers/replace-image.js":13,"../../models/post-image.js":18,"../../models/selection.js":20,"../edit-image.js":40,"../image-details.js":51,"../toolbar.js":68,"./select.js":49}],48:[function(require,module,exports){ +},{"../../controllers/edit-image.js":4,"../../controllers/image-details.js":9,"../../controllers/replace-image.js":13,"../edit-image.js":35,"../image-details.js":46,"../toolbar.js":63,"./select.js":44}],43:[function(require,module,exports){ /*globals _, wp */ /** @@ -6365,7 +5091,6 @@ var View = require( '../view.js' ), ToolbarEmbed = require( '../toolbar/embed.js' ), PlaylistSettings = require( '../settings/playlist.js' ), AttachmentsBrowser = require( '../attachments/browser.js' ), - SelectionModel = require( '../../models/selection.js' ), SelectionView = require( '../selection.js' ), EmbedController = require( '../../controllers/embed.js' ), EditImageController = require( '../../controllers/edit-image.js' ), @@ -6834,7 +5559,7 @@ Post = Select.extend({ edit = controller.state('gallery-edit'), models = selection.where({ type: 'image' }); - edit.set( 'library', new SelectionModel( models, { + edit.set( 'library', new wp.media.model.Selection( models, { props: selection.props.toJSON(), multiple: true }) ); @@ -6864,7 +5589,7 @@ Post = Select.extend({ edit = controller.state('playlist-edit'), models = selection.where({ type: 'audio' }); - edit.set( 'library', new SelectionModel( models, { + edit.set( 'library', new wp.media.model.Selection( models, { props: selection.props.toJSON(), multiple: true }) ); @@ -6894,7 +5619,7 @@ Post = Select.extend({ edit = controller.state('video-playlist-edit'), models = selection.where({ type: 'video' }); - edit.set( 'library', new SelectionModel( models, { + edit.set( 'library', new wp.media.model.Selection( models, { props: selection.props.toJSON(), multiple: true }) ); @@ -7091,7 +5816,7 @@ Post = Select.extend({ }); module.exports = Post; -},{"../../controllers/collection-add.js":1,"../../controllers/collection-edit.js":2,"../../controllers/edit-image.js":4,"../../controllers/embed.js":5,"../../controllers/featured-image.js":6,"../../controllers/gallery-add.js":7,"../../controllers/gallery-edit.js":8,"../../controllers/library.js":10,"../../models/selection.js":20,"../attachment/edit-selection.js":31,"../attachments/browser.js":35,"../edit-image.js":40,"../embed.js":41,"../selection.js":61,"../settings/playlist.js":65,"../toolbar.js":68,"../toolbar/embed.js":69,"../view.js":76,"./select.js":49}],49:[function(require,module,exports){ +},{"../../controllers/collection-add.js":1,"../../controllers/collection-edit.js":2,"../../controllers/edit-image.js":4,"../../controllers/embed.js":5,"../../controllers/featured-image.js":6,"../../controllers/gallery-add.js":7,"../../controllers/gallery-edit.js":8,"../../controllers/library.js":10,"../attachment/edit-selection.js":26,"../attachments/browser.js":30,"../edit-image.js":35,"../embed.js":36,"../selection.js":56,"../settings/playlist.js":60,"../toolbar.js":63,"../toolbar/embed.js":64,"../view.js":71,"./select.js":44}],44:[function(require,module,exports){ /*globals _, wp */ /** @@ -7110,8 +5835,6 @@ module.exports = Post; 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' ), @@ -7147,14 +5870,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: [] }; }, @@ -7268,7 +5991,7 @@ Select = MediaFrame.extend({ }); module.exports = Select; -},{"../../controllers/library.js":10,"../../models/attachments.js":17,"../../models/selection.js":20,"../attachments/browser.js":35,"../media-frame.js":53,"../toolbar/select.js":70,"../uploader/inline.js":72}],50:[function(require,module,exports){ +},{"../../controllers/library.js":10,"../attachments/browser.js":30,"../media-frame.js":48,"../toolbar/select.js":65,"../uploader/inline.js":67}],45:[function(require,module,exports){ /** * wp.media.view.Iframe * @@ -7294,7 +6017,7 @@ Iframe = View.extend({ }); module.exports = Iframe; -},{"./view.js":76}],51:[function(require,module,exports){ +},{"./view.js":71}],46:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -7462,7 +6185,7 @@ ImageDetails = AttachmentDisplay.extend({ }); module.exports = AttachmentDisplay; -},{"./settings/attachment-display.js":63}],52:[function(require,module,exports){ +},{"./settings/attachment-display.js":58}],47:[function(require,module,exports){ /** * @class * @augments wp.media.View @@ -7488,7 +6211,7 @@ Label = View.extend({ }); module.exports = Label; -},{"./view.js":76}],53:[function(require,module,exports){ +},{"./view.js":71}],48:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -7743,7 +6466,7 @@ _.each(['open','close','attach','detach','escape'], function( method ) { }); module.exports = MediaFrame; -},{"./frame.js":46,"./iframe.js":50,"./menu.js":55,"./modal.js":56,"./router.js":59,"./toolbar.js":68,"./uploader/window.js":75,"./view.js":76}],54:[function(require,module,exports){ +},{"./frame.js":41,"./iframe.js":45,"./menu.js":50,"./modal.js":51,"./router.js":54,"./toolbar.js":63,"./uploader/window.js":70,"./view.js":71}],49:[function(require,module,exports){ /*globals wp, jQuery */ /** @@ -7817,7 +6540,7 @@ MenuItem = View.extend({ }); module.exports = MenuItem; -},{"./view.js":76}],55:[function(require,module,exports){ +},{"./view.js":71}],50:[function(require,module,exports){ /** * wp.media.view.Menu * @@ -7933,7 +6656,7 @@ Menu = PriorityList.extend({ }); module.exports = Menu; -},{"./menu-item.js":54,"./priority-list.js":57}],56:[function(require,module,exports){ +},{"./menu-item.js":49,"./priority-list.js":52}],51:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -8149,7 +6872,7 @@ Modal = View.extend({ }); module.exports = Modal; -},{"./focus-manager.js":45,"./view.js":76}],57:[function(require,module,exports){ +},{"./focus-manager.js":40,"./view.js":71}],52:[function(require,module,exports){ /*globals _, Backbone */ /** @@ -8250,7 +6973,7 @@ PriorityList = View.extend({ }); module.exports = PriorityList; -},{"./view.js":76}],58:[function(require,module,exports){ +},{"./view.js":71}],53:[function(require,module,exports){ /** * wp.media.view.RouterItem * @@ -8276,7 +6999,7 @@ RouterItem = MenuItem.extend({ }); module.exports = RouterItem; -},{"./menu-item.js":54}],59:[function(require,module,exports){ +},{"./menu-item.js":49}],54:[function(require,module,exports){ /** * wp.media.view.Router * @@ -8313,7 +7036,7 @@ Router = Menu.extend({ }); module.exports = Router; -},{"./menu.js":55,"./router-item.js":58}],60:[function(require,module,exports){ +},{"./menu.js":50,"./router-item.js":53}],55:[function(require,module,exports){ /*globals wp */ /** @@ -8363,7 +7086,7 @@ Search = View.extend({ }); module.exports = Search; -},{"./view.js":76}],61:[function(require,module,exports){ +},{"./view.js":71}],56:[function(require,module,exports){ /*globals _, Backbone, wp */ /** @@ -8449,7 +7172,7 @@ Selection = View.extend({ }); module.exports = Selection; -},{"./attachments/selection.js":36,"./view.js":76}],62:[function(require,module,exports){ +},{"./attachments/selection.js":31,"./view.js":71}],57:[function(require,module,exports){ /*globals _, Backbone, jQuery */ /** @@ -8571,7 +7294,7 @@ Settings = View.extend({ }); module.exports = Settings; -},{"./view.js":76}],63:[function(require,module,exports){ +},{"./view.js":71}],58:[function(require,module,exports){ /*globals _, wp */ /** @@ -8666,7 +7389,7 @@ AttachmentDisplay = Settings.extend({ }); module.exports = AttachmentDisplay; -},{"../settings.js":62}],64:[function(require,module,exports){ +},{"../settings.js":57}],59:[function(require,module,exports){ /*globals wp */ /** @@ -8687,7 +7410,7 @@ Gallery = Settings.extend({ }); module.exports = Gallery; -},{"../settings.js":62}],65:[function(require,module,exports){ +},{"../settings.js":57}],60:[function(require,module,exports){ /*globals wp */ /** @@ -8708,7 +7431,7 @@ Playlist = Settings.extend({ }); module.exports = Playlist; -},{"../settings.js":62}],66:[function(require,module,exports){ +},{"../settings.js":57}],61:[function(require,module,exports){ /** * wp.media.view.Sidebar * @@ -8726,7 +7449,7 @@ Sidebar = PriorityList.extend({ }); module.exports = Sidebar; -},{"./priority-list.js":57}],67:[function(require,module,exports){ +},{"./priority-list.js":52}],62:[function(require,module,exports){ /*globals _, wp */ /** @@ -8765,7 +7488,7 @@ Spinner = View.extend({ }); module.exports = Spinner; -},{"./view.js":76}],68:[function(require,module,exports){ +},{"./view.js":71}],63:[function(require,module,exports){ /*globals Backbone, _ */ /** @@ -8928,7 +7651,7 @@ Toolbar = View.extend({ }); module.exports = Toolbar; -},{"./button.js":38,"./priority-list.js":57,"./view.js":76}],69:[function(require,module,exports){ +},{"./button.js":33,"./priority-list.js":52,"./view.js":71}],64:[function(require,module,exports){ /*globals _, wp */ /** @@ -8966,7 +7689,7 @@ Embed = Select.extend({ }); module.exports = Embed; -},{"./select.js":70}],70:[function(require,module,exports){ +},{"./select.js":65}],65:[function(require,module,exports){ /*globals _, wp */ /** @@ -9037,7 +7760,7 @@ Select = Toolbar.extend({ }); module.exports = Select; -},{"../toolbar.js":68}],71:[function(require,module,exports){ +},{"../toolbar.js":63}],66:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -9259,7 +7982,7 @@ EditorUploader = View.extend({ }); module.exports = EditorUploader; -},{"../view.js":76}],72:[function(require,module,exports){ +},{"../view.js":71}],67:[function(require,module,exports){ /*globals _, wp */ /** @@ -9392,7 +8115,7 @@ UploaderInline = View.extend({ }); module.exports = UploaderInline; -},{"../view.js":76,"./status.js":74}],73:[function(require,module,exports){ +},{"../view.js":71,"./status.js":69}],68:[function(require,module,exports){ /*globals wp */ /** @@ -9412,7 +8135,7 @@ UploaderStatusError = View.extend({ }); module.exports = UploaderStatusError; -},{"../view.js":76}],74:[function(require,module,exports){ +},{"../view.js":71}],69:[function(require,module,exports){ /*globals _, wp */ /** @@ -9552,7 +8275,7 @@ UploaderStatus = View.extend({ }); module.exports = UploaderStatus; -},{"../view.js":76,"./status-error.js":73}],75:[function(require,module,exports){ +},{"../view.js":71,"./status-error.js":68}],70:[function(require,module,exports){ /*globals _, wp, jQuery */ /** @@ -9665,7 +8388,7 @@ UploaderWindow = View.extend({ }); module.exports = UploaderWindow; -},{"../view.js":76}],76:[function(require,module,exports){ +},{"../view.js":71}],71:[function(require,module,exports){ /*globals wp */ /** @@ -9732,4 +8455,4 @@ var View = wp.Backbone.View.extend({ }); module.exports = View; -},{}]},{},[22]); +},{}]},{},[17]); diff --git a/src/wp-includes/js/media/views/frame/image-details.js b/src/wp-includes/js/media/views/frame/image-details.js index bdaf1fefd7..0f6cacf287 100644 --- a/src/wp-includes/js/media/views/frame/image-details.js +++ b/src/wp-includes/js/media/views/frame/image-details.js @@ -17,8 +17,6 @@ */ var Select = require( './select.js' ), Toolbar = require( '../toolbar.js' ), - PostImage = require( '../../models/post-image.js' ), - Selection = require( '../../models/selection.js' ), ImageDetailsController = require( '../../controllers/image-details.js' ), ReplaceImageController = require( '../../controllers/replace-image.js' ), EditImageController = require( '../../controllers/edit-image.js' ), @@ -40,8 +38,8 @@ ImageDetails = Select.extend({ }, initialize: function( options ) { - this.image = new PostImage( options.metadata ); - this.options.selection = new Selection( this.image.attachment, { multiple: false } ); + this.image = new wp.media.model.PostImage( options.metadata ); + this.options.selection = new wp.media.model.Selection( this.image.attachment, { multiple: false } ); Select.prototype.initialize.apply( this, arguments ); }, diff --git a/src/wp-includes/js/media/views/frame/media-details.js b/src/wp-includes/js/media/views/frame/media-details.js index b4d3884f48..bad99ed786 100644 --- a/src/wp-includes/js/media/views/frame/media-details.js +++ b/src/wp-includes/js/media/views/frame/media-details.js @@ -15,8 +15,6 @@ 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; @@ -36,8 +34,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 ); }, diff --git a/src/wp-includes/js/media/views/frame/post.js b/src/wp-includes/js/media/views/frame/post.js index acabf92ad4..f045703553 100644 --- a/src/wp-includes/js/media/views/frame/post.js +++ b/src/wp-includes/js/media/views/frame/post.js @@ -24,7 +24,6 @@ var View = require( '../view.js' ), ToolbarEmbed = require( '../toolbar/embed.js' ), PlaylistSettings = require( '../settings/playlist.js' ), AttachmentsBrowser = require( '../attachments/browser.js' ), - SelectionModel = require( '../../models/selection.js' ), SelectionView = require( '../selection.js' ), EmbedController = require( '../../controllers/embed.js' ), EditImageController = require( '../../controllers/edit-image.js' ), @@ -493,7 +492,7 @@ Post = Select.extend({ edit = controller.state('gallery-edit'), models = selection.where({ type: 'image' }); - edit.set( 'library', new SelectionModel( models, { + edit.set( 'library', new wp.media.model.Selection( models, { props: selection.props.toJSON(), multiple: true }) ); @@ -523,7 +522,7 @@ Post = Select.extend({ edit = controller.state('playlist-edit'), models = selection.where({ type: 'audio' }); - edit.set( 'library', new SelectionModel( models, { + edit.set( 'library', new wp.media.model.Selection( models, { props: selection.props.toJSON(), multiple: true }) ); @@ -553,7 +552,7 @@ Post = Select.extend({ edit = controller.state('video-playlist-edit'), models = selection.where({ type: 'video' }); - edit.set( 'library', new SelectionModel( models, { + edit.set( 'library', new wp.media.model.Selection( models, { props: selection.props.toJSON(), multiple: true }) ); diff --git a/src/wp-includes/js/media/views/frame/select.js b/src/wp-includes/js/media/views/frame/select.js index 7763b7e071..29d3cee8ce 100644 --- a/src/wp-includes/js/media/views/frame/select.js +++ b/src/wp-includes/js/media/views/frame/select.js @@ -16,8 +16,6 @@ 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' ), @@ -53,14 +51,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: [] }; },