2017-10-04 17:02:23 -04:00
|
|
|
/******/ (function(modules) { // webpackBootstrap
|
|
|
|
/******/ // The module cache
|
|
|
|
/******/ var installedModules = {};
|
|
|
|
/******/
|
|
|
|
/******/ // The require function
|
|
|
|
/******/ function __webpack_require__(moduleId) {
|
|
|
|
/******/
|
|
|
|
/******/ // Check if module is in cache
|
|
|
|
/******/ if(installedModules[moduleId]) {
|
|
|
|
/******/ return installedModules[moduleId].exports;
|
|
|
|
/******/ }
|
|
|
|
/******/ // Create a new module (and put it into the cache)
|
|
|
|
/******/ var module = installedModules[moduleId] = {
|
|
|
|
/******/ i: moduleId,
|
|
|
|
/******/ l: false,
|
|
|
|
/******/ exports: {}
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // Execute the module function
|
|
|
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
|
|
/******/
|
|
|
|
/******/ // Flag the module as loaded
|
|
|
|
/******/ module.l = true;
|
|
|
|
/******/
|
|
|
|
/******/ // Return the exports of the module
|
|
|
|
/******/ return module.exports;
|
|
|
|
/******/ }
|
|
|
|
/******/
|
|
|
|
/******/
|
|
|
|
/******/ // expose the modules object (__webpack_modules__)
|
|
|
|
/******/ __webpack_require__.m = modules;
|
|
|
|
/******/
|
|
|
|
/******/ // expose the module cache
|
|
|
|
/******/ __webpack_require__.c = installedModules;
|
|
|
|
/******/
|
|
|
|
/******/ // define getter function for harmony exports
|
|
|
|
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
|
|
/******/ if(!__webpack_require__.o(exports, name)) {
|
2018-12-13 06:05:25 -05:00
|
|
|
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
2017-10-04 17:02:23 -04:00
|
|
|
/******/ }
|
|
|
|
/******/ };
|
|
|
|
/******/
|
2018-12-13 06:05:25 -05:00
|
|
|
/******/ // define __esModule on exports
|
|
|
|
/******/ __webpack_require__.r = function(exports) {
|
|
|
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
|
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
|
/******/ }
|
|
|
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // create a fake namespace object
|
|
|
|
/******/ // mode & 1: value is a module id, require it
|
|
|
|
/******/ // mode & 2: merge all properties of value into the ns
|
|
|
|
/******/ // mode & 4: return value when already ns object
|
|
|
|
/******/ // mode & 8|1: behave like require
|
|
|
|
/******/ __webpack_require__.t = function(value, mode) {
|
|
|
|
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
|
|
/******/ if(mode & 8) return value;
|
|
|
|
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
|
|
/******/ var ns = Object.create(null);
|
|
|
|
/******/ __webpack_require__.r(ns);
|
|
|
|
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
|
|
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
|
|
/******/ return ns;
|
|
|
|
/******/ };
|
|
|
|
/******/
|
2017-10-04 17:02:23 -04:00
|
|
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
|
|
/******/ __webpack_require__.n = function(module) {
|
|
|
|
/******/ var getter = module && module.__esModule ?
|
|
|
|
/******/ function getDefault() { return module['default']; } :
|
|
|
|
/******/ function getModuleExports() { return module; };
|
|
|
|
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
|
|
/******/ return getter;
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // Object.prototype.hasOwnProperty.call
|
|
|
|
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
|
|
/******/
|
|
|
|
/******/ // __webpack_public_path__
|
|
|
|
/******/ __webpack_require__.p = "";
|
|
|
|
/******/
|
2018-12-13 06:05:25 -05:00
|
|
|
/******/
|
2017-10-04 17:02:23 -04:00
|
|
|
/******/ // Load entry module and return exports
|
2021-05-24 17:35:56 -04:00
|
|
|
/******/ return __webpack_require__(__webpack_require__.s = 2);
|
2017-10-04 17:02:23 -04:00
|
|
|
/******/ })
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ ({
|
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/***/ "0Ym0":
|
2017-10-04 17:02:23 -04:00
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
2018-12-13 12:27:38 -05:00
|
|
|
var $ = Backbone.$,
|
|
|
|
Attachment;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.media.model.Attachment
|
|
|
|
*
|
|
|
|
* @memberOf wp.media.model
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @augments Backbone.Model
|
|
|
|
*/
|
|
|
|
Attachment = Backbone.Model.extend(/** @lends wp.media.model.Attachment.prototype */{
|
|
|
|
/**
|
|
|
|
* Triggered when attachment details change
|
|
|
|
* Overrides Backbone.Model.sync
|
|
|
|
*
|
|
|
|
* @param {string} method
|
|
|
|
* @param {wp.media.model.Attachment} model
|
|
|
|
* @param {Object} [options={}]
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {Promise}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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 ) {
|
2020-01-27 09:44:08 -05:00
|
|
|
// If we do not have the necessary nonce, fail immediately.
|
2018-12-13 12:27:38 -05:00
|
|
|
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()
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {Object} The modified response object, which is the attributes hash
|
|
|
|
* to be set on the model.
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {Promise}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
saveCompat: function( data, options ) {
|
|
|
|
var model = this;
|
|
|
|
|
2020-01-27 09:44:08 -05:00
|
|
|
// If we do not have the necessary nonce, fail immediately.
|
2018-12-13 12:27:38 -05:00
|
|
|
if ( ! this.get('nonces') || ! this.get('nonces').update ) {
|
|
|
|
return $.Deferred().rejectWith( this ).promise();
|
|
|
|
}
|
|
|
|
|
|
|
|
return wp.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 );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},/** @lends wp.media.model.Attachment */{
|
|
|
|
/**
|
|
|
|
* Create a new model on the static 'all' attachments collection and return it.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*
|
|
|
|
* @param {Object} attrs
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {wp.media.model.Attachment}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
create: function( attrs ) {
|
|
|
|
var Attachments = wp.media.model.Attachments;
|
|
|
|
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
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {wp.media.model.Attachment}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
get: _.memoize( function( id, attachment ) {
|
|
|
|
var Attachments = wp.media.model.Attachments;
|
|
|
|
return Attachments.all.push( attachment || { id: id } );
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Attachment;
|
|
|
|
|
2015-02-08 19:43:50 -05:00
|
|
|
|
2017-10-04 17:02:23 -04:00
|
|
|
/***/ }),
|
2015-02-08 19:43:50 -05:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/***/ 2:
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
module.exports = __webpack_require__("dx5j");
|
|
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
/***/ "Io+g":
|
2017-10-04 17:02:23 -04:00
|
|
|
/***/ (function(module, exports) {
|
2015-02-08 19:43:50 -05:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
var Attachments = wp.media.model.Attachments,
|
|
|
|
Selection;
|
|
|
|
|
2018-12-13 12:27:38 -05:00
|
|
|
/**
|
2021-05-24 20:12:57 -04:00
|
|
|
* wp.media.model.Selection
|
|
|
|
*
|
|
|
|
* A selection of attachments.
|
|
|
|
*
|
|
|
|
* @memberOf wp.media.model
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @augments wp.media.model.Attachments
|
|
|
|
* @augments Backbone.Collection
|
|
|
|
*/
|
|
|
|
Selection = Attachments.extend(/** @lends wp.media.model.Selection.prototype */{
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @return {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
|
|
|
|
*
|
|
|
|
* @return {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;
|
|
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
/***/ "K0z/":
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.media.model.Attachments
|
2018-12-13 12:27:38 -05:00
|
|
|
*
|
|
|
|
* 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().
|
|
|
|
*
|
|
|
|
* @memberOf wp.media.model
|
|
|
|
*
|
|
|
|
* @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 Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachments.prototype */{
|
|
|
|
/**
|
|
|
|
* @type {wp.media.model.Attachment}
|
|
|
|
*/
|
|
|
|
model: wp.media.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
|
2020-07-27 19:35:02 -04:00
|
|
|
* @param {boolean} query
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
_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;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// If no `Attachments` model is provided to source the searches from,
|
|
|
|
// then automatically generate a source from the existing models.
|
2018-12-13 12:27:38 -05:00
|
|
|
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
|
2020-07-27 19:35:02 -04:00
|
|
|
* @return {boolean}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {wp.media.model.Attachments} Returns itself to allow chaining.
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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
|
2020-07-27 19:35:02 -04:00
|
|
|
* @param {Object} [options={}]
|
2018-12-13 12:27:38 -05:00
|
|
|
*
|
|
|
|
* @fires wp.media.model.Attachments#reset
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {wp.media.model.Attachments} Returns itself to allow chaining.
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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.
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {wp.media.model.Attachments} Returns itself to allow chaining.
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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.
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {wp.media.model.Attachments} Returns itself to allow chaining.
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {wp.media.model.Attachments} Returns itself to allow chaining.
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
_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
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {wp.media.model.Attachments} Returns itself to allow chaining.
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
_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.
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {wp.media.model.Attachments} Returns itself to allow chaining.
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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 );
|
|
|
|
|
2019-09-23 08:19:56 -04:00
|
|
|
// Used for the search results.
|
|
|
|
this.trigger( 'attachments:received', this );
|
2018-12-13 12:27:38 -05:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Stop mirroring another attachments collection.
|
|
|
|
*/
|
|
|
|
unmirror: function() {
|
|
|
|
if ( ! this.mirroring ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.unobserve( this.mirroring );
|
|
|
|
delete this.mirroring;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Retrieve 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.
|
|
|
|
*
|
2020-07-27 19:35:02 -04:00
|
|
|
* @param {Object} options
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {Promise}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
more: function( options ) {
|
|
|
|
var deferred = jQuery.Deferred(),
|
|
|
|
mirroring = this.mirroring,
|
|
|
|
attachments = this;
|
|
|
|
|
|
|
|
if ( ! mirroring || ! mirroring.more ) {
|
|
|
|
return deferred.resolveWith( this ).promise();
|
|
|
|
}
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-12-13 12:27:38 -05:00
|
|
|
mirroring.more( options ).done( function() {
|
|
|
|
if ( this === attachments.mirroring ) {
|
|
|
|
deferred.resolveWith( this );
|
|
|
|
}
|
2019-09-23 08:19:56 -04:00
|
|
|
|
|
|
|
// Used for the search results.
|
|
|
|
attachments.trigger( 'attachments:received', this );
|
2018-12-13 12:27:38 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {boolean}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
hasMore: function() {
|
|
|
|
return this.mirroring ? this.mirroring.hasMore() : false;
|
|
|
|
},
|
2021-05-07 19:19:03 -04:00
|
|
|
/**
|
|
|
|
* Holds the total number of attachments.
|
|
|
|
*
|
2021-05-08 07:22:03 -04:00
|
|
|
* @since 5.8.0
|
2021-05-07 19:19:03 -04:00
|
|
|
*/
|
|
|
|
totalAttachments: 0,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the total number of attachments.
|
|
|
|
*
|
2021-05-08 07:22:03 -04:00
|
|
|
* @since 5.8.0
|
2021-05-07 19:19:03 -04:00
|
|
|
*
|
|
|
|
* @return {number} The total number of attachments.
|
|
|
|
*/
|
|
|
|
getTotalAttachments: function() {
|
|
|
|
return this.mirroring ? this.mirroring.totalAttachments : 0;
|
|
|
|
},
|
|
|
|
|
2018-12-13 12:27:38 -05:00
|
|
|
/**
|
2020-06-25 08:43:07 -04:00
|
|
|
* A custom Ajax-response parser.
|
2018-12-13 12:27:38 -05:00
|
|
|
*
|
2021-05-08 07:22:03 -04:00
|
|
|
* See trac ticket #24753.
|
2018-12-13 12:27:38 -05:00
|
|
|
*
|
2021-05-07 19:19:03 -04:00
|
|
|
* Called automatically by Backbone whenever a collection's models are returned
|
|
|
|
* by the server, in fetch. The default implementation is a no-op, simply
|
|
|
|
* passing through the JSON response. We override this to add attributes to
|
|
|
|
* the collection items.
|
|
|
|
*
|
2021-05-08 07:22:03 -04:00
|
|
|
* @since 5.8.0 The response returns the attachments under `response.attachments` and
|
|
|
|
* `response.totalAttachments` holds the total number of attachments found.
|
2021-05-07 19:19:03 -04:00
|
|
|
*
|
|
|
|
* @param {Object|Array} response The raw response Object/Array.
|
2018-12-13 12:27:38 -05:00
|
|
|
* @param {Object} xhr
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {Array} The array of model attributes to be added to the collection
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
2021-05-07 19:19:03 -04:00
|
|
|
parse: function( response, xhr ) {
|
|
|
|
if ( ! _.isArray( response.attachments ) ) {
|
2021-05-08 07:22:03 -04:00
|
|
|
response = [ response.attachments ];
|
2018-12-13 12:27:38 -05:00
|
|
|
}
|
|
|
|
|
2021-05-07 19:19:03 -04:00
|
|
|
this.totalAttachments = parseInt( response.totalAttachments, 10 );
|
|
|
|
|
|
|
|
return _.map( response.attachments, function( attrs ) {
|
2018-12-13 12:27:38 -05:00
|
|
|
var id, attachment, newAttributes;
|
|
|
|
|
|
|
|
if ( attrs instanceof Backbone.Model ) {
|
|
|
|
id = attrs.get( 'id' );
|
|
|
|
attrs = attrs.attributes;
|
|
|
|
} else {
|
|
|
|
id = attrs.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
attachment = wp.media.model.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.
|
2021-01-28 21:41:57 -05:00
|
|
|
*
|
2018-12-13 12:27:38 -05:00
|
|
|
* @access private
|
2021-01-28 21:41:57 -05:00
|
|
|
* @param {Boolean} refresh Deprecated, refresh parameter no longer used.
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
2021-01-28 21:41:57 -05:00
|
|
|
_requery: function() {
|
2018-12-13 12:27:38 -05:00
|
|
|
var props;
|
|
|
|
if ( this.props.get('query') ) {
|
|
|
|
props = this.props.toJSON();
|
|
|
|
this.mirror( wp.media.model.Query.get( props ) );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* If this collection is sorted by `menuOrder`, recalculates and saves
|
|
|
|
* the menu order to the database.
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {undefined|Promise}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
saveMenuOrder: function() {
|
|
|
|
if ( 'menuOrder' !== this.props.get('orderby') ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* Removes any uploading attachments, updates each attachment's
|
|
|
|
* menu order, and returns an object with an { id: menuOrder }
|
|
|
|
* mapping to pass to the request.
|
|
|
|
*/
|
2018-12-13 12:27:38 -05:00
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},/** @lends wp.media.model.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().
|
|
|
|
*
|
|
|
|
* @param {Backbone.Model} a
|
|
|
|
* @param {Backbone.Model} b
|
|
|
|
* @param {Object} options
|
2020-07-27 19:35:02 -04:00
|
|
|
* @return {number} -1 if the first model should come before the second,
|
2019-11-29 13:01:03 -05:00
|
|
|
* 0 if they are of the same rank and
|
|
|
|
* 1 if the first model should come after.
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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 wp.media.model.Attachments.filters */
|
|
|
|
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
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {Boolean}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
2020-07-27 19:35:02 -04:00
|
|
|
* @return {boolean}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
type: function( attachment ) {
|
|
|
|
var type = this.props.get('type'), atts = attachment.toJSON(), mime, found;
|
|
|
|
|
|
|
|
if ( ! type || ( _.isArray( type ) && ! type.length ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mime = atts.mime || ( atts.file && atts.file.type ) || '';
|
|
|
|
|
|
|
|
if ( _.isArray( type ) ) {
|
|
|
|
found = _.find( type, function (t) {
|
|
|
|
return -1 !== mime.indexOf( t );
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
found = -1 !== mime.indexOf( type );
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @param {wp.media.model.Attachment} attachment
|
|
|
|
*
|
|
|
|
* @this wp.media.model.Attachments
|
|
|
|
*
|
2020-07-27 19:35:02 -04:00
|
|
|
* @return {boolean}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
2020-07-27 19:35:02 -04:00
|
|
|
* @return {boolean}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
status: function( attachment ) {
|
|
|
|
var status = this.props.get('status');
|
|
|
|
if ( _.isUndefined( status ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status === attachment.get('status');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Attachments;
|
|
|
|
|
2017-10-04 17:02:23 -04:00
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/***/ "dx5j":
|
|
|
|
/***/ (function(module, exports, __webpack_require__) {
|
2021-05-24 17:35:56 -04:00
|
|
|
|
|
|
|
/**
|
2021-05-24 20:12:57 -04:00
|
|
|
* @output wp-includes/js/media-models.js
|
|
|
|
*/
|
|
|
|
|
|
|
|
var $ = jQuery,
|
|
|
|
Attachment, Attachments, l10n, media;
|
|
|
|
|
|
|
|
/** @namespace wp */
|
|
|
|
window.wp = window.wp || {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and return a media frame.
|
2021-05-24 17:35:56 -04:00
|
|
|
*
|
2021-05-24 20:12:57 -04:00
|
|
|
* Handles the default media experience.
|
2021-05-24 17:35:56 -04:00
|
|
|
*
|
2021-05-24 20:12:57 -04:00
|
|
|
* @alias wp.media
|
|
|
|
* @memberOf wp
|
|
|
|
* @namespace
|
2021-05-24 17:35:56 -04:00
|
|
|
*
|
2021-05-24 20:12:57 -04:00
|
|
|
* @param {Object} attributes The properties passed to the main media controller.
|
|
|
|
* @return {wp.media.view.MediaFrame} A media workflow.
|
|
|
|
*/
|
|
|
|
media = wp.media = function( attributes ) {
|
|
|
|
var MediaFrame = media.view.MediaFrame,
|
|
|
|
frame;
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
if ( ! MediaFrame ) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
attributes = _.defaults( attributes || {}, {
|
|
|
|
frame: 'select'
|
|
|
|
});
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
if ( 'select' === attributes.frame && MediaFrame.Select ) {
|
|
|
|
frame = new MediaFrame.Select( attributes );
|
|
|
|
} else if ( 'post' === attributes.frame && MediaFrame.Post ) {
|
|
|
|
frame = new MediaFrame.Post( attributes );
|
|
|
|
} else if ( 'manage' === attributes.frame && MediaFrame.Manage ) {
|
|
|
|
frame = new MediaFrame.Manage( attributes );
|
|
|
|
} else if ( 'image' === attributes.frame && MediaFrame.ImageDetails ) {
|
|
|
|
frame = new MediaFrame.ImageDetails( attributes );
|
|
|
|
} else if ( 'audio' === attributes.frame && MediaFrame.AudioDetails ) {
|
|
|
|
frame = new MediaFrame.AudioDetails( attributes );
|
|
|
|
} else if ( 'video' === attributes.frame && MediaFrame.VideoDetails ) {
|
|
|
|
frame = new MediaFrame.VideoDetails( attributes );
|
|
|
|
} else if ( 'edit-attachments' === attributes.frame && MediaFrame.EditAttachments ) {
|
|
|
|
frame = new MediaFrame.EditAttachments( attributes );
|
|
|
|
}
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
delete attributes.frame;
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
media.frame = frame;
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
return frame;
|
|
|
|
};
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/** @namespace wp.media.model */
|
|
|
|
/** @namespace wp.media.view */
|
|
|
|
/** @namespace wp.media.controller */
|
|
|
|
/** @namespace wp.media.frames */
|
|
|
|
_.extend( media, { model: {}, view: {}, controller: {}, frames: {} });
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
// Link any localized strings.
|
|
|
|
l10n = media.model.l10n = window._wpMediaModelsL10n || {};
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
// Link any settings.
|
|
|
|
media.model.settings = l10n.settings || {};
|
|
|
|
delete l10n.settings;
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
Attachment = media.model.Attachment = __webpack_require__( "0Ym0" );
|
|
|
|
Attachments = media.model.Attachments = __webpack_require__( "K0z/" );
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
media.model.Query = __webpack_require__( "efdO" );
|
|
|
|
media.model.PostImage = __webpack_require__( "r1z7" );
|
|
|
|
media.model.Selection = __webpack_require__( "Io+g" );
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/**
|
|
|
|
* ========================================================================
|
|
|
|
* UTILITIES
|
|
|
|
* ========================================================================
|
|
|
|
*/
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/**
|
|
|
|
* A basic equality comparator for Backbone models.
|
|
|
|
*
|
|
|
|
* Used to order models within a collection - @see wp.media.model.Attachments.comparator().
|
|
|
|
*
|
|
|
|
* @param {mixed} a The primary parameter to compare.
|
|
|
|
* @param {mixed} b The primary parameter to compare.
|
|
|
|
* @param {string} ac The fallback parameter to compare, a's cid.
|
|
|
|
* @param {string} bc The fallback parameter to compare, b's cid.
|
|
|
|
* @return {number} -1: a should come before b.
|
|
|
|
* 0: a and b are of the same rank.
|
|
|
|
* 1: b should come before a.
|
|
|
|
*/
|
|
|
|
media.compare = function( a, b, ac, bc ) {
|
|
|
|
if ( _.isEqual( a, b ) ) {
|
|
|
|
return ac === bc ? 0 : (ac > bc ? -1 : 1);
|
|
|
|
} else {
|
|
|
|
return a > b ? -1 : 1;
|
|
|
|
}
|
|
|
|
};
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
_.extend( media, /** @lends wp.media */{
|
|
|
|
/**
|
|
|
|
* media.template( id )
|
|
|
|
*
|
|
|
|
* Fetch a JavaScript template for an id, and return a templating function for it.
|
|
|
|
*
|
|
|
|
* See wp.template() in `wp-includes/js/wp-util.js`.
|
|
|
|
*
|
|
|
|
* @borrows wp.template as template
|
|
|
|
*/
|
|
|
|
template: wp.template,
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/**
|
|
|
|
* media.post( [action], [data] )
|
|
|
|
*
|
|
|
|
* Sends a POST request to WordPress.
|
|
|
|
* See wp.ajax.post() in `wp-includes/js/wp-util.js`.
|
|
|
|
*
|
|
|
|
* @borrows wp.ajax.post as post
|
|
|
|
*/
|
|
|
|
post: wp.ajax.post,
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/**
|
|
|
|
* media.ajax( [action], [options] )
|
|
|
|
*
|
|
|
|
* Sends an XHR request to WordPress.
|
|
|
|
* See wp.ajax.send() in `wp-includes/js/wp-util.js`.
|
|
|
|
*
|
|
|
|
* @borrows wp.ajax.send as ajax
|
|
|
|
*/
|
|
|
|
ajax: wp.ajax.send,
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/**
|
|
|
|
* Scales a set of dimensions to fit within bounding dimensions.
|
|
|
|
*
|
|
|
|
* @param {Object} dimensions
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
fit: function( dimensions ) {
|
|
|
|
var width = dimensions.width,
|
|
|
|
height = dimensions.height,
|
|
|
|
maxWidth = dimensions.maxWidth,
|
|
|
|
maxHeight = dimensions.maxHeight,
|
|
|
|
constraint;
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/*
|
|
|
|
* Compare ratios between the two values to determine
|
|
|
|
* which max to constrain by. If a max value doesn't exist,
|
|
|
|
* then the opposite side is the constraint.
|
|
|
|
*/
|
|
|
|
if ( ! _.isUndefined( maxWidth ) && ! _.isUndefined( maxHeight ) ) {
|
|
|
|
constraint = ( width / height > maxWidth / maxHeight ) ? 'width' : 'height';
|
|
|
|
} else if ( _.isUndefined( maxHeight ) ) {
|
|
|
|
constraint = 'width';
|
|
|
|
} else if ( _.isUndefined( maxWidth ) && height > maxHeight ) {
|
|
|
|
constraint = 'height';
|
2021-05-24 17:35:56 -04:00
|
|
|
}
|
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
// If the value of the constrained side is larger than the max,
|
|
|
|
// then scale the values. Otherwise return the originals; they fit.
|
|
|
|
if ( 'width' === constraint && width > maxWidth ) {
|
|
|
|
return {
|
|
|
|
width : maxWidth,
|
|
|
|
height: Math.round( maxWidth * height / width )
|
|
|
|
};
|
|
|
|
} else if ( 'height' === constraint && height > maxHeight ) {
|
|
|
|
return {
|
|
|
|
width : Math.round( maxHeight * width / height ),
|
|
|
|
height: maxHeight
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
width : width,
|
|
|
|
height: height
|
|
|
|
};
|
2021-05-24 17:35:56 -04:00
|
|
|
}
|
|
|
|
},
|
2021-05-24 20:12:57 -04:00
|
|
|
/**
|
|
|
|
* Truncates a string by injecting an ellipsis into the middle.
|
|
|
|
* Useful for filenames.
|
|
|
|
*
|
|
|
|
* @param {string} string
|
|
|
|
* @param {number} [length=30]
|
|
|
|
* @param {string} [replacement=…]
|
|
|
|
* @return {string} The string, unless length is greater than string.length.
|
|
|
|
*/
|
|
|
|
truncate: function( string, length, replacement ) {
|
|
|
|
length = length || 30;
|
|
|
|
replacement = replacement || '…';
|
|
|
|
|
|
|
|
if ( string.length <= length ) {
|
|
|
|
return string;
|
2021-05-24 17:35:56 -04:00
|
|
|
}
|
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
return string.substr( 0, length / 2 ) + replacement + string.substr( -1 * length / 2 );
|
2021-05-24 17:35:56 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/**
|
|
|
|
* ========================================================================
|
|
|
|
* MODELS
|
|
|
|
* ========================================================================
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* wp.media.attachment
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @param {string} id A string used to identify a model.
|
|
|
|
* @return {wp.media.model.Attachment}
|
|
|
|
*/
|
|
|
|
media.attachment = function( id ) {
|
|
|
|
return Attachment.get( id );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A collection of all attachments that have been fetched from the server.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @member {wp.media.model.Attachments}
|
|
|
|
*/
|
|
|
|
Attachments.all = new Attachments();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wp.media.query
|
|
|
|
*
|
|
|
|
* Shorthand for creating a new Attachments Query.
|
|
|
|
*
|
|
|
|
* @param {Object} [props]
|
|
|
|
* @return {wp.media.model.Attachments}
|
|
|
|
*/
|
|
|
|
media.query = function( props ) {
|
|
|
|
return new Attachments( null, {
|
|
|
|
props: _.extend( _.defaults( props || {}, { orderby: 'date' } ), { query: true } )
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Clean up. Prevents mobile browsers caching.
|
|
|
|
$(window).on('unload', function(){
|
|
|
|
window.wp = null;
|
|
|
|
});
|
2021-05-24 17:35:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/***/ "efdO":
|
2017-10-04 17:02:23 -04:00
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
2018-12-13 12:27:38 -05:00
|
|
|
var Attachments = wp.media.model.Attachments,
|
|
|
|
Query;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @memberOf wp.media.model
|
|
|
|
*
|
|
|
|
* @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]
|
|
|
|
*/
|
|
|
|
Query = Attachments.extend(/** @lends wp.media.model.Query.prototype */{
|
|
|
|
/**
|
2020-07-27 19:35:02 -04:00
|
|
|
* @param {Array} [models=[]] Array of initial models to populate the collection.
|
|
|
|
* @param {Object} [options={}]
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-12-13 12:27:38 -05:00
|
|
|
if ( this.length ) {
|
|
|
|
return 1 !== this.comparator( attachment, this.last(), { ties: true });
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-12-13 12:27:38 -05:00
|
|
|
} 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;
|
|
|
|
};
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-12-13 12:27:38 -05:00
|
|
|
allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ];
|
|
|
|
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.
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {boolean}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
hasMore: function() {
|
|
|
|
return this._hasMore;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Fetch more attachments from the server for the collection.
|
|
|
|
*
|
2020-07-27 19:35:02 -04:00
|
|
|
* @param {Object} [options={}]
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {Promise}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
2021-05-07 19:19:03 -04:00
|
|
|
return this._more = this.fetch( options ).done( function( response ) {
|
|
|
|
var attachments = response.attachments;
|
|
|
|
|
|
|
|
if ( _.isEmpty( attachments ) || -1 === this.args.posts_per_page || attachments.length < this.args.posts_per_page ) {
|
2018-12-13 12:27:38 -05:00
|
|
|
query._hasMore = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Overrides Backbone.Collection.sync
|
|
|
|
* Overrides wp.media.model.Attachments.sync
|
|
|
|
*
|
2020-07-27 19:35:02 -04:00
|
|
|
* @param {string} method
|
2018-12-13 12:27:38 -05:00
|
|
|
* @param {Backbone.Model} model
|
|
|
|
* @param {Object} [options={}]
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {Promise}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
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.round( this.length / args.posts_per_page ) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
options.data.query = args;
|
|
|
|
return wp.media.ajax( options );
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Otherwise, fall back to `Backbone.sync()`.
|
2018-12-13 12:27:38 -05:00
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* Call wp.media.model.Attachments.sync or Backbone.sync
|
|
|
|
*/
|
|
|
|
fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone;
|
|
|
|
return fallback.sync.apply( this, arguments );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, /** @lends wp.media.model.Query */{
|
|
|
|
/**
|
|
|
|
* @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',
|
|
|
|
'author': 'author'
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 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.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} [props.author]
|
|
|
|
* @param {Object} [options]
|
|
|
|
*
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {wp.media.model.Query} A new Attachments Query collection.
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
get: (function(){
|
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @type Array
|
|
|
|
*/
|
|
|
|
var queries = [];
|
|
|
|
|
|
|
|
/**
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {Query}
|
2018-12-13 12:27:38 -05:00
|
|
|
*/
|
|
|
|
return function( props, options ) {
|
|
|
|
var args = {},
|
|
|
|
orderby = Query.orderby,
|
|
|
|
defaults = Query.defaultProps,
|
2021-01-28 20:35:59 -05:00
|
|
|
query;
|
2018-12-13 12:27:38 -05:00
|
|
|
|
|
|
|
// Remove the `query` property. This isn't linked to a query,
|
|
|
|
// this *is* the query.
|
|
|
|
delete props.query;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2021-01-28 20:35:59 -05:00
|
|
|
queries = [];
|
2018-12-13 12:27:38 -05:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2017-10-04 17:02:23 -04:00
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
/***/ "r1z7":
|
2018-12-13 12:27:38 -05:00
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
/**
|
2021-05-24 20:12:57 -04:00
|
|
|
* wp.media.model.PostImage
|
2018-12-13 12:27:38 -05:00
|
|
|
*
|
2021-05-24 20:12:57 -04:00
|
|
|
* 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.
|
2018-12-13 12:27:38 -05:00
|
|
|
*
|
|
|
|
* @memberOf wp.media.model
|
|
|
|
*
|
|
|
|
* @class
|
2021-05-24 20:12:57 -04:00
|
|
|
* @augments Backbone.Model
|
|
|
|
*
|
|
|
|
* @param {int} [attributes] Initial model attributes.
|
|
|
|
* @param {int} [attributes.attachment_id] ID of the attachment.
|
|
|
|
**/
|
|
|
|
var PostImage = Backbone.Model.extend(/** @lends wp.media.model.PostImage.prototype */{
|
2018-12-13 12:27:38 -05:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
initialize: function( attributes ) {
|
|
|
|
var Attachment = wp.media.model.Attachment;
|
|
|
|
this.attachment = false;
|
2018-12-13 12:27:38 -05:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
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();
|
2018-12-13 12:27:38 -05:00
|
|
|
}
|
2021-05-24 20:12:57 -04:00
|
|
|
|
|
|
|
// 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 );
|
2018-12-13 12:27:38 -05:00
|
|
|
},
|
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
bindAttachmentListeners: function() {
|
|
|
|
this.listenTo( this.attachment, 'sync', this.setLinkTypeFromUrl );
|
|
|
|
this.listenTo( this.attachment, 'sync', this.setAspectRatio );
|
|
|
|
this.listenTo( this.attachment, 'change', this.updateSize );
|
|
|
|
},
|
2018-12-13 12:27:38 -05:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
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;
|
2018-12-13 12:27:38 -05:00
|
|
|
}
|
2021-05-24 20:12:57 -04:00
|
|
|
|
|
|
|
// 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';
|
|
|
|
}
|
2018-12-13 12:27:38 -05:00
|
|
|
}
|
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
this.set( 'link', type );
|
|
|
|
},
|
2018-12-13 12:27:38 -05:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
updateLinkUrl: function() {
|
|
|
|
var link = this.get( 'link' ),
|
|
|
|
url;
|
2018-12-13 12:27:38 -05:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
switch( link ) {
|
|
|
|
case 'file':
|
|
|
|
if ( this.attachment ) {
|
|
|
|
url = this.attachment.get( 'url' );
|
|
|
|
} else {
|
|
|
|
url = this.get( 'url' );
|
2018-12-13 12:27:38 -05:00
|
|
|
}
|
2021-05-24 20:12:57 -04:00
|
|
|
this.set( 'linkUrl', url );
|
|
|
|
break;
|
|
|
|
case 'post':
|
|
|
|
this.set( 'linkUrl', this.attachment.get( 'link' ) );
|
|
|
|
break;
|
|
|
|
case 'none':
|
|
|
|
this.set( 'linkUrl', '' );
|
|
|
|
break;
|
2018-12-13 12:27:38 -05:00
|
|
|
}
|
2021-05-24 20:12:57 -04:00
|
|
|
},
|
2018-12-13 12:27:38 -05:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
updateSize: function() {
|
|
|
|
var size;
|
2018-12-13 12:27:38 -05:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
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;
|
|
|
|
}
|
2015-02-09 11:01:29 -05:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
size = this.attachment.get( 'sizes' )[ this.get( 'size' ) ];
|
2017-10-04 17:02:23 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
if ( ! size ) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
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' ) );
|
|
|
|
}
|
|
|
|
});
|
2021-05-24 17:35:56 -04:00
|
|
|
|
2021-05-24 20:12:57 -04:00
|
|
|
module.exports = PostImage;
|
2021-05-24 17:35:56 -04:00
|
|
|
|
|
|
|
|
2017-10-04 17:02:23 -04:00
|
|
|
/***/ })
|
|
|
|
|
2018-05-03 10:48:22 -04:00
|
|
|
/******/ });
|