WordPress/wp-includes/js/media-models.js

166 lines
51 KiB
JavaScript
Raw Normal View History

/******/ (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)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // 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;
/******/ };
/******/
/******/ // 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 = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ })
/************************************************************************/
/******/ ({
/***/ "./src/js/_enqueues/wp/media/models.js":
/*!*********************************************!*\
!*** ./src/js/_enqueues/wp/media/models.js ***!
\*********************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
eval("/**\n * @output wp-includes/js/media-models.js\n */\n\nvar $ = jQuery,\n\tAttachment, Attachments, l10n, media;\n\n/** @namespace wp */\nwindow.wp = window.wp || {};\n\n/**\n * Create and return a media frame.\n *\n * Handles the default media experience.\n *\n * @alias wp.media\n * @memberOf wp\n * @namespace\n *\n * @param {object} attributes The properties passed to the main media controller.\n * @return {wp.media.view.MediaFrame} A media workflow.\n */\nmedia = wp.media = function( attributes ) {\n\tvar MediaFrame = media.view.MediaFrame,\n\t\tframe;\n\n\tif ( ! MediaFrame ) {\n\t\treturn;\n\t}\n\n\tattributes = _.defaults( attributes || {}, {\n\t\tframe: 'select'\n\t});\n\n\tif ( 'select' === attributes.frame && MediaFrame.Select ) {\n\t\tframe = new MediaFrame.Select( attributes );\n\t} else if ( 'post' === attributes.frame && MediaFrame.Post ) {\n\t\tframe = new MediaFrame.Post( attributes );\n\t} else if ( 'manage' === attributes.frame && MediaFrame.Manage ) {\n\t\tframe = new MediaFrame.Manage( attributes );\n\t} else if ( 'image' === attributes.frame && MediaFrame.ImageDetails ) {\n\t\tframe = new MediaFrame.ImageDetails( attributes );\n\t} else if ( 'audio' === attributes.frame && MediaFrame.AudioDetails ) {\n\t\tframe = new MediaFrame.AudioDetails( attributes );\n\t} else if ( 'video' === attributes.frame && MediaFrame.VideoDetails ) {\n\t\tframe = new MediaFrame.VideoDetails( attributes );\n\t} else if ( 'edit-attachments' === attributes.frame && MediaFrame.EditAttachments ) {\n\t\tframe = new MediaFrame.EditAttachments( attributes );\n\t}\n\n\tdelete attributes.frame;\n\n\tmedia.frame = frame;\n\n\treturn frame;\n};\n\n/** @namespace wp.media.model */\n/** @namespace wp.media.view */\n/** @namespace wp.media.controller */\n/** @namespace wp.media.frames */\n_.extend( media, { model: {}, view: {}, controller: {}, frames: {} });\n\n// Link any localized strings.\nl10n = media.model.l10n = window._wpMediaModelsL10n || {};\n\n// Link any settings.\nmedia.model.settings = l10n.settings || {};\ndelete l10n.settings;\n\nAttachment = media.model.Attachment = __webpack_require__( /*! ../../../media/models/attachment.js */ \"./src/js/media/models/attachment.js\" );\nAttachments = media.model.Attachments = __webpack_require__( /*! ../../../media/models/attachments.js */ \"./src/js/media/models/attachments.js\" );\n\nmedia.model.Query = __webpack_require__( /*! ../../../media/models/query.js */ \"./src/js/media/models/query.js\" );\nmedia.model.PostImage = __webpack_require__( /*! ../../../media/models/post-image.js */ \"./src/js/media/models/post-image.js\" );\nmedia.model.Selection = __webpack_require__( /*! ../../../media/models/selection.js */ \"./src/js/media/models/selection.js\" );\n\n/**\n * ========================================================================\n * UTILITIES\n * ========================================================================\n */\n\n/**\n * A basic equality comparator for Backbone models.\n *\n * Used to order models within a collection - @see wp.media.model.Attachments.comparator().\n *\n * @param {mixed} a The primary parameter to compare.\n * @param {mixed} b The primary parameter to compare.\n * @param {string} ac The fallback parameter to compare, a's cid.\n * @param {string} bc The fallback parameter to compare, b's cid.\n * @return {number} -1: a should come before b.\n * 0: a and b are of the same rank.\n * 1: b should come before a.\n */\nmedia.compare = function( a, b, ac, bc ) {\n\tif ( _.isEqual( a, b ) ) {\n\t\treturn ac === bc ? 0 : (ac > bc ? -1 : 1);\n\t} else {\n\t\treturn a > b ? -1 : 1;\n\t}\n};\n\n_.extend( media, /** @lends wp.media */{\n\t/**\n\t * media.template( id )\n\t *\n\t * Fetch a JavaScript template for an id, and return a templating function for it.\n\t *\n\t * See wp.template() in `wp-includes/js/wp-util.js`.\n\t *\n\t * @borrows wp.template as template\n\t */\n\ttemplate: wp.template,\n\n\t/**\n\t * media.post( [action], [data] )\n\t *\n\t * Sends a POST request to WordPress.\n\t * See wp.a
/***/ }),
/***/ "./src/js/media/models/attachment.js":
/*!*******************************************!*\
!*** ./src/js/media/models/attachment.js ***!
\*******************************************/
/*! no static exports found */
/***/ (function(module, exports) {
eval("var $ = Backbone.$,\n\tAttachment;\n\n/**\n * wp.media.model.Attachment\n *\n * @memberOf wp.media.model\n *\n * @class\n * @augments Backbone.Model\n */\nAttachment = Backbone.Model.extend(/** @lends wp.media.model.Attachment.prototype */{\n\t/**\n\t * Triggered when attachment details change\n\t * Overrides Backbone.Model.sync\n\t *\n\t * @param {string} method\n\t * @param {wp.media.model.Attachment} model\n\t * @param {Object} [options={}]\n\t *\n\t * @returns {Promise}\n\t */\n\tsync: function( method, model, options ) {\n\t\t// If the attachment does not yet have an `id`, return an instantly\n\t\t// rejected promise. Otherwise, all of our requests will fail.\n\t\tif ( _.isUndefined( this.id ) ) {\n\t\t\treturn $.Deferred().rejectWith( this ).promise();\n\t\t}\n\n\t\t// Overload the `read` request so Attachment.fetch() functions correctly.\n\t\tif ( 'read' === method ) {\n\t\t\toptions = options || {};\n\t\t\toptions.context = this;\n\t\t\toptions.data = _.extend( options.data || {}, {\n\t\t\t\taction: 'get-attachment',\n\t\t\t\tid: this.id\n\t\t\t});\n\t\t\treturn wp.media.ajax( options );\n\n\t\t// Overload the `update` request so properties can be saved.\n\t\t} else if ( 'update' === method ) {\n\t\t\t// If we do not have the necessary nonce, fail immeditately.\n\t\t\tif ( ! this.get('nonces') || ! this.get('nonces').update ) {\n\t\t\t\treturn $.Deferred().rejectWith( this ).promise();\n\t\t\t}\n\n\t\t\toptions = options || {};\n\t\t\toptions.context = this;\n\n\t\t\t// Set the action and ID.\n\t\t\toptions.data = _.extend( options.data || {}, {\n\t\t\t\taction: 'save-attachment',\n\t\t\t\tid: this.id,\n\t\t\t\tnonce: this.get('nonces').update,\n\t\t\t\tpost_id: wp.media.model.settings.post.id\n\t\t\t});\n\n\t\t\t// Record the values of the changed attributes.\n\t\t\tif ( model.hasChanged() ) {\n\t\t\t\toptions.data.changes = {};\n\n\t\t\t\t_.each( model.changed, function( value, key ) {\n\t\t\t\t\toptions.data.changes[ key ] = this.get( key );\n\t\t\t\t}, this );\n\t\t\t}\n\n\t\t\treturn wp.media.ajax( options );\n\n\t\t// Overload the `delete` request so attachments can be removed.\n\t\t// This will permanently delete an attachment.\n\t\t} else if ( 'delete' === method ) {\n\t\t\toptions = options || {};\n\n\t\t\tif ( ! options.wait ) {\n\t\t\t\tthis.destroyed = true;\n\t\t\t}\n\n\t\t\toptions.context = this;\n\t\t\toptions.data = _.extend( options.data || {}, {\n\t\t\t\taction: 'delete-post',\n\t\t\t\tid: this.id,\n\t\t\t\t_wpnonce: this.get('nonces')['delete']\n\t\t\t});\n\n\t\t\treturn wp.media.ajax( options ).done( function() {\n\t\t\t\tthis.destroyed = true;\n\t\t\t}).fail( function() {\n\t\t\t\tthis.destroyed = false;\n\t\t\t});\n\n\t\t// Otherwise, fall back to `Backbone.sync()`.\n\t\t} else {\n\t\t\t/**\n\t\t\t * Call `sync` directly on Backbone.Model\n\t\t\t */\n\t\t\treturn Backbone.Model.prototype.sync.apply( this, arguments );\n\t\t}\n\t},\n\t/**\n\t * Convert date strings into Date objects.\n\t *\n\t * @param {Object} resp The raw response object, typically returned by fetch()\n\t * @returns {Object} The modified response object, which is the attributes hash\n\t * to be set on the model.\n\t */\n\tparse: function( resp ) {\n\t\tif ( ! resp ) {\n\t\t\treturn resp;\n\t\t}\n\n\t\tresp.date = new Date( resp.date );\n\t\tresp.modified = new Date( resp.modified );\n\t\treturn resp;\n\t},\n\t/**\n\t * @param {Object} data The properties to be saved.\n\t * @param {Object} options Sync options. e.g. patch, wait, success, error.\n\t *\n\t * @this Backbone.Model\n\t *\n\t * @returns {Promise}\n\t */\n\tsaveCompat: function( data, options ) {\n\t\tvar model = this;\n\n\t\t// If we do not have the necessary nonce, fail immeditately.\n\t\tif ( ! this.get('nonces') || ! this.get('nonces').update ) {\n\t\t\treturn $.Deferred().rejectWith( this ).promise();\n\t\t}\n\n\t\treturn wp.media.post( 'save-attachment-compat', _.defaults({\n\t\t\tid: this.id,\n\t\t\tnonce: this.get('nonces').update,\n\t\t\tpost_id: wp.media.model.settings.post.id\n\t\t}, data ) ).done( function( resp, status
/***/ }),
/***/ "./src/js/media/models/attachments.js":
/*!********************************************!*\
!*** ./src/js/media/models/attachments.js ***!
\********************************************/
/*! no static exports found */
/***/ (function(module, exports) {
eval("/**\n * wp.media.model.Attachments\n *\n * A collection of attachments.\n *\n * This collection has no persistence with the server without supplying\n * 'options.props.query = true', which will mirror the collection\n * to an Attachments Query collection - @see wp.media.model.Attachments.mirror().\n *\n * @memberOf wp.media.model\n *\n * @class\n * @augments Backbone.Collection\n *\n * @param {array} [models] Models to initialize with the collection.\n * @param {object} [options] Options hash for the collection.\n * @param {string} [options.props] Options hash for the initial query properties.\n * @param {string} [options.props.order] Initial order (ASC or DESC) for the collection.\n * @param {string} [options.props.orderby] Initial attribute key to order the collection by.\n * @param {string} [options.props.query] Whether the collection is linked to an attachments query.\n * @param {string} [options.observe]\n * @param {string} [options.filters]\n *\n */\nvar Attachments = Backbone.Collection.extend(/** @lends wp.media.model.Attachments.prototype */{\n\t/**\n\t * @type {wp.media.model.Attachment}\n\t */\n\tmodel: wp.media.model.Attachment,\n\t/**\n\t * @param {Array} [models=[]] Array of models used to populate the collection.\n\t * @param {Object} [options={}]\n\t */\n\tinitialize: function( models, options ) {\n\t\toptions = options || {};\n\n\t\tthis.props = new Backbone.Model();\n\t\tthis.filters = options.filters || {};\n\n\t\t// Bind default `change` events to the `props` model.\n\t\tthis.props.on( 'change', this._changeFilteredProps, this );\n\n\t\tthis.props.on( 'change:order', this._changeOrder, this );\n\t\tthis.props.on( 'change:orderby', this._changeOrderby, this );\n\t\tthis.props.on( 'change:query', this._changeQuery, this );\n\n\t\tthis.props.set( _.defaults( options.props || {} ) );\n\n\t\tif ( options.observe ) {\n\t\t\tthis.observe( options.observe );\n\t\t}\n\t},\n\t/**\n\t * Sort the collection when the order attribute changes.\n\t *\n\t * @access private\n\t */\n\t_changeOrder: function() {\n\t\tif ( this.comparator ) {\n\t\t\tthis.sort();\n\t\t}\n\t},\n\t/**\n\t * Set the default comparator only when the `orderby` property is set.\n\t *\n\t * @access private\n\t *\n\t * @param {Backbone.Model} model\n\t * @param {string} orderby\n\t */\n\t_changeOrderby: function( model, orderby ) {\n\t\t// If a different comparator is defined, bail.\n\t\tif ( this.comparator && this.comparator !== Attachments.comparator ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( orderby && 'post__in' !== orderby ) {\n\t\t\tthis.comparator = Attachments.comparator;\n\t\t} else {\n\t\t\tdelete this.comparator;\n\t\t}\n\t},\n\t/**\n\t * If the `query` property is set to true, query the server using\n\t * the `props` values, and sync the results to this collection.\n\t *\n\t * @access private\n\t *\n\t * @param {Backbone.Model} model\n\t * @param {Boolean} query\n\t */\n\t_changeQuery: function( model, query ) {\n\t\tif ( query ) {\n\t\t\tthis.props.on( 'change', this._requery, this );\n\t\t\tthis._requery();\n\t\t} else {\n\t\t\tthis.props.off( 'change', this._requery, this );\n\t\t}\n\t},\n\t/**\n\t * @access private\n\t *\n\t * @param {Backbone.Model} model\n\t */\n\t_changeFilteredProps: function( model ) {\n\t\t// If this is a query, updating the collection will be handled by\n\t\t// `this._requery()`.\n\t\tif ( this.props.get('query') ) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar changed = _.chain( model.changed ).map( function( t, prop ) {\n\t\t\tvar filter = Attachments.filters[ prop ],\n\t\t\t\tterm = model.get( prop );\n\n\t\t\tif ( ! filter ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( term && ! this.filters[ prop ] ) {\n\t\t\t\tthis.filters[ prop ] = filter;\n\t\t\t} else if ( ! term && this.filters[ prop ] === filter ) {\n\t\t\t\tdelete this.filters[ prop ];\n\t\t\t} else {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Record the change.\n\t\t\treturn true;\n\t\t}, this ).any().value();\n\n\t\tif ( ! changed ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If no `Attachments` model is provided to sou
/***/ }),
/***/ "./src/js/media/models/post-image.js":
/*!*******************************************!*\
!*** ./src/js/media/models/post-image.js ***!
\*******************************************/
/*! no static exports found */
/***/ (function(module, exports) {
eval("/**\n * wp.media.model.PostImage\n *\n * An instance of an image that's been embedded into a post.\n *\n * Used in the embedded image attachment display settings modal - @see wp.media.view.MediaFrame.ImageDetails.\n *\n * @memberOf wp.media.model\n *\n * @class\n * @augments Backbone.Model\n *\n * @param {int} [attributes] Initial model attributes.\n * @param {int} [attributes.attachment_id] ID of the attachment.\n **/\nvar PostImage = Backbone.Model.extend(/** @lends wp.media.model.PostImage.prototype */{\n\n\tinitialize: function( attributes ) {\n\t\tvar Attachment = wp.media.model.Attachment;\n\t\tthis.attachment = false;\n\n\t\tif ( attributes.attachment_id ) {\n\t\t\tthis.attachment = Attachment.get( attributes.attachment_id );\n\t\t\tif ( this.attachment.get( 'url' ) ) {\n\t\t\t\tthis.dfd = jQuery.Deferred();\n\t\t\t\tthis.dfd.resolve();\n\t\t\t} else {\n\t\t\t\tthis.dfd = this.attachment.fetch();\n\t\t\t}\n\t\t\tthis.bindAttachmentListeners();\n\t\t}\n\n\t\t// keep url in sync with changes to the type of link\n\t\tthis.on( 'change:link', this.updateLinkUrl, this );\n\t\tthis.on( 'change:size', this.updateSize, this );\n\n\t\tthis.setLinkTypeFromUrl();\n\t\tthis.setAspectRatio();\n\n\t\tthis.set( 'originalUrl', attributes.url );\n\t},\n\n\tbindAttachmentListeners: function() {\n\t\tthis.listenTo( this.attachment, 'sync', this.setLinkTypeFromUrl );\n\t\tthis.listenTo( this.attachment, 'sync', this.setAspectRatio );\n\t\tthis.listenTo( this.attachment, 'change', this.updateSize );\n\t},\n\n\tchangeAttachment: function( attachment, props ) {\n\t\tthis.stopListening( this.attachment );\n\t\tthis.attachment = attachment;\n\t\tthis.bindAttachmentListeners();\n\n\t\tthis.set( 'attachment_id', this.attachment.get( 'id' ) );\n\t\tthis.set( 'caption', this.attachment.get( 'caption' ) );\n\t\tthis.set( 'alt', this.attachment.get( 'alt' ) );\n\t\tthis.set( 'size', props.get( 'size' ) );\n\t\tthis.set( 'align', props.get( 'align' ) );\n\t\tthis.set( 'link', props.get( 'link' ) );\n\t\tthis.updateLinkUrl();\n\t\tthis.updateSize();\n\t},\n\n\tsetLinkTypeFromUrl: function() {\n\t\tvar linkUrl = this.get( 'linkUrl' ),\n\t\t\ttype;\n\n\t\tif ( ! linkUrl ) {\n\t\t\tthis.set( 'link', 'none' );\n\t\t\treturn;\n\t\t}\n\n\t\t// default to custom if there is a linkUrl\n\t\ttype = 'custom';\n\n\t\tif ( this.attachment ) {\n\t\t\tif ( this.attachment.get( 'url' ) === linkUrl ) {\n\t\t\t\ttype = 'file';\n\t\t\t} else if ( this.attachment.get( 'link' ) === linkUrl ) {\n\t\t\t\ttype = 'post';\n\t\t\t}\n\t\t} else {\n\t\t\tif ( this.get( 'url' ) === linkUrl ) {\n\t\t\t\ttype = 'file';\n\t\t\t}\n\t\t}\n\n\t\tthis.set( 'link', type );\n\t},\n\n\tupdateLinkUrl: function() {\n\t\tvar link = this.get( 'link' ),\n\t\t\turl;\n\n\t\tswitch( link ) {\n\t\t\tcase 'file':\n\t\t\t\tif ( this.attachment ) {\n\t\t\t\t\turl = this.attachment.get( 'url' );\n\t\t\t\t} else {\n\t\t\t\t\turl = this.get( 'url' );\n\t\t\t\t}\n\t\t\t\tthis.set( 'linkUrl', url );\n\t\t\t\tbreak;\n\t\t\tcase 'post':\n\t\t\t\tthis.set( 'linkUrl', this.attachment.get( 'link' ) );\n\t\t\t\tbreak;\n\t\t\tcase 'none':\n\t\t\t\tthis.set( 'linkUrl', '' );\n\t\t\t\tbreak;\n\t\t}\n\t},\n\n\tupdateSize: function() {\n\t\tvar size;\n\n\t\tif ( ! this.attachment ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( this.get( 'size' ) === 'custom' ) {\n\t\t\tthis.set( 'width', this.get( 'customWidth' ) );\n\t\t\tthis.set( 'height', this.get( 'customHeight' ) );\n\t\t\tthis.set( 'url', this.get( 'originalUrl' ) );\n\t\t\treturn;\n\t\t}\n\n\t\tsize = this.attachment.get( 'sizes' )[ this.get( 'size' ) ];\n\n\t\tif ( ! size ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.set( 'url', size.url );\n\t\tthis.set( 'width', size.width );\n\t\tthis.set( 'height', size.height );\n\t},\n\n\tsetAspectRatio: function() {\n\t\tvar full;\n\n\t\tif ( this.attachment && this.attachment.get( 'sizes' ) ) {\n\t\t\tfull = this.attachment.get( 'sizes' ).full;\n\n\t\t\tif ( full ) {\n\t\t\t\tthis.set( 'aspectRatio', full.width / full.height );\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tthis.set( 'aspectRatio', this.get( 'customWi
/***/ }),
/***/ "./src/js/media/models/query.js":
/*!**************************************!*\
!*** ./src/js/media/models/query.js ***!
\**************************************/
/*! no static exports found */
/***/ (function(module, exports) {
eval("var Attachments = wp.media.model.Attachments,\n\tQuery;\n\n/**\n * wp.media.model.Query\n *\n * A collection of attachments that match the supplied query arguments.\n *\n * Note: Do NOT change this.args after the query has been initialized.\n * Things will break.\n *\n * @memberOf wp.media.model\n *\n * @class\n * @augments wp.media.model.Attachments\n * @augments Backbone.Collection\n *\n * @param {array} [models] Models to initialize with the collection.\n * @param {object} [options] Options hash.\n * @param {object} [options.args] Attachments query arguments.\n * @param {object} [options.args.posts_per_page]\n */\nQuery = Attachments.extend(/** @lends wp.media.model.Query.prototype */{\n\t/**\n\t * @param {array} [models=[]] Array of initial models to populate the collection.\n\t * @param {object} [options={}]\n\t */\n\tinitialize: function( models, options ) {\n\t\tvar allowed;\n\n\t\toptions = options || {};\n\t\tAttachments.prototype.initialize.apply( this, arguments );\n\n\t\tthis.args = options.args;\n\t\tthis._hasMore = true;\n\t\tthis.created = new Date();\n\n\t\tthis.filters.order = function( attachment ) {\n\t\t\tvar orderby = this.props.get('orderby'),\n\t\t\t\torder = this.props.get('order');\n\n\t\t\tif ( ! this.comparator ) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t// We want any items that can be placed before the last\n\t\t\t// item in the set. If we add any items after the last\n\t\t\t// item, then we can't guarantee the set is complete.\n\t\t\tif ( this.length ) {\n\t\t\t\treturn 1 !== this.comparator( attachment, this.last(), { ties: true });\n\n\t\t\t// Handle the case where there are no items yet and\n\t\t\t// we're sorting for recent items. In that case, we want\n\t\t\t// changes that occurred after we created the query.\n\t\t\t} else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) {\n\t\t\t\treturn attachment.get( orderby ) >= this.created;\n\n\t\t\t// If we're sorting by menu order and we have no items,\n\t\t\t// accept any items that have the default menu order (0).\n\t\t\t} else if ( 'ASC' === order && 'menuOrder' === orderby ) {\n\t\t\t\treturn attachment.get( orderby ) === 0;\n\t\t\t}\n\n\t\t\t// Otherwise, we don't want any items yet.\n\t\t\treturn false;\n\t\t};\n\n\t\t// Observe the central `wp.Uploader.queue` collection to watch for\n\t\t// new matches for the query.\n\t\t//\n\t\t// Only observe when a limited number of query args are set. There\n\t\t// are no filters for other properties, so observing will result in\n\t\t// false positives in those queries.\n\t\tallowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent', 'author' ];\n\t\tif ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) {\n\t\t\tthis.observe( wp.Uploader.queue );\n\t\t}\n\t},\n\t/**\n\t * Whether there are more attachments that haven't been sync'd from the server\n\t * that match the collection's query.\n\t *\n\t * @returns {boolean}\n\t */\n\thasMore: function() {\n\t\treturn this._hasMore;\n\t},\n\t/**\n\t * Fetch more attachments from the server for the collection.\n\t *\n\t * @param {object} [options={}]\n\t * @returns {Promise}\n\t */\n\tmore: function( options ) {\n\t\tvar query = this;\n\n\t\t// If there is already a request pending, return early with the Deferred object.\n\t\tif ( this._more && 'pending' === this._more.state() ) {\n\t\t\treturn this._more;\n\t\t}\n\n\t\tif ( ! this.hasMore() ) {\n\t\t\treturn jQuery.Deferred().resolveWith( this ).promise();\n\t\t}\n\n\t\toptions = options || {};\n\t\toptions.remove = false;\n\n\t\treturn this._more = this.fetch( options ).done( function( resp ) {\n\t\t\tif ( _.isEmpty( resp ) || -1 === this.args.posts_per_page || resp.length < this.args.posts_per_page ) {\n\t\t\t\tquery._hasMore = false;\n\t\t\t}\n\t\t});\n\t},\n\t/**\n\t * Overrides Backbone.Collection.sync\n\t * Overrides wp.media.model.Attachments.sync\n\t *\n\t * @param {String} method\n\t * @param {Backbone.Model} model\n\t * @param
/***/ }),
/***/ "./src/js/media/models/selection.js":
/*!******************************************!*\
!*** ./src/js/media/models/selection.js ***!
\******************************************/
/*! no static exports found */
/***/ (function(module, exports) {
eval("var Attachments = wp.media.model.Attachments,\n\tSelection;\n\n/**\n * wp.media.model.Selection\n *\n * A selection of attachments.\n *\n * @memberOf wp.media.model\n *\n * @class\n * @augments wp.media.model.Attachments\n * @augments Backbone.Collection\n */\nSelection = Attachments.extend(/** @lends wp.media.model.Selection.prototype */{\n\t/**\n\t * Refresh the `single` model whenever the selection changes.\n\t * Binds `single` instead of using the context argument to ensure\n\t * it receives no parameters.\n\t *\n\t * @param {Array} [models=[]] Array of models used to populate the collection.\n\t * @param {Object} [options={}]\n\t */\n\tinitialize: function( models, options ) {\n\t\t/**\n\t\t * call 'initialize' directly on the parent class\n\t\t */\n\t\tAttachments.prototype.initialize.apply( this, arguments );\n\t\tthis.multiple = options && options.multiple;\n\n\t\tthis.on( 'add remove reset', _.bind( this.single, this, false ) );\n\t},\n\n\t/**\n\t * If the workflow does not support multi-select, clear out the selection\n\t * before adding a new attachment to it.\n\t *\n\t * @param {Array} models\n\t * @param {Object} options\n\t * @returns {wp.media.model.Attachment[]}\n\t */\n\tadd: function( models, options ) {\n\t\tif ( ! this.multiple ) {\n\t\t\tthis.remove( this.models );\n\t\t}\n\t\t/**\n\t\t * call 'add' directly on the parent class\n\t\t */\n\t\treturn Attachments.prototype.add.call( this, models, options );\n\t},\n\n\t/**\n\t * Fired when toggling (clicking on) an attachment in the modal.\n\t *\n\t * @param {undefined|boolean|wp.media.model.Attachment} model\n\t *\n\t * @fires wp.media.model.Selection#selection:single\n\t * @fires wp.media.model.Selection#selection:unsingle\n\t *\n\t * @returns {Backbone.Model}\n\t */\n\tsingle: function( model ) {\n\t\tvar previous = this._single;\n\n\t\t// If a `model` is provided, use it as the single model.\n\t\tif ( model ) {\n\t\t\tthis._single = model;\n\t\t}\n\t\t// If the single model isn't in the selection, remove it.\n\t\tif ( this._single && ! this.get( this._single.cid ) ) {\n\t\t\tdelete this._single;\n\t\t}\n\n\t\tthis._single = this._single || this.last();\n\n\t\t// If single has changed, fire an event.\n\t\tif ( this._single !== previous ) {\n\t\t\tif ( previous ) {\n\t\t\t\tprevious.trigger( 'selection:unsingle', previous, this );\n\n\t\t\t\t// If the model was already removed, trigger the collection\n\t\t\t\t// event manually.\n\t\t\t\tif ( ! this.get( previous.cid ) ) {\n\t\t\t\t\tthis.trigger( 'selection:unsingle', previous, this );\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ( this._single ) {\n\t\t\t\tthis._single.trigger( 'selection:single', this._single, this );\n\t\t\t}\n\t\t}\n\n\t\t// Return the single model, or the last model as a fallback.\n\t\treturn this._single;\n\t}\n});\n\nmodule.exports = Selection;\n\n\n//# sourceURL=webpack:///./src/js/media/models/selection.js?");
/***/ }),
/***/ 2:
/*!***************************************************!*\
!*** multi ./src/js/_enqueues/wp/media/models.js ***!
\***************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
eval("module.exports = __webpack_require__(/*! ./src/js/_enqueues/wp/media/models.js */\"./src/js/_enqueues/wp/media/models.js\");\n\n\n//# sourceURL=webpack:///multi_./src/js/_enqueues/wp/media/models.js?");
/***/ })
/******/ });