Changeset 31379
- Timestamp:
- 02/09/2015 04:13:38 AM (9 years ago)
- Location:
- trunk/src/wp-includes/js/media
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/media/audio-video.js
r31373 r31379 224 224 225 225 }(_)); 226 },{"./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){226 },{"./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){ 227 227 /*globals wp */ 228 228 … … 294 294 */ 295 295 var selectionSync = require( '../utils/selection-sync.js' ), 296 Selection = require( '../models/selection.js' ),297 296 State = require( './state.js' ), 298 297 l10n = wp.media.view.l10n, … … 339 338 } 340 339 341 this.set( 'selection', new Selection( null, {340 this.set( 'selection', new wp.media.model.Selection( null, { 342 341 multiple: this.get('multiple'), 343 342 props: props … … 530 529 531 530 module.exports = Library; 532 },{"../ models/selection.js":13,"../utils/selection-sync.js":14,"./state.js":7}],4:[function(require,module,exports){531 },{"../utils/selection-sync.js":10,"./state.js":7}],4:[function(require,module,exports){ 533 532 /*globals _, wp */ 534 533 … … 1161 1160 module.exports = VideoDetails; 1162 1161 },{"./state.js":7}],9:[function(require,module,exports){ 1163 /*globals jQuery, Backbone, _, wp */1164 1165 /**1166 * wp.media.model.Attachment1167 *1168 * @class1169 * @augments Backbone.Model1170 */1171 var $ = jQuery,1172 Attachment;1173 1174 Attachment = Backbone.Model.extend({1175 /**1176 * Triggered when attachment details change1177 * Overrides Backbone.Model.sync1178 *1179 * @param {string} method1180 * @param {wp.media.model.Attachment} model1181 * @param {Object} [options={}]1182 *1183 * @returns {Promise}1184 */1185 sync: function( method, model, options ) {1186 // If the attachment does not yet have an `id`, return an instantly1187 // rejected promise. Otherwise, all of our requests will fail.1188 if ( _.isUndefined( this.id ) ) {1189 return $.Deferred().rejectWith( this ).promise();1190 }1191 1192 // Overload the `read` request so Attachment.fetch() functions correctly.1193 if ( 'read' === method ) {1194 options = options || {};1195 options.context = this;1196 options.data = _.extend( options.data || {}, {1197 action: 'get-attachment',1198 id: this.id1199 });1200 return wp.media.ajax( options );1201 1202 // Overload the `update` request so properties can be saved.1203 } else if ( 'update' === method ) {1204 // If we do not have the necessary nonce, fail immeditately.1205 if ( ! this.get('nonces') || ! this.get('nonces').update ) {1206 return $.Deferred().rejectWith( this ).promise();1207 }1208 1209 options = options || {};1210 options.context = this;1211 1212 // Set the action and ID.1213 options.data = _.extend( options.data || {}, {1214 action: 'save-attachment',1215 id: this.id,1216 nonce: this.get('nonces').update,1217 post_id: wp.media.model.settings.post.id1218 });1219 1220 // Record the values of the changed attributes.1221 if ( model.hasChanged() ) {1222 options.data.changes = {};1223 1224 _.each( model.changed, function( value, key ) {1225 options.data.changes[ key ] = this.get( key );1226 }, this );1227 }1228 1229 return wp.media.ajax( options );1230 1231 // Overload the `delete` request so attachments can be removed.1232 // This will permanently delete an attachment.1233 } else if ( 'delete' === method ) {1234 options = options || {};1235 1236 if ( ! options.wait ) {1237 this.destroyed = true;1238 }1239 1240 options.context = this;1241 options.data = _.extend( options.data || {}, {1242 action: 'delete-post',1243 id: this.id,1244 _wpnonce: this.get('nonces')['delete']1245 });1246 1247 return wp.media.ajax( options ).done( function() {1248 this.destroyed = true;1249 }).fail( function() {1250 this.destroyed = false;1251 });1252 1253 // Otherwise, fall back to `Backbone.sync()`.1254 } else {1255 /**1256 * Call `sync` directly on Backbone.Model1257 */1258 return Backbone.Model.prototype.sync.apply( this, arguments );1259 }1260 },1261 /**1262 * Convert date strings into Date objects.1263 *1264 * @param {Object} resp The raw response object, typically returned by fetch()1265 * @returns {Object} The modified response object, which is the attributes hash1266 * to be set on the model.1267 */1268 parse: function( resp ) {1269 if ( ! resp ) {1270 return resp;1271 }1272 1273 resp.date = new Date( resp.date );1274 resp.modified = new Date( resp.modified );1275 return resp;1276 },1277 /**1278 * @param {Object} data The properties to be saved.1279 * @param {Object} options Sync options. e.g. patch, wait, success, error.1280 *1281 * @this Backbone.Model1282 *1283 * @returns {Promise}1284 */1285 saveCompat: function( data, options ) {1286 var model = this;1287 1288 // If we do not have the necessary nonce, fail immeditately.1289 if ( ! this.get('nonces') || ! this.get('nonces').update ) {1290 return $.Deferred().rejectWith( this ).promise();1291 }1292 1293 return media.post( 'save-attachment-compat', _.defaults({1294 id: this.id,1295 nonce: this.get('nonces').update,1296 post_id: wp.media.model.settings.post.id1297 }, data ) ).done( function( resp, status, xhr ) {1298 model.set( model.parse( resp, xhr ), options );1299 });1300 }1301 }, {1302 /**1303 * Create a new model on the static 'all' attachments collection and return it.1304 *1305 * @static1306 * @param {Object} attrs1307 * @returns {wp.media.model.Attachment}1308 */1309 create: function( attrs ) {1310 var Attachments = require( './attachments.js' );1311 return Attachments.all.push( attrs );1312 },1313 /**1314 * Create a new model on the static 'all' attachments collection and return it.1315 *1316 * If this function has already been called for the id,1317 * it returns the specified attachment.1318 *1319 * @static1320 * @param {string} id A string used to identify a model.1321 * @param {Backbone.Model|undefined} attachment1322 * @returns {wp.media.model.Attachment}1323 */1324 get: _.memoize( function( id, attachment ) {1325 var Attachments = require( './attachments.js' );1326 return Attachments.all.push( attachment || { id: id } );1327 })1328 });1329 1330 module.exports = Attachment;1331 },{"./attachments.js":10}],10:[function(require,module,exports){1332 /*globals jQuery, Backbone, _, wp */1333 1334 /**1335 * wp.media.model.Attachments1336 *1337 * A collection of attachments.1338 *1339 * This collection has no persistence with the server without supplying1340 * 'options.props.query = true', which will mirror the collection1341 * to an Attachments Query collection - @see wp.media.model.Attachments.mirror().1342 *1343 * @class1344 * @augments Backbone.Collection1345 *1346 * @param {array} [models] Models to initialize with the collection.1347 * @param {object} [options] Options hash for the collection.1348 * @param {string} [options.props] Options hash for the initial query properties.1349 * @param {string} [options.props.order] Initial order (ASC or DESC) for the collection.1350 * @param {string} [options.props.orderby] Initial attribute key to order the collection by.1351 * @param {string} [options.props.query] Whether the collection is linked to an attachments query.1352 * @param {string} [options.observe]1353 * @param {string} [options.filters]1354 *1355 */1356 var Attachment = require( './attachment.js' ),1357 Attachments;1358 1359 Attachments = Backbone.Collection.extend({1360 /**1361 * @type {wp.media.model.Attachment}1362 */1363 model: Attachment,1364 /**1365 * @param {Array} [models=[]] Array of models used to populate the collection.1366 * @param {Object} [options={}]1367 */1368 initialize: function( models, options ) {1369 options = options || {};1370 1371 this.props = new Backbone.Model();1372 this.filters = options.filters || {};1373 1374 // Bind default `change` events to the `props` model.1375 this.props.on( 'change', this._changeFilteredProps, this );1376 1377 this.props.on( 'change:order', this._changeOrder, this );1378 this.props.on( 'change:orderby', this._changeOrderby, this );1379 this.props.on( 'change:query', this._changeQuery, this );1380 1381 this.props.set( _.defaults( options.props || {} ) );1382 1383 if ( options.observe ) {1384 this.observe( options.observe );1385 }1386 },1387 /**1388 * Sort the collection when the order attribute changes.1389 *1390 * @access private1391 */1392 _changeOrder: function() {1393 if ( this.comparator ) {1394 this.sort();1395 }1396 },1397 /**1398 * Set the default comparator only when the `orderby` property is set.1399 *1400 * @access private1401 *1402 * @param {Backbone.Model} model1403 * @param {string} orderby1404 */1405 _changeOrderby: function( model, orderby ) {1406 // If a different comparator is defined, bail.1407 if ( this.comparator && this.comparator !== Attachments.comparator ) {1408 return;1409 }1410 1411 if ( orderby && 'post__in' !== orderby ) {1412 this.comparator = Attachments.comparator;1413 } else {1414 delete this.comparator;1415 }1416 },1417 /**1418 * If the `query` property is set to true, query the server using1419 * the `props` values, and sync the results to this collection.1420 *1421 * @access private1422 *1423 * @param {Backbone.Model} model1424 * @param {Boolean} query1425 */1426 _changeQuery: function( model, query ) {1427 if ( query ) {1428 this.props.on( 'change', this._requery, this );1429 this._requery();1430 } else {1431 this.props.off( 'change', this._requery, this );1432 }1433 },1434 /**1435 * @access private1436 *1437 * @param {Backbone.Model} model1438 */1439 _changeFilteredProps: function( model ) {1440 // If this is a query, updating the collection will be handled by1441 // `this._requery()`.1442 if ( this.props.get('query') ) {1443 return;1444 }1445 1446 var changed = _.chain( model.changed ).map( function( t, prop ) {1447 var filter = Attachments.filters[ prop ],1448 term = model.get( prop );1449 1450 if ( ! filter ) {1451 return;1452 }1453 1454 if ( term && ! this.filters[ prop ] ) {1455 this.filters[ prop ] = filter;1456 } else if ( ! term && this.filters[ prop ] === filter ) {1457 delete this.filters[ prop ];1458 } else {1459 return;1460 }1461 1462 // Record the change.1463 return true;1464 }, this ).any().value();1465 1466 if ( ! changed ) {1467 return;1468 }1469 1470 // If no `Attachments` model is provided to source the searches1471 // from, then automatically generate a source from the existing1472 // models.1473 if ( ! this._source ) {1474 this._source = new Attachments( this.models );1475 }1476 1477 this.reset( this._source.filter( this.validator, this ) );1478 },1479 1480 validateDestroyed: false,1481 /**1482 * Checks whether an attachment is valid.1483 *1484 * @param {wp.media.model.Attachment} attachment1485 * @returns {Boolean}1486 */1487 validator: function( attachment ) {1488 if ( ! this.validateDestroyed && attachment.destroyed ) {1489 return false;1490 }1491 return _.all( this.filters, function( filter ) {1492 return !! filter.call( this, attachment );1493 }, this );1494 },1495 /**1496 * Add or remove an attachment to the collection depending on its validity.1497 *1498 * @param {wp.media.model.Attachment} attachment1499 * @param {Object} options1500 * @returns {wp.media.model.Attachments} Returns itself to allow chaining1501 */1502 validate: function( attachment, options ) {1503 var valid = this.validator( attachment ),1504 hasAttachment = !! this.get( attachment.cid );1505 1506 if ( ! valid && hasAttachment ) {1507 this.remove( attachment, options );1508 } else if ( valid && ! hasAttachment ) {1509 this.add( attachment, options );1510 }1511 1512 return this;1513 },1514 1515 /**1516 * Add or remove all attachments from another collection depending on each one's validity.1517 *1518 * @param {wp.media.model.Attachments} attachments1519 * @param {object} [options={}]1520 *1521 * @fires wp.media.model.Attachments#reset1522 *1523 * @returns {wp.media.model.Attachments} Returns itself to allow chaining1524 */1525 validateAll: function( attachments, options ) {1526 options = options || {};1527 1528 _.each( attachments.models, function( attachment ) {1529 this.validate( attachment, { silent: true });1530 }, this );1531 1532 if ( ! options.silent ) {1533 this.trigger( 'reset', this, options );1534 }1535 return this;1536 },1537 /**1538 * Start observing another attachments collection change events1539 * and replicate them on this collection.1540 *1541 * @param {wp.media.model.Attachments} The attachments collection to observe.1542 * @returns {wp.media.model.Attachments} Returns itself to allow chaining.1543 */1544 observe: function( attachments ) {1545 this.observers = this.observers || [];1546 this.observers.push( attachments );1547 1548 attachments.on( 'add change remove', this._validateHandler, this );1549 attachments.on( 'reset', this._validateAllHandler, this );1550 this.validateAll( attachments );1551 return this;1552 },1553 /**1554 * Stop replicating collection change events from another attachments collection.1555 *1556 * @param {wp.media.model.Attachments} The attachments collection to stop observing.1557 * @returns {wp.media.model.Attachments} Returns itself to allow chaining1558 */1559 unobserve: function( attachments ) {1560 if ( attachments ) {1561 attachments.off( null, null, this );1562 this.observers = _.without( this.observers, attachments );1563 1564 } else {1565 _.each( this.observers, function( attachments ) {1566 attachments.off( null, null, this );1567 }, this );1568 delete this.observers;1569 }1570 1571 return this;1572 },1573 /**1574 * @access private1575 *1576 * @param {wp.media.model.Attachments} attachment1577 * @param {wp.media.model.Attachments} attachments1578 * @param {Object} options1579 *1580 * @returns {wp.media.model.Attachments} Returns itself to allow chaining1581 */1582 _validateHandler: function( attachment, attachments, options ) {1583 // If we're not mirroring this `attachments` collection,1584 // only retain the `silent` option.1585 options = attachments === this.mirroring ? options : {1586 silent: options && options.silent1587 };1588 1589 return this.validate( attachment, options );1590 },1591 /**1592 * @access private1593 *1594 * @param {wp.media.model.Attachments} attachments1595 * @param {Object} options1596 * @returns {wp.media.model.Attachments} Returns itself to allow chaining1597 */1598 _validateAllHandler: function( attachments, options ) {1599 return this.validateAll( attachments, options );1600 },1601 /**1602 * Start mirroring another attachments collection, clearing out any models already1603 * in the collection.1604 *1605 * @param {wp.media.model.Attachments} The attachments collection to mirror.1606 * @returns {wp.media.model.Attachments} Returns itself to allow chaining1607 */1608 mirror: function( attachments ) {1609 if ( this.mirroring && this.mirroring === attachments ) {1610 return this;1611 }1612 1613 this.unmirror();1614 this.mirroring = attachments;1615 1616 // Clear the collection silently. A `reset` event will be fired1617 // when `observe()` calls `validateAll()`.1618 this.reset( [], { silent: true } );1619 this.observe( attachments );1620 1621 return this;1622 },1623 /**1624 * Stop mirroring another attachments collection.1625 */1626 unmirror: function() {1627 if ( ! this.mirroring ) {1628 return;1629 }1630 1631 this.unobserve( this.mirroring );1632 delete this.mirroring;1633 },1634 /**1635 * Retrive more attachments from the server for the collection.1636 *1637 * Only works if the collection is mirroring a Query Attachments collection,1638 * and forwards to its `more` method. This collection class doesn't have1639 * server persistence by itself.1640 *1641 * @param {object} options1642 * @returns {Promise}1643 */1644 more: function( options ) {1645 var deferred = jQuery.Deferred(),1646 mirroring = this.mirroring,1647 attachments = this;1648 1649 if ( ! mirroring || ! mirroring.more ) {1650 return deferred.resolveWith( this ).promise();1651 }1652 // If we're mirroring another collection, forward `more` to1653 // the mirrored collection. Account for a race condition by1654 // checking if we're still mirroring that collection when1655 // the request resolves.1656 mirroring.more( options ).done( function() {1657 if ( this === attachments.mirroring )1658 deferred.resolveWith( this );1659 });1660 1661 return deferred.promise();1662 },1663 /**1664 * Whether there are more attachments that haven't been sync'd from the server1665 * that match the collection's query.1666 *1667 * Only works if the collection is mirroring a Query Attachments collection,1668 * and forwards to its `hasMore` method. This collection class doesn't have1669 * server persistence by itself.1670 *1671 * @returns {boolean}1672 */1673 hasMore: function() {1674 return this.mirroring ? this.mirroring.hasMore() : false;1675 },1676 /**1677 * A custom AJAX-response parser.1678 *1679 * See trac ticket #247531680 *1681 * @param {Object|Array} resp The raw response Object/Array.1682 * @param {Object} xhr1683 * @returns {Array} The array of model attributes to be added to the collection1684 */1685 parse: function( resp, xhr ) {1686 if ( ! _.isArray( resp ) ) {1687 resp = [resp];1688 }1689 1690 return _.map( resp, function( attrs ) {1691 var id, attachment, newAttributes;1692 1693 if ( attrs instanceof Backbone.Model ) {1694 id = attrs.get( 'id' );1695 attrs = attrs.attributes;1696 } else {1697 id = attrs.id;1698 }1699 1700 attachment = Attachment.get( id );1701 newAttributes = attachment.parse( attrs, xhr );1702 1703 if ( ! _.isEqual( attachment.attributes, newAttributes ) ) {1704 attachment.set( newAttributes );1705 }1706 1707 return attachment;1708 });1709 },1710 /**1711 * If the collection is a query, create and mirror an Attachments Query collection.1712 *1713 * @access private1714 */1715 _requery: function( refresh ) {1716 var props, Query;1717 if ( this.props.get('query') ) {1718 Query = require( './query.js' );1719 props = this.props.toJSON();1720 props.cache = ( true !== refresh );1721 this.mirror( Query.get( props ) );1722 }1723 },1724 /**1725 * If this collection is sorted by `menuOrder`, recalculates and saves1726 * the menu order to the database.1727 *1728 * @returns {undefined|Promise}1729 */1730 saveMenuOrder: function() {1731 if ( 'menuOrder' !== this.props.get('orderby') ) {1732 return;1733 }1734 1735 // Removes any uploading attachments, updates each attachment's1736 // menu order, and returns an object with an { id: menuOrder }1737 // mapping to pass to the request.1738 var attachments = this.chain().filter( function( attachment ) {1739 return ! _.isUndefined( attachment.id );1740 }).map( function( attachment, index ) {1741 // Indices start at 1.1742 index = index + 1;1743 attachment.set( 'menuOrder', index );1744 return [ attachment.id, index ];1745 }).object().value();1746 1747 if ( _.isEmpty( attachments ) ) {1748 return;1749 }1750 1751 return wp.media.post( 'save-attachment-order', {1752 nonce: wp.media.model.settings.post.nonce,1753 post_id: wp.media.model.settings.post.id,1754 attachments: attachments1755 });1756 }1757 }, {1758 /**1759 * A function to compare two attachment models in an attachments collection.1760 *1761 * Used as the default comparator for instances of wp.media.model.Attachments1762 * and its subclasses. @see wp.media.model.Attachments._changeOrderby().1763 *1764 * @static1765 *1766 * @param {Backbone.Model} a1767 * @param {Backbone.Model} b1768 * @param {Object} options1769 * @returns {Number} -1 if the first model should come before the second,1770 * 0 if they are of the same rank and1771 * 1 if the first model should come after.1772 */1773 comparator: function( a, b, options ) {1774 var key = this.props.get('orderby'),1775 order = this.props.get('order') || 'DESC',1776 ac = a.cid,1777 bc = b.cid;1778 1779 a = a.get( key );1780 b = b.get( key );1781 1782 if ( 'date' === key || 'modified' === key ) {1783 a = a || new Date();1784 b = b || new Date();1785 }1786 1787 // If `options.ties` is set, don't enforce the `cid` tiebreaker.1788 if ( options && options.ties ) {1789 ac = bc = null;1790 }1791 1792 return ( 'DESC' === order ) ? wp.media.compare( a, b, ac, bc ) : wp.media.compare( b, a, bc, ac );1793 },1794 /**1795 * @namespace1796 */1797 filters: {1798 /**1799 * @static1800 * Note that this client-side searching is *not* equivalent1801 * to our server-side searching.1802 *1803 * @param {wp.media.model.Attachment} attachment1804 *1805 * @this wp.media.model.Attachments1806 *1807 * @returns {Boolean}1808 */1809 search: function( attachment ) {1810 if ( ! this.props.get('search') ) {1811 return true;1812 }1813 1814 return _.any(['title','filename','description','caption','name'], function( key ) {1815 var value = attachment.get( key );1816 return value && -1 !== value.search( this.props.get('search') );1817 }, this );1818 },1819 /**1820 * @static1821 * @param {wp.media.model.Attachment} attachment1822 *1823 * @this wp.media.model.Attachments1824 *1825 * @returns {Boolean}1826 */1827 type: function( attachment ) {1828 var type = this.props.get('type');1829 return ! type || -1 !== type.indexOf( attachment.get('type') );1830 },1831 /**1832 * @static1833 * @param {wp.media.model.Attachment} attachment1834 *1835 * @this wp.media.model.Attachments1836 *1837 * @returns {Boolean}1838 */1839 uploadedTo: function( attachment ) {1840 var uploadedTo = this.props.get('uploadedTo');1841 if ( _.isUndefined( uploadedTo ) ) {1842 return true;1843 }1844 1845 return uploadedTo === attachment.get('uploadedTo');1846 },1847 /**1848 * @static1849 * @param {wp.media.model.Attachment} attachment1850 *1851 * @this wp.media.model.Attachments1852 *1853 * @returns {Boolean}1854 */1855 status: function( attachment ) {1856 var status = this.props.get('status');1857 if ( _.isUndefined( status ) ) {1858 return true;1859 }1860 1861 return status === attachment.get('status');1862 }1863 }1864 });1865 1866 module.exports = Attachments;1867 },{"./attachment.js":9,"./query.js":12}],11:[function(require,module,exports){1868 1162 /*globals Backbone, _, wp */ 1869 1163 … … 1908 1202 1909 1203 module.exports = PostMedia; 1910 },{}],12:[function(require,module,exports){ 1911 /*globals jQuery, _, wp */ 1912 1913 /** 1914 * wp.media.model.Query 1915 * 1916 * A collection of attachments that match the supplied query arguments. 1917 * 1918 * Note: Do NOT change this.args after the query has been initialized. 1919 * Things will break. 1920 * 1921 * @class 1922 * @augments wp.media.model.Attachments 1923 * @augments Backbone.Collection 1924 * 1925 * @param {array} [models] Models to initialize with the collection. 1926 * @param {object} [options] Options hash. 1927 * @param {object} [options.args] Attachments query arguments. 1928 * @param {object} [options.args.posts_per_page] 1929 */ 1930 var Attachments = require( './attachments.js' ), 1931 Query; 1932 1933 Query = Attachments.extend({ 1934 /** 1935 * @global wp.Uploader 1936 * 1937 * @param {array} [models=[]] Array of initial models to populate the collection. 1938 * @param {object} [options={}] 1939 */ 1940 initialize: function( models, options ) { 1941 var allowed; 1942 1943 options = options || {}; 1944 Attachments.prototype.initialize.apply( this, arguments ); 1945 1946 this.args = options.args; 1947 this._hasMore = true; 1948 this.created = new Date(); 1949 1950 this.filters.order = function( attachment ) { 1951 var orderby = this.props.get('orderby'), 1952 order = this.props.get('order'); 1953 1954 if ( ! this.comparator ) { 1955 return true; 1956 } 1957 1958 // We want any items that can be placed before the last 1959 // item in the set. If we add any items after the last 1960 // item, then we can't guarantee the set is complete. 1961 if ( this.length ) { 1962 return 1 !== this.comparator( attachment, this.last(), { ties: true }); 1963 1964 // Handle the case where there are no items yet and 1965 // we're sorting for recent items. In that case, we want 1966 // changes that occurred after we created the query. 1967 } else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) { 1968 return attachment.get( orderby ) >= this.created; 1969 1970 // If we're sorting by menu order and we have no items, 1971 // accept any items that have the default menu order (0). 1972 } else if ( 'ASC' === order && 'menuOrder' === orderby ) { 1973 return attachment.get( orderby ) === 0; 1974 } 1975 1976 // Otherwise, we don't want any items yet. 1977 return false; 1978 }; 1979 1980 // Observe the central `wp.Uploader.queue` collection to watch for 1981 // new matches for the query. 1982 // 1983 // Only observe when a limited number of query args are set. There 1984 // are no filters for other properties, so observing will result in 1985 // false positives in those queries. 1986 allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent' ]; 1987 if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) { 1988 this.observe( wp.Uploader.queue ); 1989 } 1990 }, 1991 /** 1992 * Whether there are more attachments that haven't been sync'd from the server 1993 * that match the collection's query. 1994 * 1995 * @returns {boolean} 1996 */ 1997 hasMore: function() { 1998 return this._hasMore; 1999 }, 2000 /** 2001 * Fetch more attachments from the server for the collection. 2002 * 2003 * @param {object} [options={}] 2004 * @returns {Promise} 2005 */ 2006 more: function( options ) { 2007 var query = this; 2008 2009 // If there is already a request pending, return early with the Deferred object. 2010 if ( this._more && 'pending' === this._more.state() ) { 2011 return this._more; 2012 } 2013 2014 if ( ! this.hasMore() ) { 2015 return jQuery.Deferred().resolveWith( this ).promise(); 2016 } 2017 2018 options = options || {}; 2019 options.remove = false; 2020 2021 return this._more = this.fetch( options ).done( function( resp ) { 2022 if ( _.isEmpty( resp ) || -1 === this.args.posts_per_page || resp.length < this.args.posts_per_page ) { 2023 query._hasMore = false; 2024 } 2025 }); 2026 }, 2027 /** 2028 * Overrides Backbone.Collection.sync 2029 * Overrides wp.media.model.Attachments.sync 2030 * 2031 * @param {String} method 2032 * @param {Backbone.Model} model 2033 * @param {Object} [options={}] 2034 * @returns {Promise} 2035 */ 2036 sync: function( method, model, options ) { 2037 var args, fallback; 2038 2039 // Overload the read method so Attachment.fetch() functions correctly. 2040 if ( 'read' === method ) { 2041 options = options || {}; 2042 options.context = this; 2043 options.data = _.extend( options.data || {}, { 2044 action: 'query-attachments', 2045 post_id: wp.media.model.settings.post.id 2046 }); 2047 2048 // Clone the args so manipulation is non-destructive. 2049 args = _.clone( this.args ); 2050 2051 // Determine which page to query. 2052 if ( -1 !== args.posts_per_page ) { 2053 args.paged = Math.floor( this.length / args.posts_per_page ) + 1; 2054 } 2055 2056 options.data.query = args; 2057 return wp.media.ajax( options ); 2058 2059 // Otherwise, fall back to Backbone.sync() 2060 } else { 2061 /** 2062 * Call wp.media.model.Attachments.sync or Backbone.sync 2063 */ 2064 fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone; 2065 return fallback.sync.apply( this, arguments ); 2066 } 2067 } 2068 }, { 2069 /** 2070 * @readonly 2071 */ 2072 defaultProps: { 2073 orderby: 'date', 2074 order: 'DESC' 2075 }, 2076 /** 2077 * @readonly 2078 */ 2079 defaultArgs: { 2080 posts_per_page: 40 2081 }, 2082 /** 2083 * @readonly 2084 */ 2085 orderby: { 2086 allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ], 2087 /** 2088 * A map of JavaScript orderby values to their WP_Query equivalents. 2089 * @type {Object} 2090 */ 2091 valuemap: { 2092 'id': 'ID', 2093 'uploadedTo': 'parent', 2094 'menuOrder': 'menu_order ID' 2095 } 2096 }, 2097 /** 2098 * A map of JavaScript query properties to their WP_Query equivalents. 2099 * 2100 * @readonly 2101 */ 2102 propmap: { 2103 'search': 's', 2104 'type': 'post_mime_type', 2105 'perPage': 'posts_per_page', 2106 'menuOrder': 'menu_order', 2107 'uploadedTo': 'post_parent', 2108 'status': 'post_status', 2109 'include': 'post__in', 2110 'exclude': 'post__not_in' 2111 }, 2112 /** 2113 * Creates and returns an Attachments Query collection given the properties. 2114 * 2115 * Caches query objects and reuses where possible. 2116 * 2117 * @static 2118 * @method 2119 * 2120 * @param {object} [props] 2121 * @param {Object} [props.cache=true] Whether to use the query cache or not. 2122 * @param {Object} [props.order] 2123 * @param {Object} [props.orderby] 2124 * @param {Object} [props.include] 2125 * @param {Object} [props.exclude] 2126 * @param {Object} [props.s] 2127 * @param {Object} [props.post_mime_type] 2128 * @param {Object} [props.posts_per_page] 2129 * @param {Object} [props.menu_order] 2130 * @param {Object} [props.post_parent] 2131 * @param {Object} [props.post_status] 2132 * @param {Object} [options] 2133 * 2134 * @returns {wp.media.model.Query} A new Attachments Query collection. 2135 */ 2136 get: (function(){ 2137 /** 2138 * @static 2139 * @type Array 2140 */ 2141 var queries = []; 2142 2143 /** 2144 * @returns {Query} 2145 */ 2146 return function( props, options ) { 2147 var args = {}, 2148 orderby = Query.orderby, 2149 defaults = Query.defaultProps, 2150 query, 2151 cache = !! props.cache || _.isUndefined( props.cache ); 2152 2153 // Remove the `query` property. This isn't linked to a query, 2154 // this *is* the query. 2155 delete props.query; 2156 delete props.cache; 2157 2158 // Fill default args. 2159 _.defaults( props, defaults ); 2160 2161 // Normalize the order. 2162 props.order = props.order.toUpperCase(); 2163 if ( 'DESC' !== props.order && 'ASC' !== props.order ) { 2164 props.order = defaults.order.toUpperCase(); 2165 } 2166 2167 // Ensure we have a valid orderby value. 2168 if ( ! _.contains( orderby.allowed, props.orderby ) ) { 2169 props.orderby = defaults.orderby; 2170 } 2171 2172 _.each( [ 'include', 'exclude' ], function( prop ) { 2173 if ( props[ prop ] && ! _.isArray( props[ prop ] ) ) { 2174 props[ prop ] = [ props[ prop ] ]; 2175 } 2176 } ); 2177 2178 // Generate the query `args` object. 2179 // Correct any differing property names. 2180 _.each( props, function( value, prop ) { 2181 if ( _.isNull( value ) ) { 2182 return; 2183 } 2184 2185 args[ Query.propmap[ prop ] || prop ] = value; 2186 }); 2187 2188 // Fill any other default query args. 2189 _.defaults( args, Query.defaultArgs ); 2190 2191 // `props.orderby` does not always map directly to `args.orderby`. 2192 // Substitute exceptions specified in orderby.keymap. 2193 args.orderby = orderby.valuemap[ props.orderby ] || props.orderby; 2194 2195 // Search the query cache for a matching query. 2196 if ( cache ) { 2197 query = _.find( queries, function( query ) { 2198 return _.isEqual( query.args, args ); 2199 }); 2200 } else { 2201 queries = []; 2202 } 2203 2204 // Otherwise, create a new query and add it to the cache. 2205 if ( ! query ) { 2206 query = new Query( [], _.extend( options || {}, { 2207 props: props, 2208 args: args 2209 } ) ); 2210 queries.push( query ); 2211 } 2212 2213 return query; 2214 }; 2215 }()) 2216 }); 2217 2218 module.exports = Query; 2219 },{"./attachments.js":10}],13:[function(require,module,exports){ 2220 /*globals _ */ 2221 2222 /** 2223 * wp.media.model.Selection 2224 * 2225 * A selection of attachments. 2226 * 2227 * @class 2228 * @augments wp.media.model.Attachments 2229 * @augments Backbone.Collection 2230 */ 2231 var Attachments = require( './attachments.js' ), 2232 Selection; 2233 2234 Selection = Attachments.extend({ 2235 /** 2236 * Refresh the `single` model whenever the selection changes. 2237 * Binds `single` instead of using the context argument to ensure 2238 * it receives no parameters. 2239 * 2240 * @param {Array} [models=[]] Array of models used to populate the collection. 2241 * @param {Object} [options={}] 2242 */ 2243 initialize: function( models, options ) { 2244 /** 2245 * call 'initialize' directly on the parent class 2246 */ 2247 Attachments.prototype.initialize.apply( this, arguments ); 2248 this.multiple = options && options.multiple; 2249 2250 this.on( 'add remove reset', _.bind( this.single, this, false ) ); 2251 }, 2252 2253 /** 2254 * If the workflow does not support multi-select, clear out the selection 2255 * before adding a new attachment to it. 2256 * 2257 * @param {Array} models 2258 * @param {Object} options 2259 * @returns {wp.media.model.Attachment[]} 2260 */ 2261 add: function( models, options ) { 2262 if ( ! this.multiple ) { 2263 this.remove( this.models ); 2264 } 2265 /** 2266 * call 'add' directly on the parent class 2267 */ 2268 return Attachments.prototype.add.call( this, models, options ); 2269 }, 2270 2271 /** 2272 * Fired when toggling (clicking on) an attachment in the modal. 2273 * 2274 * @param {undefined|boolean|wp.media.model.Attachment} model 2275 * 2276 * @fires wp.media.model.Selection#selection:single 2277 * @fires wp.media.model.Selection#selection:unsingle 2278 * 2279 * @returns {Backbone.Model} 2280 */ 2281 single: function( model ) { 2282 var previous = this._single; 2283 2284 // If a `model` is provided, use it as the single model. 2285 if ( model ) { 2286 this._single = model; 2287 } 2288 // If the single model isn't in the selection, remove it. 2289 if ( this._single && ! this.get( this._single.cid ) ) { 2290 delete this._single; 2291 } 2292 2293 this._single = this._single || this.last(); 2294 2295 // If single has changed, fire an event. 2296 if ( this._single !== previous ) { 2297 if ( previous ) { 2298 previous.trigger( 'selection:unsingle', previous, this ); 2299 2300 // If the model was already removed, trigger the collection 2301 // event manually. 2302 if ( ! this.get( previous.cid ) ) { 2303 this.trigger( 'selection:unsingle', previous, this ); 2304 } 2305 } 2306 if ( this._single ) { 2307 this._single.trigger( 'selection:single', this._single, this ); 2308 } 2309 } 2310 2311 // Return the single model, or the last model as a fallback. 2312 return this._single; 2313 } 2314 }); 2315 2316 module.exports = Selection; 2317 },{"./attachments.js":10}],14:[function(require,module,exports){ 1204 },{}],10:[function(require,module,exports){ 2318 1205 /*globals _ */ 2319 1206 … … 2382 1269 2383 1270 module.exports = selectionSync; 2384 },{}],1 5:[function(require,module,exports){1271 },{}],11:[function(require,module,exports){ 2385 1272 /*globals _ */ 2386 1273 … … 2468 1355 2469 1356 module.exports = AttachmentCompat; 2470 },{"./view.js":5 5}],16:[function(require,module,exports){1357 },{"./view.js":51}],12:[function(require,module,exports){ 2471 1358 /*globals _, jQuery */ 2472 1359 … … 2547 1434 2548 1435 module.exports = AttachmentFilters; 2549 },{"./view.js":5 5}],17:[function(require,module,exports){1436 },{"./view.js":51}],13:[function(require,module,exports){ 2550 1437 /*globals _, wp */ 2551 1438 … … 2639 1526 2640 1527 module.exports = All; 2641 },{"../attachment-filters.js":1 6}],18:[function(require,module,exports){1528 },{"../attachment-filters.js":12}],14:[function(require,module,exports){ 2642 1529 /*globals _, wp */ 2643 1530 … … 2682 1569 2683 1570 module.exports = DateFilter; 2684 },{"../attachment-filters.js":1 6}],19:[function(require,module,exports){1571 },{"../attachment-filters.js":12}],15:[function(require,module,exports){ 2685 1572 /*globals wp */ 2686 1573 … … 2743 1630 2744 1631 module.exports = Uploaded; 2745 },{"../attachment-filters.js":1 6}],20:[function(require,module,exports){1632 },{"../attachment-filters.js":12}],16:[function(require,module,exports){ 2746 1633 /*globals _, wp, jQuery */ 2747 1634 … … 3298 2185 3299 2186 module.exports = Attachment; 3300 },{"./view.js":5 5}],21:[function(require,module,exports){2187 },{"./view.js":51}],17:[function(require,module,exports){ 3301 2188 /*globals _, wp */ 3302 2189 … … 3439 2326 3440 2327 module.exports = Details; 3441 },{"../attachment.js": 20}],22:[function(require,module,exports){2328 },{"../attachment.js":16}],18:[function(require,module,exports){ 3442 2329 /** 3443 2330 * wp.media.view.Attachment.Library … … 3459 2346 3460 2347 module.exports = Library; 3461 },{"../attachment.js": 20}],23:[function(require,module,exports){2348 },{"../attachment.js":16}],19:[function(require,module,exports){ 3462 2349 /*globals _, wp, jQuery */ 3463 2350 … … 3760 2647 3761 2648 module.exports = Attachments; 3762 },{"./attachment.js": 20,"./view.js":55}],24:[function(require,module,exports){2649 },{"./attachment.js":16,"./view.js":51}],20:[function(require,module,exports){ 3763 2650 /*globals _, wp, jQuery */ 3764 2651 … … 4220 3107 4221 3108 module.exports = AttachmentsBrowser; 4222 },{"../attachment-compat.js":1 5,"../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){3109 },{"../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){ 4223 3110 /*globals wp */ 4224 3111 … … 4259 3146 4260 3147 module.exports = AudioDetails; 4261 },{"./media-details":3 5}],26:[function(require,module,exports){3148 },{"./media-details":31}],22:[function(require,module,exports){ 4262 3149 /*globals _, Backbone */ 4263 3150 … … 4349 3236 4350 3237 module.exports = Button; 4351 },{"./view.js":5 5}],27:[function(require,module,exports){3238 },{"./view.js":51}],23:[function(require,module,exports){ 4352 3239 /** 4353 3240 * wp.media.view.FocusManager … … 4397 3284 4398 3285 module.exports = FocusManager; 4399 },{"./view.js":5 5}],28:[function(require,module,exports){3286 },{"./view.js":51}],24:[function(require,module,exports){ 4400 3287 /*globals _, Backbone */ 4401 3288 … … 4570 3457 4571 3458 module.exports = Frame; 4572 },{"../controllers/region.js":5,"../controllers/state-machine.js":6,"../controllers/state.js":7,"./view.js":5 5}],29:[function(require,module,exports){3459 },{"../controllers/region.js":5,"../controllers/state-machine.js":6,"../controllers/state.js":7,"./view.js":51}],25:[function(require,module,exports){ 4573 3460 /*globals wp */ 4574 3461 … … 4648 3535 4649 3536 module.exports = AudioDetails; 4650 },{"../../controllers/audio-details.js":2,"../../controllers/media-library.js":4,"../audio-details.js":2 5,"./media-details":30}],30:[function(require,module,exports){3537 },{"../../controllers/audio-details.js":2,"../../controllers/media-library.js":4,"../audio-details.js":21,"./media-details":26}],26:[function(require,module,exports){ 4651 3538 /*globals wp */ 4652 3539 … … 4666 3553 Toolbar = require( '../toolbar.js' ), 4667 3554 Select = require( './select.js' ), 4668 Selection = require( '../../models/selection.js' ),4669 PostMedia = require( '../../models/post-media.js' ),4670 3555 l10n = wp.media.view.l10n, 4671 3556 MediaDetails; … … 4687 3572 this.addText = options.addText; 4688 3573 4689 this.media = new PostMedia( options.metadata );4690 this.options.selection = new Selection( this.media.attachment, { multiple: false } );3574 this.media = new wp.media.model.PostMedia( options.metadata ); 3575 this.options.selection = new wp.media.model.Selection( this.media.attachment, { multiple: false } ); 4691 3576 Select.prototype.initialize.apply( this, arguments ); 4692 3577 }, … … 4783 3668 4784 3669 module.exports = MediaDetails; 4785 },{"../ ../models/post-media.js":11,"../../models/selection.js":13,"../toolbar.js":48,"../view.js":55,"./select.js":31}],31:[function(require,module,exports){3670 },{"../toolbar.js":44,"../view.js":51,"./select.js":27}],27:[function(require,module,exports){ 4786 3671 /*globals _, wp */ 4787 3672 … … 4802 3687 var MediaFrame = require( '../media-frame.js' ), 4803 3688 Library = require( '../../controllers/library.js' ), 4804 AttachmentsModel = require( '../../models/attachments.js' ),4805 SelectionModel = require( '../../models/selection.js' ),4806 3689 AttachmentsBrowser = require( '../attachments/browser.js' ), 4807 3690 UploaderInline = require( '../uploader/inline.js' ), … … 4839 3722 var selection = this.options.selection; 4840 3723 4841 if ( ! (selection instanceof SelectionModel) ) {4842 this.options.selection = new SelectionModel( selection, {3724 if ( ! (selection instanceof wp.media.model.Selection) ) { 3725 this.options.selection = new wp.media.model.Selection( selection, { 4843 3726 multiple: this.options.multiple 4844 3727 }); … … 4846 3729 4847 3730 this._selection = { 4848 attachments: new AttachmentsModel(),3731 attachments: new wp.media.model.Attachments(), 4849 3732 difference: [] 4850 3733 }; … … 4960 3843 4961 3844 module.exports = Select; 4962 },{"../../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){3845 },{"../../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){ 4963 3846 /*globals _, wp */ 4964 3847 … … 5098 3981 5099 3982 module.exports = VideoDetails; 5100 },{"../../controllers/media-library.js":4,"../../controllers/video-details.js":8,"../video-details.js":5 4,"./media-details":30}],33:[function(require,module,exports){3983 },{"../../controllers/media-library.js":4,"../../controllers/video-details.js":8,"../video-details.js":50,"./media-details":26}],29:[function(require,module,exports){ 5101 3984 /** 5102 3985 * wp.media.view.Iframe … … 5124 4007 5125 4008 module.exports = Iframe; 5126 },{"./view.js":5 5}],34:[function(require,module,exports){4009 },{"./view.js":51}],30:[function(require,module,exports){ 5127 4010 /** 5128 4011 * @class … … 5150 4033 5151 4034 module.exports = Label; 5152 },{"./view.js":5 5}],35:[function(require,module,exports){4035 },{"./view.js":51}],31:[function(require,module,exports){ 5153 4036 /*globals _, wp, jQuery */ 5154 4037 … … 5302 4185 5303 4186 module.exports = MediaDetails; 5304 },{"./settings/attachment-display.js":4 5}],36:[function(require,module,exports){4187 },{"./settings/attachment-display.js":41}],32:[function(require,module,exports){ 5305 4188 /*globals _, wp, jQuery */ 5306 4189 … … 5557 4440 5558 4441 module.exports = MediaFrame; 5559 },{"./frame.js":2 8,"./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){4442 },{"./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){ 5560 4443 /*globals wp, jQuery */ 5561 4444 … … 5631 4514 5632 4515 module.exports = MenuItem; 5633 },{"./view.js":5 5}],38:[function(require,module,exports){4516 },{"./view.js":51}],34:[function(require,module,exports){ 5634 4517 /** 5635 4518 * wp.media.view.Menu … … 5747 4630 5748 4631 module.exports = Menu; 5749 },{"./menu-item.js":3 7,"./priority-list.js":40}],39:[function(require,module,exports){4632 },{"./menu-item.js":33,"./priority-list.js":36}],35:[function(require,module,exports){ 5750 4633 /*globals _, wp, jQuery */ 5751 4634 … … 5963 4846 5964 4847 module.exports = Modal; 5965 },{"./focus-manager.js":2 7,"./view.js":55}],40:[function(require,module,exports){4848 },{"./focus-manager.js":23,"./view.js":51}],36:[function(require,module,exports){ 5966 4849 /*globals _, Backbone */ 5967 4850 … … 6064 4947 6065 4948 module.exports = PriorityList; 6066 },{"./view.js":5 5}],41:[function(require,module,exports){4949 },{"./view.js":51}],37:[function(require,module,exports){ 6067 4950 /** 6068 4951 * wp.media.view.RouterItem … … 6090 4973 6091 4974 module.exports = RouterItem; 6092 },{"./menu-item.js":3 7}],42:[function(require,module,exports){4975 },{"./menu-item.js":33}],38:[function(require,module,exports){ 6093 4976 /** 6094 4977 * wp.media.view.Router … … 6127 5010 6128 5011 module.exports = Router; 6129 },{"./menu.js":3 8,"./router-item.js":41}],43:[function(require,module,exports){5012 },{"./menu.js":34,"./router-item.js":37}],39:[function(require,module,exports){ 6130 5013 /*globals wp */ 6131 5014 … … 6177 5060 6178 5061 module.exports = Search; 6179 },{"./view.js":5 5}],44:[function(require,module,exports){5062 },{"./view.js":51}],40:[function(require,module,exports){ 6180 5063 /*globals _, Backbone, jQuery */ 6181 5064 … … 6299 5182 6300 5183 module.exports = Settings; 6301 },{"./view.js":5 5}],45:[function(require,module,exports){5184 },{"./view.js":51}],41:[function(require,module,exports){ 6302 5185 /*globals _, wp */ 6303 5186 … … 6394 5277 6395 5278 module.exports = AttachmentDisplay; 6396 },{"../settings.js":4 4}],46:[function(require,module,exports){5279 },{"../settings.js":40}],42:[function(require,module,exports){ 6397 5280 /** 6398 5281 * wp.media.view.Sidebar … … 6412 5295 6413 5296 module.exports = Sidebar; 6414 },{"./priority-list.js": 40}],47:[function(require,module,exports){5297 },{"./priority-list.js":36}],43:[function(require,module,exports){ 6415 5298 /*globals _, wp */ 6416 5299 … … 6451 5334 6452 5335 module.exports = Spinner; 6453 },{"./view.js":5 5}],48:[function(require,module,exports){5336 },{"./view.js":51}],44:[function(require,module,exports){ 6454 5337 /*globals Backbone, _ */ 6455 5338 … … 6614 5497 6615 5498 module.exports = Toolbar; 6616 },{"./button.js":2 6,"./priority-list.js":40,"./view.js":55}],49:[function(require,module,exports){5499 },{"./button.js":22,"./priority-list.js":36,"./view.js":51}],45:[function(require,module,exports){ 6617 5500 /*globals _, wp */ 6618 5501 … … 6685 5568 6686 5569 module.exports = Select; 6687 },{"../toolbar.js":4 8}],50:[function(require,module,exports){5570 },{"../toolbar.js":44}],46:[function(require,module,exports){ 6688 5571 /*globals _, wp */ 6689 5572 … … 6818 5701 6819 5702 module.exports = UploaderInline; 6820 },{"../view.js":5 5,"./status.js":52}],51:[function(require,module,exports){5703 },{"../view.js":51,"./status.js":48}],47:[function(require,module,exports){ 6821 5704 /*globals wp */ 6822 5705 … … 6838 5721 6839 5722 module.exports = UploaderStatusError; 6840 },{"../view.js":5 5}],52:[function(require,module,exports){5723 },{"../view.js":51}],48:[function(require,module,exports){ 6841 5724 /*globals _, wp */ 6842 5725 … … 6978 5861 6979 5862 module.exports = UploaderStatus; 6980 },{"../view.js":5 5,"./status-error.js":51}],53:[function(require,module,exports){5863 },{"../view.js":51,"./status-error.js":47}],49:[function(require,module,exports){ 6981 5864 /*globals _, wp, jQuery */ 6982 5865 … … 7091 5974 7092 5975 module.exports = UploaderWindow; 7093 },{"../view.js":5 5}],54:[function(require,module,exports){5976 },{"../view.js":51}],50:[function(require,module,exports){ 7094 5977 /*globals wp */ 7095 5978 … … 7135 6018 7136 6019 module.exports = VideoDetails; 7137 },{"./media-details":3 5}],55:[function(require,module,exports){6020 },{"./media-details":31}],51:[function(require,module,exports){ 7138 6021 /*globals wp */ 7139 6022 -
trunk/src/wp-includes/js/media/controllers/collection-add.js
r31373 r31379 34 34 * @param {string} attributes.collectionType The collection type. (e.g. 'playlist'). 35 35 */ 36 var Selection = require( '../models/selection.js' ),36 var Selection = wp.media.model.Selection, 37 37 Library = require( './library.js' ), 38 38 CollectionAdd; -
trunk/src/wp-includes/js/media/controllers/collection-edit.js
r31373 r31379 35 35 * @param {string} attributes.collectionType The collection type. (e.g. 'playlist'). 36 36 */ 37 var Selection = require( '../models/selection.js' ), 38 Library = require( './library.js' ), 37 var Library = require( './library.js' ), 39 38 View = require( '../views/view.js' ), 40 39 EditLibraryView = require( '../views/attachment/edit-library.js' ), … … 73 72 // If we haven't been provided a `library`, create a `Selection`. 74 73 if ( ! this.get('library') ) { 75 this.set( 'library', new Selection() );74 this.set( 'library', new wp.media.model.Selection() ); 76 75 } 77 76 // The single `Attachment` view to be used in the `Attachments` view. -
trunk/src/wp-includes/js/media/controllers/featured-image.js
r31373 r31379 32 32 * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state. 33 33 */ 34 var Attachment = require( '../models/attachment.js' ),34 var Attachment = wp.media.model.Attachment, 35 35 Library = require( './library.js' ), 36 36 l10n = wp.media.view.l10n, -
trunk/src/wp-includes/js/media/controllers/gallery-add.js
r31373 r31379 30 30 * Defaults to false because for this state, because the library of the Edit Gallery state is the selection. 31 31 */ 32 var Selection = require( '../models/selection.js' ),32 var Selection = wp.media.model.Selection, 33 33 Library = require( './library.js' ), 34 34 l10n = wp.media.view.l10n, -
trunk/src/wp-includes/js/media/controllers/gallery-edit.js
r31373 r31379 32 32 * If none supplied, defaults to wp.media.view.Attachment.EditLibrary. 33 33 */ 34 var Selection = require( '../models/selection.js' ), 35 Library = require( './library.js' ), 34 var Library = require( './library.js' ), 36 35 EditLibraryView = require( '../views/attachment/edit-library.js' ), 37 36 GallerySettingsView = require( '../views/settings/gallery.js' ), … … 64 63 // If we haven't been provided a `library`, create a `Selection`. 65 64 if ( ! this.get('library') ) 66 this.set( 'library', new Selection() );65 this.set( 'library', new wp.media.model.Selection() ); 67 66 68 67 // The single `Attachment` view to be used in the `Attachments` view. -
trunk/src/wp-includes/js/media/controllers/library.js
r31373 r31379 36 36 */ 37 37 var selectionSync = require( '../utils/selection-sync.js' ), 38 Selection = require( '../models/selection.js' ),39 38 State = require( './state.js' ), 40 39 l10n = wp.media.view.l10n, … … 81 80 } 82 81 83 this.set( 'selection', new Selection( null, {82 this.set( 'selection', new wp.media.model.Selection( null, { 84 83 multiple: this.get('multiple'), 85 84 props: props -
trunk/src/wp-includes/js/media/grid.js
r31373 r31379 108 108 109 109 module.exports = EditImage; 110 },{"../views/toolbar.js": 50,"./state.js":6}],3:[function(require,module,exports){110 },{"../views/toolbar.js":46,"./state.js":6}],3:[function(require,module,exports){ 111 111 /*globals _, wp, Backbone, getUserSetting, setUserSetting */ 112 112 … … 146 146 */ 147 147 var selectionSync = require( '../utils/selection-sync.js' ), 148 Selection = require( '../models/selection.js' ),149 148 State = require( './state.js' ), 150 149 l10n = wp.media.view.l10n, … … 191 190 } 192 191 193 this.set( 'selection', new Selection( null, {192 this.set( 'selection', new wp.media.model.Selection( null, { 194 193 multiple: this.get('multiple'), 195 194 props: props … … 382 381 383 382 module.exports = Library; 384 },{"../ models/selection.js":11,"../utils/selection-sync.js":13,"./state.js":6}],4:[function(require,module,exports){383 },{"../utils/selection-sync.js":9,"./state.js":6}],4:[function(require,module,exports){ 385 384 /*globals _, Backbone */ 386 385 … … 945 944 946 945 }(wp)); 947 },{"./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){ 948 /*globals jQuery, Backbone, _, wp */ 949 950 /** 951 * wp.media.model.Attachment 952 * 953 * @class 954 * @augments Backbone.Model 955 */ 956 var $ = jQuery, 957 Attachment; 958 959 Attachment = Backbone.Model.extend({ 960 /** 961 * Triggered when attachment details change 962 * Overrides Backbone.Model.sync 963 * 964 * @param {string} method 965 * @param {wp.media.model.Attachment} model 966 * @param {Object} [options={}] 967 * 968 * @returns {Promise} 969 */ 970 sync: function( method, model, options ) { 971 // If the attachment does not yet have an `id`, return an instantly 972 // rejected promise. Otherwise, all of our requests will fail. 973 if ( _.isUndefined( this.id ) ) { 974 return $.Deferred().rejectWith( this ).promise(); 975 } 976 977 // Overload the `read` request so Attachment.fetch() functions correctly. 978 if ( 'read' === method ) { 979 options = options || {}; 980 options.context = this; 981 options.data = _.extend( options.data || {}, { 982 action: 'get-attachment', 983 id: this.id 984 }); 985 return wp.media.ajax( options ); 986 987 // Overload the `update` request so properties can be saved. 988 } else if ( 'update' === method ) { 989 // If we do not have the necessary nonce, fail immeditately. 990 if ( ! this.get('nonces') || ! this.get('nonces').update ) { 991 return $.Deferred().rejectWith( this ).promise(); 992 } 993 994 options = options || {}; 995 options.context = this; 996 997 // Set the action and ID. 998 options.data = _.extend( options.data || {}, { 999 action: 'save-attachment', 1000 id: this.id, 1001 nonce: this.get('nonces').update, 1002 post_id: wp.media.model.settings.post.id 1003 }); 1004 1005 // Record the values of the changed attributes. 1006 if ( model.hasChanged() ) { 1007 options.data.changes = {}; 1008 1009 _.each( model.changed, function( value, key ) { 1010 options.data.changes[ key ] = this.get( key ); 1011 }, this ); 1012 } 1013 1014 return wp.media.ajax( options ); 1015 1016 // Overload the `delete` request so attachments can be removed. 1017 // This will permanently delete an attachment. 1018 } else if ( 'delete' === method ) { 1019 options = options || {}; 1020 1021 if ( ! options.wait ) { 1022 this.destroyed = true; 1023 } 1024 1025 options.context = this; 1026 options.data = _.extend( options.data || {}, { 1027 action: 'delete-post', 1028 id: this.id, 1029 _wpnonce: this.get('nonces')['delete'] 1030 }); 1031 1032 return wp.media.ajax( options ).done( function() { 1033 this.destroyed = true; 1034 }).fail( function() { 1035 this.destroyed = false; 1036 }); 1037 1038 // Otherwise, fall back to `Backbone.sync()`. 1039 } else { 1040 /** 1041 * Call `sync` directly on Backbone.Model 1042 */ 1043 return Backbone.Model.prototype.sync.apply( this, arguments ); 1044 } 1045 }, 1046 /** 1047 * Convert date strings into Date objects. 1048 * 1049 * @param {Object} resp The raw response object, typically returned by fetch() 1050 * @returns {Object} The modified response object, which is the attributes hash 1051 * to be set on the model. 1052 */ 1053 parse: function( resp ) { 1054 if ( ! resp ) { 1055 return resp; 1056 } 1057 1058 resp.date = new Date( resp.date ); 1059 resp.modified = new Date( resp.modified ); 1060 return resp; 1061 }, 1062 /** 1063 * @param {Object} data The properties to be saved. 1064 * @param {Object} options Sync options. e.g. patch, wait, success, error. 1065 * 1066 * @this Backbone.Model 1067 * 1068 * @returns {Promise} 1069 */ 1070 saveCompat: function( data, options ) { 1071 var model = this; 1072 1073 // If we do not have the necessary nonce, fail immeditately. 1074 if ( ! this.get('nonces') || ! this.get('nonces').update ) { 1075 return $.Deferred().rejectWith( this ).promise(); 1076 } 1077 1078 return media.post( 'save-attachment-compat', _.defaults({ 1079 id: this.id, 1080 nonce: this.get('nonces').update, 1081 post_id: wp.media.model.settings.post.id 1082 }, data ) ).done( function( resp, status, xhr ) { 1083 model.set( model.parse( resp, xhr ), options ); 1084 }); 1085 } 1086 }, { 1087 /** 1088 * Create a new model on the static 'all' attachments collection and return it. 1089 * 1090 * @static 1091 * @param {Object} attrs 1092 * @returns {wp.media.model.Attachment} 1093 */ 1094 create: function( attrs ) { 1095 var Attachments = require( './attachments.js' ); 1096 return Attachments.all.push( attrs ); 1097 }, 1098 /** 1099 * Create a new model on the static 'all' attachments collection and return it. 1100 * 1101 * If this function has already been called for the id, 1102 * it returns the specified attachment. 1103 * 1104 * @static 1105 * @param {string} id A string used to identify a model. 1106 * @param {Backbone.Model|undefined} attachment 1107 * @returns {wp.media.model.Attachment} 1108 */ 1109 get: _.memoize( function( id, attachment ) { 1110 var Attachments = require( './attachments.js' ); 1111 return Attachments.all.push( attachment || { id: id } ); 1112 }) 1113 }); 1114 1115 module.exports = Attachment; 1116 },{"./attachments.js":9}],9:[function(require,module,exports){ 1117 /*globals jQuery, Backbone, _, wp */ 1118 1119 /** 1120 * wp.media.model.Attachments 1121 * 1122 * A collection of attachments. 1123 * 1124 * This collection has no persistence with the server without supplying 1125 * 'options.props.query = true', which will mirror the collection 1126 * to an Attachments Query collection - @see wp.media.model.Attachments.mirror(). 1127 * 1128 * @class 1129 * @augments Backbone.Collection 1130 * 1131 * @param {array} [models] Models to initialize with the collection. 1132 * @param {object} [options] Options hash for the collection. 1133 * @param {string} [options.props] Options hash for the initial query properties. 1134 * @param {string} [options.props.order] Initial order (ASC or DESC) for the collection. 1135 * @param {string} [options.props.orderby] Initial attribute key to order the collection by. 1136 * @param {string} [options.props.query] Whether the collection is linked to an attachments query. 1137 * @param {string} [options.observe] 1138 * @param {string} [options.filters] 1139 * 1140 */ 1141 var Attachment = require( './attachment.js' ), 1142 Attachments; 1143 1144 Attachments = Backbone.Collection.extend({ 1145 /** 1146 * @type {wp.media.model.Attachment} 1147 */ 1148 model: Attachment, 1149 /** 1150 * @param {Array} [models=[]] Array of models used to populate the collection. 1151 * @param {Object} [options={}] 1152 */ 1153 initialize: function( models, options ) { 1154 options = options || {}; 1155 1156 this.props = new Backbone.Model(); 1157 this.filters = options.filters || {}; 1158 1159 // Bind default `change` events to the `props` model. 1160 this.props.on( 'change', this._changeFilteredProps, this ); 1161 1162 this.props.on( 'change:order', this._changeOrder, this ); 1163 this.props.on( 'change:orderby', this._changeOrderby, this ); 1164 this.props.on( 'change:query', this._changeQuery, this ); 1165 1166 this.props.set( _.defaults( options.props || {} ) ); 1167 1168 if ( options.observe ) { 1169 this.observe( options.observe ); 1170 } 1171 }, 1172 /** 1173 * Sort the collection when the order attribute changes. 1174 * 1175 * @access private 1176 */ 1177 _changeOrder: function() { 1178 if ( this.comparator ) { 1179 this.sort(); 1180 } 1181 }, 1182 /** 1183 * Set the default comparator only when the `orderby` property is set. 1184 * 1185 * @access private 1186 * 1187 * @param {Backbone.Model} model 1188 * @param {string} orderby 1189 */ 1190 _changeOrderby: function( model, orderby ) { 1191 // If a different comparator is defined, bail. 1192 if ( this.comparator && this.comparator !== Attachments.comparator ) { 1193 return; 1194 } 1195 1196 if ( orderby && 'post__in' !== orderby ) { 1197 this.comparator = Attachments.comparator; 1198 } else { 1199 delete this.comparator; 1200 } 1201 }, 1202 /** 1203 * If the `query` property is set to true, query the server using 1204 * the `props` values, and sync the results to this collection. 1205 * 1206 * @access private 1207 * 1208 * @param {Backbone.Model} model 1209 * @param {Boolean} query 1210 */ 1211 _changeQuery: function( model, query ) { 1212 if ( query ) { 1213 this.props.on( 'change', this._requery, this ); 1214 this._requery(); 1215 } else { 1216 this.props.off( 'change', this._requery, this ); 1217 } 1218 }, 1219 /** 1220 * @access private 1221 * 1222 * @param {Backbone.Model} model 1223 */ 1224 _changeFilteredProps: function( model ) { 1225 // If this is a query, updating the collection will be handled by 1226 // `this._requery()`. 1227 if ( this.props.get('query') ) { 1228 return; 1229 } 1230 1231 var changed = _.chain( model.changed ).map( function( t, prop ) { 1232 var filter = Attachments.filters[ prop ], 1233 term = model.get( prop ); 1234 1235 if ( ! filter ) { 1236 return; 1237 } 1238 1239 if ( term && ! this.filters[ prop ] ) { 1240 this.filters[ prop ] = filter; 1241 } else if ( ! term && this.filters[ prop ] === filter ) { 1242 delete this.filters[ prop ]; 1243 } else { 1244 return; 1245 } 1246 1247 // Record the change. 1248 return true; 1249 }, this ).any().value(); 1250 1251 if ( ! changed ) { 1252 return; 1253 } 1254 1255 // If no `Attachments` model is provided to source the searches 1256 // from, then automatically generate a source from the existing 1257 // models. 1258 if ( ! this._source ) { 1259 this._source = new Attachments( this.models ); 1260 } 1261 1262 this.reset( this._source.filter( this.validator, this ) ); 1263 }, 1264 1265 validateDestroyed: false, 1266 /** 1267 * Checks whether an attachment is valid. 1268 * 1269 * @param {wp.media.model.Attachment} attachment 1270 * @returns {Boolean} 1271 */ 1272 validator: function( attachment ) { 1273 if ( ! this.validateDestroyed && attachment.destroyed ) { 1274 return false; 1275 } 1276 return _.all( this.filters, function( filter ) { 1277 return !! filter.call( this, attachment ); 1278 }, this ); 1279 }, 1280 /** 1281 * Add or remove an attachment to the collection depending on its validity. 1282 * 1283 * @param {wp.media.model.Attachment} attachment 1284 * @param {Object} options 1285 * @returns {wp.media.model.Attachments} Returns itself to allow chaining 1286 */ 1287 validate: function( attachment, options ) { 1288 var valid = this.validator( attachment ), 1289 hasAttachment = !! this.get( attachment.cid ); 1290 1291 if ( ! valid && hasAttachment ) { 1292 this.remove( attachment, options ); 1293 } else if ( valid && ! hasAttachment ) { 1294 this.add( attachment, options ); 1295 } 1296 1297 return this; 1298 }, 1299 1300 /** 1301 * Add or remove all attachments from another collection depending on each one's validity. 1302 * 1303 * @param {wp.media.model.Attachments} attachments 1304 * @param {object} [options={}] 1305 * 1306 * @fires wp.media.model.Attachments#reset 1307 * 1308 * @returns {wp.media.model.Attachments} Returns itself to allow chaining 1309 */ 1310 validateAll: function( attachments, options ) { 1311 options = options || {}; 1312 1313 _.each( attachments.models, function( attachment ) { 1314 this.validate( attachment, { silent: true }); 1315 }, this ); 1316 1317 if ( ! options.silent ) { 1318 this.trigger( 'reset', this, options ); 1319 } 1320 return this; 1321 }, 1322 /** 1323 * Start observing another attachments collection change events 1324 * and replicate them on this collection. 1325 * 1326 * @param {wp.media.model.Attachments} The attachments collection to observe. 1327 * @returns {wp.media.model.Attachments} Returns itself to allow chaining. 1328 */ 1329 observe: function( attachments ) { 1330 this.observers = this.observers || []; 1331 this.observers.push( attachments ); 1332 1333 attachments.on( 'add change remove', this._validateHandler, this ); 1334 attachments.on( 'reset', this._validateAllHandler, this ); 1335 this.validateAll( attachments ); 1336 return this; 1337 }, 1338 /** 1339 * Stop replicating collection change events from another attachments collection. 1340 * 1341 * @param {wp.media.model.Attachments} The attachments collection to stop observing. 1342 * @returns {wp.media.model.Attachments} Returns itself to allow chaining 1343 */ 1344 unobserve: function( attachments ) { 1345 if ( attachments ) { 1346 attachments.off( null, null, this ); 1347 this.observers = _.without( this.observers, attachments ); 1348 1349 } else { 1350 _.each( this.observers, function( attachments ) { 1351 attachments.off( null, null, this ); 1352 }, this ); 1353 delete this.observers; 1354 } 1355 1356 return this; 1357 }, 1358 /** 1359 * @access private 1360 * 1361 * @param {wp.media.model.Attachments} attachment 1362 * @param {wp.media.model.Attachments} attachments 1363 * @param {Object} options 1364 * 1365 * @returns {wp.media.model.Attachments} Returns itself to allow chaining 1366 */ 1367 _validateHandler: function( attachment, attachments, options ) { 1368 // If we're not mirroring this `attachments` collection, 1369 // only retain the `silent` option. 1370 options = attachments === this.mirroring ? options : { 1371 silent: options && options.silent 1372 }; 1373 1374 return this.validate( attachment, options ); 1375 }, 1376 /** 1377 * @access private 1378 * 1379 * @param {wp.media.model.Attachments} attachments 1380 * @param {Object} options 1381 * @returns {wp.media.model.Attachments} Returns itself to allow chaining 1382 */ 1383 _validateAllHandler: function( attachments, options ) { 1384 return this.validateAll( attachments, options ); 1385 }, 1386 /** 1387 * Start mirroring another attachments collection, clearing out any models already 1388 * in the collection. 1389 * 1390 * @param {wp.media.model.Attachments} The attachments collection to mirror. 1391 * @returns {wp.media.model.Attachments} Returns itself to allow chaining 1392 */ 1393 mirror: function( attachments ) { 1394 if ( this.mirroring && this.mirroring === attachments ) { 1395 return this; 1396 } 1397 1398 this.unmirror(); 1399 this.mirroring = attachments; 1400 1401 // Clear the collection silently. A `reset` event will be fired 1402 // when `observe()` calls `validateAll()`. 1403 this.reset( [], { silent: true } ); 1404 this.observe( attachments ); 1405 1406 return this; 1407 }, 1408 /** 1409 * Stop mirroring another attachments collection. 1410 */ 1411 unmirror: function() { 1412 if ( ! this.mirroring ) { 1413 return; 1414 } 1415 1416 this.unobserve( this.mirroring ); 1417 delete this.mirroring; 1418 }, 1419 /** 1420 * Retrive more attachments from the server for the collection. 1421 * 1422 * Only works if the collection is mirroring a Query Attachments collection, 1423 * and forwards to its `more` method. This collection class doesn't have 1424 * server persistence by itself. 1425 * 1426 * @param {object} options 1427 * @returns {Promise} 1428 */ 1429 more: function( options ) { 1430 var deferred = jQuery.Deferred(), 1431 mirroring = this.mirroring, 1432 attachments = this; 1433 1434 if ( ! mirroring || ! mirroring.more ) { 1435 return deferred.resolveWith( this ).promise(); 1436 } 1437 // If we're mirroring another collection, forward `more` to 1438 // the mirrored collection. Account for a race condition by 1439 // checking if we're still mirroring that collection when 1440 // the request resolves. 1441 mirroring.more( options ).done( function() { 1442 if ( this === attachments.mirroring ) 1443 deferred.resolveWith( this ); 1444 }); 1445 1446 return deferred.promise(); 1447 }, 1448 /** 1449 * Whether there are more attachments that haven't been sync'd from the server 1450 * that match the collection's query. 1451 * 1452 * Only works if the collection is mirroring a Query Attachments collection, 1453 * and forwards to its `hasMore` method. This collection class doesn't have 1454 * server persistence by itself. 1455 * 1456 * @returns {boolean} 1457 */ 1458 hasMore: function() { 1459 return this.mirroring ? this.mirroring.hasMore() : false; 1460 }, 1461 /** 1462 * A custom AJAX-response parser. 1463 * 1464 * See trac ticket #24753 1465 * 1466 * @param {Object|Array} resp The raw response Object/Array. 1467 * @param {Object} xhr 1468 * @returns {Array} The array of model attributes to be added to the collection 1469 */ 1470 parse: function( resp, xhr ) { 1471 if ( ! _.isArray( resp ) ) { 1472 resp = [resp]; 1473 } 1474 1475 return _.map( resp, function( attrs ) { 1476 var id, attachment, newAttributes; 1477 1478 if ( attrs instanceof Backbone.Model ) { 1479 id = attrs.get( 'id' ); 1480 attrs = attrs.attributes; 1481 } else { 1482 id = attrs.id; 1483 } 1484 1485 attachment = Attachment.get( id ); 1486 newAttributes = attachment.parse( attrs, xhr ); 1487 1488 if ( ! _.isEqual( attachment.attributes, newAttributes ) ) { 1489 attachment.set( newAttributes ); 1490 } 1491 1492 return attachment; 1493 }); 1494 }, 1495 /** 1496 * If the collection is a query, create and mirror an Attachments Query collection. 1497 * 1498 * @access private 1499 */ 1500 _requery: function( refresh ) { 1501 var props, Query; 1502 if ( this.props.get('query') ) { 1503 Query = require( './query.js' ); 1504 props = this.props.toJSON(); 1505 props.cache = ( true !== refresh ); 1506 this.mirror( Query.get( props ) ); 1507 } 1508 }, 1509 /** 1510 * If this collection is sorted by `menuOrder`, recalculates and saves 1511 * the menu order to the database. 1512 * 1513 * @returns {undefined|Promise} 1514 */ 1515 saveMenuOrder: function() { 1516 if ( 'menuOrder' !== this.props.get('orderby') ) { 1517 return; 1518 } 1519 1520 // Removes any uploading attachments, updates each attachment's 1521 // menu order, and returns an object with an { id: menuOrder } 1522 // mapping to pass to the request. 1523 var attachments = this.chain().filter( function( attachment ) { 1524 return ! _.isUndefined( attachment.id ); 1525 }).map( function( attachment, index ) { 1526 // Indices start at 1. 1527 index = index + 1; 1528 attachment.set( 'menuOrder', index ); 1529 return [ attachment.id, index ]; 1530 }).object().value(); 1531 1532 if ( _.isEmpty( attachments ) ) { 1533 return; 1534 } 1535 1536 return wp.media.post( 'save-attachment-order', { 1537 nonce: wp.media.model.settings.post.nonce, 1538 post_id: wp.media.model.settings.post.id, 1539 attachments: attachments 1540 }); 1541 } 1542 }, { 1543 /** 1544 * A function to compare two attachment models in an attachments collection. 1545 * 1546 * Used as the default comparator for instances of wp.media.model.Attachments 1547 * and its subclasses. @see wp.media.model.Attachments._changeOrderby(). 1548 * 1549 * @static 1550 * 1551 * @param {Backbone.Model} a 1552 * @param {Backbone.Model} b 1553 * @param {Object} options 1554 * @returns {Number} -1 if the first model should come before the second, 1555 * 0 if they are of the same rank and 1556 * 1 if the first model should come after. 1557 */ 1558 comparator: function( a, b, options ) { 1559 var key = this.props.get('orderby'), 1560 order = this.props.get('order') || 'DESC', 1561 ac = a.cid, 1562 bc = b.cid; 1563 1564 a = a.get( key ); 1565 b = b.get( key ); 1566 1567 if ( 'date' === key || 'modified' === key ) { 1568 a = a || new Date(); 1569 b = b || new Date(); 1570 } 1571 1572 // If `options.ties` is set, don't enforce the `cid` tiebreaker. 1573 if ( options && options.ties ) { 1574 ac = bc = null; 1575 } 1576 1577 return ( 'DESC' === order ) ? wp.media.compare( a, b, ac, bc ) : wp.media.compare( b, a, bc, ac ); 1578 }, 1579 /** 1580 * @namespace 1581 */ 1582 filters: { 1583 /** 1584 * @static 1585 * Note that this client-side searching is *not* equivalent 1586 * to our server-side searching. 1587 * 1588 * @param {wp.media.model.Attachment} attachment 1589 * 1590 * @this wp.media.model.Attachments 1591 * 1592 * @returns {Boolean} 1593 */ 1594 search: function( attachment ) { 1595 if ( ! this.props.get('search') ) { 1596 return true; 1597 } 1598 1599 return _.any(['title','filename','description','caption','name'], function( key ) { 1600 var value = attachment.get( key ); 1601 return value && -1 !== value.search( this.props.get('search') ); 1602 }, this ); 1603 }, 1604 /** 1605 * @static 1606 * @param {wp.media.model.Attachment} attachment 1607 * 1608 * @this wp.media.model.Attachments 1609 * 1610 * @returns {Boolean} 1611 */ 1612 type: function( attachment ) { 1613 var type = this.props.get('type'); 1614 return ! type || -1 !== type.indexOf( attachment.get('type') ); 1615 }, 1616 /** 1617 * @static 1618 * @param {wp.media.model.Attachment} attachment 1619 * 1620 * @this wp.media.model.Attachments 1621 * 1622 * @returns {Boolean} 1623 */ 1624 uploadedTo: function( attachment ) { 1625 var uploadedTo = this.props.get('uploadedTo'); 1626 if ( _.isUndefined( uploadedTo ) ) { 1627 return true; 1628 } 1629 1630 return uploadedTo === attachment.get('uploadedTo'); 1631 }, 1632 /** 1633 * @static 1634 * @param {wp.media.model.Attachment} attachment 1635 * 1636 * @this wp.media.model.Attachments 1637 * 1638 * @returns {Boolean} 1639 */ 1640 status: function( attachment ) { 1641 var status = this.props.get('status'); 1642 if ( _.isUndefined( status ) ) { 1643 return true; 1644 } 1645 1646 return status === attachment.get('status'); 1647 } 1648 } 1649 }); 1650 1651 module.exports = Attachments; 1652 },{"./attachment.js":8,"./query.js":10}],10:[function(require,module,exports){ 1653 /*globals jQuery, _, wp */ 1654 1655 /** 1656 * wp.media.model.Query 1657 * 1658 * A collection of attachments that match the supplied query arguments. 1659 * 1660 * Note: Do NOT change this.args after the query has been initialized. 1661 * Things will break. 1662 * 1663 * @class 1664 * @augments wp.media.model.Attachments 1665 * @augments Backbone.Collection 1666 * 1667 * @param {array} [models] Models to initialize with the collection. 1668 * @param {object} [options] Options hash. 1669 * @param {object} [options.args] Attachments query arguments. 1670 * @param {object} [options.args.posts_per_page] 1671 */ 1672 var Attachments = require( './attachments.js' ), 1673 Query; 1674 1675 Query = Attachments.extend({ 1676 /** 1677 * @global wp.Uploader 1678 * 1679 * @param {array} [models=[]] Array of initial models to populate the collection. 1680 * @param {object} [options={}] 1681 */ 1682 initialize: function( models, options ) { 1683 var allowed; 1684 1685 options = options || {}; 1686 Attachments.prototype.initialize.apply( this, arguments ); 1687 1688 this.args = options.args; 1689 this._hasMore = true; 1690 this.created = new Date(); 1691 1692 this.filters.order = function( attachment ) { 1693 var orderby = this.props.get('orderby'), 1694 order = this.props.get('order'); 1695 1696 if ( ! this.comparator ) { 1697 return true; 1698 } 1699 1700 // We want any items that can be placed before the last 1701 // item in the set. If we add any items after the last 1702 // item, then we can't guarantee the set is complete. 1703 if ( this.length ) { 1704 return 1 !== this.comparator( attachment, this.last(), { ties: true }); 1705 1706 // Handle the case where there are no items yet and 1707 // we're sorting for recent items. In that case, we want 1708 // changes that occurred after we created the query. 1709 } else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) { 1710 return attachment.get( orderby ) >= this.created; 1711 1712 // If we're sorting by menu order and we have no items, 1713 // accept any items that have the default menu order (0). 1714 } else if ( 'ASC' === order && 'menuOrder' === orderby ) { 1715 return attachment.get( orderby ) === 0; 1716 } 1717 1718 // Otherwise, we don't want any items yet. 1719 return false; 1720 }; 1721 1722 // Observe the central `wp.Uploader.queue` collection to watch for 1723 // new matches for the query. 1724 // 1725 // Only observe when a limited number of query args are set. There 1726 // are no filters for other properties, so observing will result in 1727 // false positives in those queries. 1728 allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent' ]; 1729 if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) { 1730 this.observe( wp.Uploader.queue ); 1731 } 1732 }, 1733 /** 1734 * Whether there are more attachments that haven't been sync'd from the server 1735 * that match the collection's query. 1736 * 1737 * @returns {boolean} 1738 */ 1739 hasMore: function() { 1740 return this._hasMore; 1741 }, 1742 /** 1743 * Fetch more attachments from the server for the collection. 1744 * 1745 * @param {object} [options={}] 1746 * @returns {Promise} 1747 */ 1748 more: function( options ) { 1749 var query = this; 1750 1751 // If there is already a request pending, return early with the Deferred object. 1752 if ( this._more && 'pending' === this._more.state() ) { 1753 return this._more; 1754 } 1755 1756 if ( ! this.hasMore() ) { 1757 return jQuery.Deferred().resolveWith( this ).promise(); 1758 } 1759 1760 options = options || {}; 1761 options.remove = false; 1762 1763 return this._more = this.fetch( options ).done( function( resp ) { 1764 if ( _.isEmpty( resp ) || -1 === this.args.posts_per_page || resp.length < this.args.posts_per_page ) { 1765 query._hasMore = false; 1766 } 1767 }); 1768 }, 1769 /** 1770 * Overrides Backbone.Collection.sync 1771 * Overrides wp.media.model.Attachments.sync 1772 * 1773 * @param {String} method 1774 * @param {Backbone.Model} model 1775 * @param {Object} [options={}] 1776 * @returns {Promise} 1777 */ 1778 sync: function( method, model, options ) { 1779 var args, fallback; 1780 1781 // Overload the read method so Attachment.fetch() functions correctly. 1782 if ( 'read' === method ) { 1783 options = options || {}; 1784 options.context = this; 1785 options.data = _.extend( options.data || {}, { 1786 action: 'query-attachments', 1787 post_id: wp.media.model.settings.post.id 1788 }); 1789 1790 // Clone the args so manipulation is non-destructive. 1791 args = _.clone( this.args ); 1792 1793 // Determine which page to query. 1794 if ( -1 !== args.posts_per_page ) { 1795 args.paged = Math.floor( this.length / args.posts_per_page ) + 1; 1796 } 1797 1798 options.data.query = args; 1799 return wp.media.ajax( options ); 1800 1801 // Otherwise, fall back to Backbone.sync() 1802 } else { 1803 /** 1804 * Call wp.media.model.Attachments.sync or Backbone.sync 1805 */ 1806 fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone; 1807 return fallback.sync.apply( this, arguments ); 1808 } 1809 } 1810 }, { 1811 /** 1812 * @readonly 1813 */ 1814 defaultProps: { 1815 orderby: 'date', 1816 order: 'DESC' 1817 }, 1818 /** 1819 * @readonly 1820 */ 1821 defaultArgs: { 1822 posts_per_page: 40 1823 }, 1824 /** 1825 * @readonly 1826 */ 1827 orderby: { 1828 allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ], 1829 /** 1830 * A map of JavaScript orderby values to their WP_Query equivalents. 1831 * @type {Object} 1832 */ 1833 valuemap: { 1834 'id': 'ID', 1835 'uploadedTo': 'parent', 1836 'menuOrder': 'menu_order ID' 1837 } 1838 }, 1839 /** 1840 * A map of JavaScript query properties to their WP_Query equivalents. 1841 * 1842 * @readonly 1843 */ 1844 propmap: { 1845 'search': 's', 1846 'type': 'post_mime_type', 1847 'perPage': 'posts_per_page', 1848 'menuOrder': 'menu_order', 1849 'uploadedTo': 'post_parent', 1850 'status': 'post_status', 1851 'include': 'post__in', 1852 'exclude': 'post__not_in' 1853 }, 1854 /** 1855 * Creates and returns an Attachments Query collection given the properties. 1856 * 1857 * Caches query objects and reuses where possible. 1858 * 1859 * @static 1860 * @method 1861 * 1862 * @param {object} [props] 1863 * @param {Object} [props.cache=true] Whether to use the query cache or not. 1864 * @param {Object} [props.order] 1865 * @param {Object} [props.orderby] 1866 * @param {Object} [props.include] 1867 * @param {Object} [props.exclude] 1868 * @param {Object} [props.s] 1869 * @param {Object} [props.post_mime_type] 1870 * @param {Object} [props.posts_per_page] 1871 * @param {Object} [props.menu_order] 1872 * @param {Object} [props.post_parent] 1873 * @param {Object} [props.post_status] 1874 * @param {Object} [options] 1875 * 1876 * @returns {wp.media.model.Query} A new Attachments Query collection. 1877 */ 1878 get: (function(){ 1879 /** 1880 * @static 1881 * @type Array 1882 */ 1883 var queries = []; 1884 1885 /** 1886 * @returns {Query} 1887 */ 1888 return function( props, options ) { 1889 var args = {}, 1890 orderby = Query.orderby, 1891 defaults = Query.defaultProps, 1892 query, 1893 cache = !! props.cache || _.isUndefined( props.cache ); 1894 1895 // Remove the `query` property. This isn't linked to a query, 1896 // this *is* the query. 1897 delete props.query; 1898 delete props.cache; 1899 1900 // Fill default args. 1901 _.defaults( props, defaults ); 1902 1903 // Normalize the order. 1904 props.order = props.order.toUpperCase(); 1905 if ( 'DESC' !== props.order && 'ASC' !== props.order ) { 1906 props.order = defaults.order.toUpperCase(); 1907 } 1908 1909 // Ensure we have a valid orderby value. 1910 if ( ! _.contains( orderby.allowed, props.orderby ) ) { 1911 props.orderby = defaults.orderby; 1912 } 1913 1914 _.each( [ 'include', 'exclude' ], function( prop ) { 1915 if ( props[ prop ] && ! _.isArray( props[ prop ] ) ) { 1916 props[ prop ] = [ props[ prop ] ]; 1917 } 1918 } ); 1919 1920 // Generate the query `args` object. 1921 // Correct any differing property names. 1922 _.each( props, function( value, prop ) { 1923 if ( _.isNull( value ) ) { 1924 return; 1925 } 1926 1927 args[ Query.propmap[ prop ] || prop ] = value; 1928 }); 1929 1930 // Fill any other default query args. 1931 _.defaults( args, Query.defaultArgs ); 1932 1933 // `props.orderby` does not always map directly to `args.orderby`. 1934 // Substitute exceptions specified in orderby.keymap. 1935 args.orderby = orderby.valuemap[ props.orderby ] || props.orderby; 1936 1937 // Search the query cache for a matching query. 1938 if ( cache ) { 1939 query = _.find( queries, function( query ) { 1940 return _.isEqual( query.args, args ); 1941 }); 1942 } else { 1943 queries = []; 1944 } 1945 1946 // Otherwise, create a new query and add it to the cache. 1947 if ( ! query ) { 1948 query = new Query( [], _.extend( options || {}, { 1949 props: props, 1950 args: args 1951 } ) ); 1952 queries.push( query ); 1953 } 1954 1955 return query; 1956 }; 1957 }()) 1958 }); 1959 1960 module.exports = Query; 1961 },{"./attachments.js":9}],11:[function(require,module,exports){ 1962 /*globals _ */ 1963 1964 /** 1965 * wp.media.model.Selection 1966 * 1967 * A selection of attachments. 1968 * 1969 * @class 1970 * @augments wp.media.model.Attachments 1971 * @augments Backbone.Collection 1972 */ 1973 var Attachments = require( './attachments.js' ), 1974 Selection; 1975 1976 Selection = Attachments.extend({ 1977 /** 1978 * Refresh the `single` model whenever the selection changes. 1979 * Binds `single` instead of using the context argument to ensure 1980 * it receives no parameters. 1981 * 1982 * @param {Array} [models=[]] Array of models used to populate the collection. 1983 * @param {Object} [options={}] 1984 */ 1985 initialize: function( models, options ) { 1986 /** 1987 * call 'initialize' directly on the parent class 1988 */ 1989 Attachments.prototype.initialize.apply( this, arguments ); 1990 this.multiple = options && options.multiple; 1991 1992 this.on( 'add remove reset', _.bind( this.single, this, false ) ); 1993 }, 1994 1995 /** 1996 * If the workflow does not support multi-select, clear out the selection 1997 * before adding a new attachment to it. 1998 * 1999 * @param {Array} models 2000 * @param {Object} options 2001 * @returns {wp.media.model.Attachment[]} 2002 */ 2003 add: function( models, options ) { 2004 if ( ! this.multiple ) { 2005 this.remove( this.models ); 2006 } 2007 /** 2008 * call 'add' directly on the parent class 2009 */ 2010 return Attachments.prototype.add.call( this, models, options ); 2011 }, 2012 2013 /** 2014 * Fired when toggling (clicking on) an attachment in the modal. 2015 * 2016 * @param {undefined|boolean|wp.media.model.Attachment} model 2017 * 2018 * @fires wp.media.model.Selection#selection:single 2019 * @fires wp.media.model.Selection#selection:unsingle 2020 * 2021 * @returns {Backbone.Model} 2022 */ 2023 single: function( model ) { 2024 var previous = this._single; 2025 2026 // If a `model` is provided, use it as the single model. 2027 if ( model ) { 2028 this._single = model; 2029 } 2030 // If the single model isn't in the selection, remove it. 2031 if ( this._single && ! this.get( this._single.cid ) ) { 2032 delete this._single; 2033 } 2034 2035 this._single = this._single || this.last(); 2036 2037 // If single has changed, fire an event. 2038 if ( this._single !== previous ) { 2039 if ( previous ) { 2040 previous.trigger( 'selection:unsingle', previous, this ); 2041 2042 // If the model was already removed, trigger the collection 2043 // event manually. 2044 if ( ! this.get( previous.cid ) ) { 2045 this.trigger( 'selection:unsingle', previous, this ); 2046 } 2047 } 2048 if ( this._single ) { 2049 this._single.trigger( 'selection:single', this._single, this ); 2050 } 2051 } 2052 2053 // Return the single model, or the last model as a fallback. 2054 return this._single; 2055 } 2056 }); 2057 2058 module.exports = Selection; 2059 },{"./attachments.js":9}],12:[function(require,module,exports){ 946 },{"./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){ 2060 947 /*globals jQuery, Backbone */ 2061 948 … … 2104 991 2105 992 module.exports = Router; 2106 },{}], 13:[function(require,module,exports){993 },{}],9:[function(require,module,exports){ 2107 994 /*globals _ */ 2108 995 … … 2171 1058 2172 1059 module.exports = selectionSync; 2173 },{}],1 4:[function(require,module,exports){1060 },{}],10:[function(require,module,exports){ 2174 1061 /*globals _ */ 2175 1062 … … 2257 1144 2258 1145 module.exports = AttachmentCompat; 2259 },{"./view.js":5 5}],15:[function(require,module,exports){1146 },{"./view.js":51}],11:[function(require,module,exports){ 2260 1147 /*globals _, jQuery */ 2261 1148 … … 2336 1223 2337 1224 module.exports = AttachmentFilters; 2338 },{"./view.js":5 5}],16:[function(require,module,exports){1225 },{"./view.js":51}],12:[function(require,module,exports){ 2339 1226 /*globals _, wp */ 2340 1227 … … 2428 1315 2429 1316 module.exports = All; 2430 },{"../attachment-filters.js":1 5}],17:[function(require,module,exports){1317 },{"../attachment-filters.js":11}],13:[function(require,module,exports){ 2431 1318 /*globals _, wp */ 2432 1319 … … 2471 1358 2472 1359 module.exports = DateFilter; 2473 },{"../attachment-filters.js":1 5}],18:[function(require,module,exports){1360 },{"../attachment-filters.js":11}],14:[function(require,module,exports){ 2474 1361 /*globals wp */ 2475 1362 … … 2532 1419 2533 1420 module.exports = Uploaded; 2534 },{"../attachment-filters.js":1 5}],19:[function(require,module,exports){1421 },{"../attachment-filters.js":11}],15:[function(require,module,exports){ 2535 1422 /*globals _, wp, jQuery */ 2536 1423 … … 3087 1974 3088 1975 module.exports = Attachment; 3089 },{"./view.js":5 5}],20:[function(require,module,exports){1976 },{"./view.js":51}],16:[function(require,module,exports){ 3090 1977 /*globals wp */ 3091 1978 … … 3130 2017 3131 2018 module.exports = TwoColumn; 3132 },{"../media-details.js":3 7,"./details.js":21}],21:[function(require,module,exports){2019 },{"../media-details.js":33,"./details.js":17}],17:[function(require,module,exports){ 3133 2020 /*globals _, wp */ 3134 2021 … … 3271 2158 3272 2159 module.exports = Details; 3273 },{"../attachment.js":1 9}],22:[function(require,module,exports){2160 },{"../attachment.js":15}],18:[function(require,module,exports){ 3274 2161 /** 3275 2162 * wp.media.view.Attachment.Library … … 3291 2178 3292 2179 module.exports = Library; 3293 },{"../attachment.js":1 9}],23:[function(require,module,exports){2180 },{"../attachment.js":15}],19:[function(require,module,exports){ 3294 2181 /*globals _, wp, jQuery */ 3295 2182 … … 3592 2479 3593 2480 module.exports = Attachments; 3594 },{"./attachment.js":1 9,"./view.js":55}],24:[function(require,module,exports){2481 },{"./attachment.js":15,"./view.js":51}],20:[function(require,module,exports){ 3595 2482 /*globals _, wp, jQuery */ 3596 2483 … … 4052 2939 4053 2940 module.exports = AttachmentsBrowser; 4054 },{"../attachment-compat.js":1 4,"../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){2941 },{"../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){ 4055 2942 /*globals _, Backbone */ 4056 2943 … … 4142 3029 4143 3030 module.exports = Button; 4144 },{"./view.js":5 5}],26:[function(require,module,exports){3031 },{"./view.js":51}],22:[function(require,module,exports){ 4145 3032 /** 4146 3033 * When MEDIA_TRASH is true, a button that handles bulk Delete Permanently logic … … 4186 3073 4187 3074 module.exports = DeleteSelectedPermanently; 4188 },{"../button.js":2 5,"./delete-selected.js":27}],27:[function(require,module,exports){3075 },{"../button.js":21,"./delete-selected.js":23}],23:[function(require,module,exports){ 4189 3076 /*globals wp */ 4190 3077 … … 4238 3125 4239 3126 module.exports = DeleteSelected; 4240 },{"../button.js":2 5}],28:[function(require,module,exports){3127 },{"../button.js":21}],24:[function(require,module,exports){ 4241 3128 /*globals wp */ 4242 3129 … … 4294 3181 4295 3182 module.exports = SelectModeToggle; 4296 },{"../button.js":2 5}],29:[function(require,module,exports){3183 },{"../button.js":21}],25:[function(require,module,exports){ 4297 3184 var View = require( './view.js' ), 4298 3185 EditImage = require( './edit-image.js' ), … … 4321 3208 4322 3209 module.exports = Details; 4323 },{"./edit-image.js": 30,"./view.js":55}],30:[function(require,module,exports){3210 },{"./edit-image.js":26,"./view.js":51}],26:[function(require,module,exports){ 4324 3211 /*globals _, wp */ 4325 3212 … … 4376 3263 4377 3264 module.exports = EditImage; 4378 },{"./view.js":5 5}],31:[function(require,module,exports){3265 },{"./view.js":51}],27:[function(require,module,exports){ 4379 3266 /** 4380 3267 * wp.media.view.FocusManager … … 4424 3311 4425 3312 module.exports = FocusManager; 4426 },{"./view.js":5 5}],32:[function(require,module,exports){3313 },{"./view.js":51}],28:[function(require,module,exports){ 4427 3314 /*globals _, Backbone */ 4428 3315 … … 4597 3484 4598 3485 module.exports = Frame; 4599 },{"../controllers/region.js":4,"../controllers/state-machine.js":5,"../controllers/state.js":6,"./view.js":5 5}],33:[function(require,module,exports){3486 },{"../controllers/region.js":4,"../controllers/state-machine.js":5,"../controllers/state.js":6,"./view.js":51}],29:[function(require,module,exports){ 4600 3487 /*globals _, wp, jQuery */ 4601 3488 … … 4846 3733 4847 3734 module.exports = EditAttachments; 4848 },{"../../controllers/edit-attachment-metadata.js":1,"../../controllers/edit-image.js":2,"../attachment-compat.js":1 4,"../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){3735 },{"../../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){ 4849 3736 /*globals _, Backbone, wp, jQuery */ 4850 3737 … … 5094 3981 5095 3982 module.exports = Manage; 5096 },{"../../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){3983 },{"../../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){ 5097 3984 /** 5098 3985 * wp.media.view.Iframe … … 5120 4007 5121 4008 module.exports = Iframe; 5122 },{"./view.js":5 5}],36:[function(require,module,exports){4009 },{"./view.js":51}],32:[function(require,module,exports){ 5123 4010 /** 5124 4011 * @class … … 5146 4033 5147 4034 module.exports = Label; 5148 },{"./view.js":5 5}],37:[function(require,module,exports){4035 },{"./view.js":51}],33:[function(require,module,exports){ 5149 4036 /*globals _, wp, jQuery */ 5150 4037 … … 5298 4185 5299 4186 module.exports = MediaDetails; 5300 },{"./settings/attachment-display.js":4 7}],38:[function(require,module,exports){4187 },{"./settings/attachment-display.js":43}],34:[function(require,module,exports){ 5301 4188 /*globals _, wp, jQuery */ 5302 4189 … … 5553 4440 5554 4441 module.exports = MediaFrame; 5555 },{"./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){4442 },{"./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){ 5556 4443 /*globals wp, jQuery */ 5557 4444 … … 5627 4514 5628 4515 module.exports = MenuItem; 5629 },{"./view.js":5 5}],40:[function(require,module,exports){4516 },{"./view.js":51}],36:[function(require,module,exports){ 5630 4517 /** 5631 4518 * wp.media.view.Menu … … 5743 4630 5744 4631 module.exports = Menu; 5745 },{"./menu-item.js":3 9,"./priority-list.js":42}],41:[function(require,module,exports){4632 },{"./menu-item.js":35,"./priority-list.js":38}],37:[function(require,module,exports){ 5746 4633 /*globals _, wp, jQuery */ 5747 4634 … … 5959 4846 5960 4847 module.exports = Modal; 5961 },{"./focus-manager.js": 31,"./view.js":55}],42:[function(require,module,exports){4848 },{"./focus-manager.js":27,"./view.js":51}],38:[function(require,module,exports){ 5962 4849 /*globals _, Backbone */ 5963 4850 … … 6060 4947 6061 4948 module.exports = PriorityList; 6062 },{"./view.js":5 5}],43:[function(require,module,exports){4949 },{"./view.js":51}],39:[function(require,module,exports){ 6063 4950 /** 6064 4951 * wp.media.view.RouterItem … … 6086 4973 6087 4974 module.exports = RouterItem; 6088 },{"./menu-item.js":3 9}],44:[function(require,module,exports){4975 },{"./menu-item.js":35}],40:[function(require,module,exports){ 6089 4976 /** 6090 4977 * wp.media.view.Router … … 6123 5010 6124 5011 module.exports = Router; 6125 },{"./menu.js": 40,"./router-item.js":43}],45:[function(require,module,exports){5012 },{"./menu.js":36,"./router-item.js":39}],41:[function(require,module,exports){ 6126 5013 /*globals wp */ 6127 5014 … … 6173 5060 6174 5061 module.exports = Search; 6175 },{"./view.js":5 5}],46:[function(require,module,exports){5062 },{"./view.js":51}],42:[function(require,module,exports){ 6176 5063 /*globals _, Backbone, jQuery */ 6177 5064 … … 6295 5182 6296 5183 module.exports = Settings; 6297 },{"./view.js":5 5}],47:[function(require,module,exports){5184 },{"./view.js":51}],43:[function(require,module,exports){ 6298 5185 /*globals _, wp */ 6299 5186 … … 6390 5277 6391 5278 module.exports = AttachmentDisplay; 6392 },{"../settings.js":4 6}],48:[function(require,module,exports){5279 },{"../settings.js":42}],44:[function(require,module,exports){ 6393 5280 /** 6394 5281 * wp.media.view.Sidebar … … 6408 5295 6409 5296 module.exports = Sidebar; 6410 },{"./priority-list.js": 42}],49:[function(require,module,exports){5297 },{"./priority-list.js":38}],45:[function(require,module,exports){ 6411 5298 /*globals _, wp */ 6412 5299 … … 6447 5334 6448 5335 module.exports = Spinner; 6449 },{"./view.js":5 5}],50:[function(require,module,exports){5336 },{"./view.js":51}],46:[function(require,module,exports){ 6450 5337 /*globals Backbone, _ */ 6451 5338 … … 6610 5497 6611 5498 module.exports = Toolbar; 6612 },{"./button.js":2 5,"./priority-list.js":42,"./view.js":55}],51:[function(require,module,exports){5499 },{"./button.js":21,"./priority-list.js":38,"./view.js":51}],47:[function(require,module,exports){ 6613 5500 /*globals _, wp */ 6614 5501 … … 6743 5630 6744 5631 module.exports = UploaderInline; 6745 },{"../view.js":5 5,"./status.js":53}],52:[function(require,module,exports){5632 },{"../view.js":51,"./status.js":49}],48:[function(require,module,exports){ 6746 5633 /*globals wp */ 6747 5634 … … 6763 5650 6764 5651 module.exports = UploaderStatusError; 6765 },{"../view.js":5 5}],53:[function(require,module,exports){5652 },{"../view.js":51}],49:[function(require,module,exports){ 6766 5653 /*globals _, wp */ 6767 5654 … … 6903 5790 6904 5791 module.exports = UploaderStatus; 6905 },{"../view.js":5 5,"./status-error.js":52}],54:[function(require,module,exports){5792 },{"../view.js":51,"./status-error.js":48}],50:[function(require,module,exports){ 6906 5793 /*globals _, wp, jQuery */ 6907 5794 … … 7016 5903 7017 5904 module.exports = UploaderWindow; 7018 },{"../view.js":5 5}],55:[function(require,module,exports){5905 },{"../view.js":51}],51:[function(require,module,exports){ 7019 5906 /*globals wp */ 7020 5907 -
trunk/src/wp-includes/js/media/views.js
r31373 r31379 35 35 * @param {string} attributes.collectionType The collection type. (e.g. 'playlist'). 36 36 */ 37 var Selection = require( '../models/selection.js' ),37 var Selection = wp.media.model.Selection, 38 38 Library = require( './library.js' ), 39 39 CollectionAdd; … … 101 101 102 102 module.exports = CollectionAdd; 103 },{". ./models/selection.js":20,"./library.js":10}],2:[function(require,module,exports){103 },{"./library.js":10}],2:[function(require,module,exports){ 104 104 /*globals wp, jQuery, Backbone */ 105 105 … … 138 138 * @param {string} attributes.collectionType The collection type. (e.g. 'playlist'). 139 139 */ 140 var Selection = require( '../models/selection.js' ), 141 Library = require( './library.js' ), 140 var Library = require( './library.js' ), 142 141 View = require( '../views/view.js' ), 143 142 EditLibraryView = require( '../views/attachment/edit-library.js' ), … … 176 175 // If we haven't been provided a `library`, create a `Selection`. 177 176 if ( ! this.get('library') ) { 178 this.set( 'library', new Selection() );177 this.set( 'library', new wp.media.model.Selection() ); 179 178 } 180 179 // The single `Attachment` view to be used in the `Attachments` view. … … 265 264 266 265 module.exports = CollectionEdit; 267 },{"../ models/selection.js":20,"../views/attachment/edit-library.js":30,"../views/view.js":76,"./library.js":10}],3:[function(require,module,exports){266 },{"../views/attachment/edit-library.js":25,"../views/view.js":71,"./library.js":10}],3:[function(require,module,exports){ 268 267 /*globals _, wp, Backbone */ 269 268 … … 383 382 384 383 module.exports = Cropper; 385 },{"../views/cropper.js":3 9,"../views/toolbar.js":68,"./state.js":15}],4:[function(require,module,exports){384 },{"../views/cropper.js":34,"../views/toolbar.js":63,"./state.js":15}],4:[function(require,module,exports){ 386 385 /*globals _, wp */ 387 386 … … 462 461 463 462 module.exports = EditImage; 464 },{"../views/toolbar.js":6 8,"./state.js":15}],5:[function(require,module,exports){463 },{"../views/toolbar.js":63,"./state.js":15}],5:[function(require,module,exports){ 465 464 /*globals _, wp, jQuery, Backbone */ 466 465 … … 634 633 * @param {boolean} [attributes.syncSelection=true] Whether the Attachments selection should be persisted from the last state. 635 634 */ 636 var Attachment = require( '../models/attachment.js' ),635 var Attachment = wp.media.model.Attachment, 637 636 Library = require( './library.js' ), 638 637 l10n = wp.media.view.l10n, … … 723 722 724 723 module.exports = FeaturedImage; 725 },{". ./models/attachment.js":16,"./library.js":10}],7:[function(require,module,exports){724 },{"./library.js":10}],7:[function(require,module,exports){ 726 725 /*globals _, wp */ 727 726 … … 755 754 * Defaults to false because for this state, because the library of the Edit Gallery state is the selection. 756 755 */ 757 var Selection = require( '../models/selection.js' ),756 var Selection = wp.media.model.Selection, 758 757 Library = require( './library.js' ), 759 758 l10n = wp.media.view.l10n, … … 811 810 812 811 module.exports = GalleryAdd; 813 },{". ./models/selection.js":20,"./library.js":10}],8:[function(require,module,exports){812 },{"./library.js":10}],8:[function(require,module,exports){ 814 813 /*globals wp, Backbone */ 815 814 … … 845 844 * If none supplied, defaults to wp.media.view.Attachment.EditLibrary. 846 845 */ 847 var Selection = require( '../models/selection.js' ), 848 Library = require( './library.js' ), 846 var Library = require( './library.js' ), 849 847 EditLibraryView = require( '../views/attachment/edit-library.js' ), 850 848 GallerySettingsView = require( '../views/settings/gallery.js' ), … … 877 875 // If we haven't been provided a `library`, create a `Selection`. 878 876 if ( ! this.get('library') ) 879 this.set( 'library', new Selection() );877 this.set( 'library', new wp.media.model.Selection() ); 880 878 881 879 // The single `Attachment` view to be used in the `Attachments` view. … … 952 950 953 951 module.exports = GalleryEdit; 954 },{"../ models/selection.js":20,"../views/attachment/edit-library.js":30,"../views/settings/gallery.js":64,"./library.js":10}],9:[function(require,module,exports){952 },{"../views/attachment/edit-library.js":25,"../views/settings/gallery.js":59,"./library.js":10}],9:[function(require,module,exports){ 955 953 /*globals _, wp */ 956 954 … … 1053 1051 */ 1054 1052 var selectionSync = require( '../utils/selection-sync.js' ), 1055 Selection = require( '../models/selection.js' ),1056 1053 State = require( './state.js' ), 1057 1054 l10n = wp.media.view.l10n, … … 1098 1095 } 1099 1096 1100 this.set( 'selection', new Selection( null, {1097 this.set( 'selection', new wp.media.model.Selection( null, { 1101 1098 multiple: this.get('multiple'), 1102 1099 props: props … … 1289 1286 1290 1287 module.exports = Library; 1291 },{"../ models/selection.js":20,"../utils/selection-sync.js":21,"./state.js":15}],11:[function(require,module,exports){1288 },{"../utils/selection-sync.js":16,"./state.js":15}],11:[function(require,module,exports){ 1292 1289 /*globals _, wp */ 1293 1290 … … 1997 1994 module.exports = State; 1998 1995 },{}],16:[function(require,module,exports){ 1999 /*globals jQuery, Backbone, _, wp */2000 2001 /**2002 * wp.media.model.Attachment2003 *2004 * @class2005 * @augments Backbone.Model2006 */2007 var $ = jQuery,2008 Attachment;2009 2010 Attachment = Backbone.Model.extend({2011 /**2012 * Triggered when attachment details change2013 * Overrides Backbone.Model.sync2014 *2015 * @param {string} method2016 * @param {wp.media.model.Attachment} model2017 * @param {Object} [options={}]2018 *2019 * @returns {Promise}2020 */2021 sync: function( method, model, options ) {2022 // If the attachment does not yet have an `id`, return an instantly2023 // rejected promise. Otherwise, all of our requests will fail.2024 if ( _.isUndefined( this.id ) ) {2025 return $.Deferred().rejectWith( this ).promise();2026 }2027 2028 // Overload the `read` request so Attachment.fetch() functions correctly.2029 if ( 'read' === method ) {2030 options = options || {};2031 options.context = this;2032 options.data = _.extend( options.data || {}, {2033 action: 'get-attachment',2034 id: this.id2035 });2036 return wp.media.ajax( options );2037 2038 // Overload the `update` request so properties can be saved.2039 } else if ( 'update' === method ) {2040 // If we do not have the necessary nonce, fail immeditately.2041 if ( ! this.get('nonces') || ! this.get('nonces').update ) {2042 return $.Deferred().rejectWith( this ).promise();2043 }2044 2045 options = options || {};2046 options.context = this;2047 2048 // Set the action and ID.2049 options.data = _.extend( options.data || {}, {2050 action: 'save-attachment',2051 id: this.id,2052 nonce: this.get('nonces').update,2053 post_id: wp.media.model.settings.post.id2054 });2055 2056 // Record the values of the changed attributes.2057 if ( model.hasChanged() ) {2058 options.data.changes = {};2059 2060 _.each( model.changed, function( value, key ) {2061 options.data.changes[ key ] = this.get( key );2062 }, this );2063 }2064 2065 return wp.media.ajax( options );2066 2067 // Overload the `delete` request so attachments can be removed.2068 // This will permanently delete an attachment.2069 } else if ( 'delete' === method ) {2070 options = options || {};2071 2072 if ( ! options.wait ) {2073 this.destroyed = true;2074 }2075 2076 options.context = this;2077 options.data = _.extend( options.data || {}, {2078 action: 'delete-post',2079 id: this.id,2080 _wpnonce: this.get('nonces')['delete']2081 });2082 2083 return wp.media.ajax( options ).done( function() {2084 this.destroyed = true;2085 }).fail( function() {2086 this.destroyed = false;2087 });2088 2089 // Otherwise, fall back to `Backbone.sync()`.2090 } else {2091 /**2092 * Call `sync` directly on Backbone.Model2093 */2094 return Backbone.Model.prototype.sync.apply( this, arguments );2095 }2096 },2097 /**2098 * Convert date strings into Date objects.2099 *2100 * @param {Object} resp The raw response object, typically returned by fetch()2101 * @returns {Object} The modified response object, which is the attributes hash2102 * to be set on the model.2103 */2104 parse: function( resp ) {2105 if ( ! resp ) {2106 return resp;2107 }2108 2109 resp.date = new Date( resp.date );2110 resp.modified = new Date( resp.modified );2111 return resp;2112 },2113 /**2114 * @param {Object} data The properties to be saved.2115 * @param {Object} options Sync options. e.g. patch, wait, success, error.2116 *2117 * @this Backbone.Model2118 *2119 * @returns {Promise}2120 */2121 saveCompat: function( data, options ) {2122 var model = this;2123 2124 // If we do not have the necessary nonce, fail immeditately.2125 if ( ! this.get('nonces') || ! this.get('nonces').update ) {2126 return $.Deferred().rejectWith( this ).promise();2127 }2128 2129 return media.post( 'save-attachment-compat', _.defaults({2130 id: this.id,2131 nonce: this.get('nonces').update,2132 post_id: wp.media.model.settings.post.id2133 }, data ) ).done( function( resp, status, xhr ) {2134 model.set( model.parse( resp, xhr ), options );2135 });2136 }2137 }, {2138 /**2139 * Create a new model on the static 'all' attachments collection and return it.2140 *2141 * @static2142 * @param {Object} attrs2143 * @returns {wp.media.model.Attachment}2144 */2145 create: function( attrs ) {2146 var Attachments = require( './attachments.js' );2147 return Attachments.all.push( attrs );2148 },2149 /**2150 * Create a new model on the static 'all' attachments collection and return it.2151 *2152 * If this function has already been called for the id,2153 * it returns the specified attachment.2154 *2155 * @static2156 * @param {string} id A string used to identify a model.2157 * @param {Backbone.Model|undefined} attachment2158 * @returns {wp.media.model.Attachment}2159 */2160 get: _.memoize( function( id, attachment ) {2161 var Attachments = require( './attachments.js' );2162 return Attachments.all.push( attachment || { id: id } );2163 })2164 });2165 2166 module.exports = Attachment;2167 },{"./attachments.js":17}],17:[function(require,module,exports){2168 /*globals jQuery, Backbone, _, wp */2169 2170 /**2171 * wp.media.model.Attachments2172 *2173 * A collection of attachments.2174 *2175 * This collection has no persistence with the server without supplying2176 * 'options.props.query = true', which will mirror the collection2177 * to an Attachments Query collection - @see wp.media.model.Attachments.mirror().2178 *2179 * @class2180 * @augments Backbone.Collection2181 *2182 * @param {array} [models] Models to initialize with the collection.2183 * @param {object} [options] Options hash for the collection.2184 * @param {string} [options.props] Options hash for the initial query properties.2185 * @param {string} [options.props.order] Initial order (ASC or DESC) for the collection.2186 * @param {string} [options.props.orderby] Initial attribute key to order the collection by.2187 * @param {string} [options.props.query] Whether the collection is linked to an attachments query.2188 * @param {string} [options.observe]2189 * @param {string} [options.filters]2190 *2191 */2192 var Attachment = require( './attachment.js' ),2193 Attachments;2194 2195 Attachments = Backbone.Collection.extend({2196 /**2197 * @type {wp.media.model.Attachment}2198 */2199 model: Attachment,2200 /**2201 * @param {Array} [models=[]] Array of models used to populate the collection.2202 * @param {Object} [options={}]2203 */2204 initialize: function( models, options ) {2205 options = options || {};2206 2207 this.props = new Backbone.Model();2208 this.filters = options.filters || {};2209 2210 // Bind default `change` events to the `props` model.2211 this.props.on( 'change', this._changeFilteredProps, this );2212 2213 this.props.on( 'change:order', this._changeOrder, this );2214 this.props.on( 'change:orderby', this._changeOrderby, this );2215 this.props.on( 'change:query', this._changeQuery, this );2216 2217 this.props.set( _.defaults( options.props || {} ) );2218 2219 if ( options.observe ) {2220 this.observe( options.observe );2221 }2222 },2223 /**2224 * Sort the collection when the order attribute changes.2225 *2226 * @access private2227 */2228 _changeOrder: function() {2229 if ( this.comparator ) {2230 this.sort();2231 }2232 },2233 /**2234 * Set the default comparator only when the `orderby` property is set.2235 *2236 * @access private2237 *2238 * @param {Backbone.Model} model2239 * @param {string} orderby2240 */2241 _changeOrderby: function( model, orderby ) {2242 // If a different comparator is defined, bail.2243 if ( this.comparator && this.comparator !== Attachments.comparator ) {2244 return;2245 }2246 2247 if ( orderby && 'post__in' !== orderby ) {2248 this.comparator = Attachments.comparator;2249 } else {2250 delete this.comparator;2251 }2252 },2253 /**2254 * If the `query` property is set to true, query the server using2255 * the `props` values, and sync the results to this collection.2256 *2257 * @access private2258 *2259 * @param {Backbone.Model} model2260 * @param {Boolean} query2261 */2262 _changeQuery: function( model, query ) {2263 if ( query ) {2264 this.props.on( 'change', this._requery, this );2265 this._requery();2266 } else {2267 this.props.off( 'change', this._requery, this );2268 }2269 },2270 /**2271 * @access private2272 *2273 * @param {Backbone.Model} model2274 */2275 _changeFilteredProps: function( model ) {2276 // If this is a query, updating the collection will be handled by2277 // `this._requery()`.2278 if ( this.props.get('query') ) {2279 return;2280 }2281 2282 var changed = _.chain( model.changed ).map( function( t, prop ) {2283 var filter = Attachments.filters[ prop ],2284 term = model.get( prop );2285 2286 if ( ! filter ) {2287 return;2288 }2289 2290 if ( term && ! this.filters[ prop ] ) {2291 this.filters[ prop ] = filter;2292 } else if ( ! term && this.filters[ prop ] === filter ) {2293 delete this.filters[ prop ];2294 } else {2295 return;2296 }2297 2298 // Record the change.2299 return true;2300 }, this ).any().value();2301 2302 if ( ! changed ) {2303 return;2304 }2305 2306 // If no `Attachments` model is provided to source the searches2307 // from, then automatically generate a source from the existing2308 // models.2309 if ( ! this._source ) {2310 this._source = new Attachments( this.models );2311 }2312 2313 this.reset( this._source.filter( this.validator, this ) );2314 },2315 2316 validateDestroyed: false,2317 /**2318 * Checks whether an attachment is valid.2319 *2320 * @param {wp.media.model.Attachment} attachment2321 * @returns {Boolean}2322 */2323 validator: function( attachment ) {2324 if ( ! this.validateDestroyed && attachment.destroyed ) {2325 return false;2326 }2327 return _.all( this.filters, function( filter ) {2328 return !! filter.call( this, attachment );2329 }, this );2330 },2331 /**2332 * Add or remove an attachment to the collection depending on its validity.2333 *2334 * @param {wp.media.model.Attachment} attachment2335 * @param {Object} options2336 * @returns {wp.media.model.Attachments} Returns itself to allow chaining2337 */2338 validate: function( attachment, options ) {2339 var valid = this.validator( attachment ),2340 hasAttachment = !! this.get( attachment.cid );2341 2342 if ( ! valid && hasAttachment ) {2343 this.remove( attachment, options );2344 } else if ( valid && ! hasAttachment ) {2345 this.add( attachment, options );2346 }2347 2348 return this;2349 },2350 2351 /**2352 * Add or remove all attachments from another collection depending on each one's validity.2353 *2354 * @param {wp.media.model.Attachments} attachments2355 * @param {object} [options={}]2356 *2357 * @fires wp.media.model.Attachments#reset2358 *2359 * @returns {wp.media.model.Attachments} Returns itself to allow chaining2360 */2361 validateAll: function( attachments, options ) {2362 options = options || {};2363 2364 _.each( attachments.models, function( attachment ) {2365 this.validate( attachment, { silent: true });2366 }, this );2367 2368 if ( ! options.silent ) {2369 this.trigger( 'reset', this, options );2370 }2371 return this;2372 },2373 /**2374 * Start observing another attachments collection change events2375 * and replicate them on this collection.2376 *2377 * @param {wp.media.model.Attachments} The attachments collection to observe.2378 * @returns {wp.media.model.Attachments} Returns itself to allow chaining.2379 */2380 observe: function( attachments ) {2381 this.observers = this.observers || [];2382 this.observers.push( attachments );2383 2384 attachments.on( 'add change remove', this._validateHandler, this );2385 attachments.on( 'reset', this._validateAllHandler, this );2386 this.validateAll( attachments );2387 return this;2388 },2389 /**2390 * Stop replicating collection change events from another attachments collection.2391 *2392 * @param {wp.media.model.Attachments} The attachments collection to stop observing.2393 * @returns {wp.media.model.Attachments} Returns itself to allow chaining2394 */2395 unobserve: function( attachments ) {2396 if ( attachments ) {2397 attachments.off( null, null, this );2398 this.observers = _.without( this.observers, attachments );2399 2400 } else {2401 _.each( this.observers, function( attachments ) {2402 attachments.off( null, null, this );2403 }, this );2404 delete this.observers;2405 }2406 2407 return this;2408 },2409 /**2410 * @access private2411 *2412 * @param {wp.media.model.Attachments} attachment2413 * @param {wp.media.model.Attachments} attachments2414 * @param {Object} options2415 *2416 * @returns {wp.media.model.Attachments} Returns itself to allow chaining2417 */2418 _validateHandler: function( attachment, attachments, options ) {2419 // If we're not mirroring this `attachments` collection,2420 // only retain the `silent` option.2421 options = attachments === this.mirroring ? options : {2422 silent: options && options.silent2423 };2424 2425 return this.validate( attachment, options );2426 },2427 /**2428 * @access private2429 *2430 * @param {wp.media.model.Attachments} attachments2431 * @param {Object} options2432 * @returns {wp.media.model.Attachments} Returns itself to allow chaining2433 */2434 _validateAllHandler: function( attachments, options ) {2435 return this.validateAll( attachments, options );2436 },2437 /**2438 * Start mirroring another attachments collection, clearing out any models already2439 * in the collection.2440 *2441 * @param {wp.media.model.Attachments} The attachments collection to mirror.2442 * @returns {wp.media.model.Attachments} Returns itself to allow chaining2443 */2444 mirror: function( attachments ) {2445 if ( this.mirroring && this.mirroring === attachments ) {2446 return this;2447 }2448 2449 this.unmirror();2450 this.mirroring = attachments;2451 2452 // Clear the collection silently. A `reset` event will be fired2453 // when `observe()` calls `validateAll()`.2454 this.reset( [], { silent: true } );2455 this.observe( attachments );2456 2457 return this;2458 },2459 /**2460 * Stop mirroring another attachments collection.2461 */2462 unmirror: function() {2463 if ( ! this.mirroring ) {2464 return;2465 }2466 2467 this.unobserve( this.mirroring );2468 delete this.mirroring;2469 },2470 /**2471 * Retrive more attachments from the server for the collection.2472 *2473 * Only works if the collection is mirroring a Query Attachments collection,2474 * and forwards to its `more` method. This collection class doesn't have2475 * server persistence by itself.2476 *2477 * @param {object} options2478 * @returns {Promise}2479 */2480 more: function( options ) {2481 var deferred = jQuery.Deferred(),2482 mirroring = this.mirroring,2483 attachments = this;2484 2485 if ( ! mirroring || ! mirroring.more ) {2486 return deferred.resolveWith( this ).promise();2487 }2488 // If we're mirroring another collection, forward `more` to2489 // the mirrored collection. Account for a race condition by2490 // checking if we're still mirroring that collection when2491 // the request resolves.2492 mirroring.more( options ).done( function() {2493 if ( this === attachments.mirroring )2494 deferred.resolveWith( this );2495 });2496 2497 return deferred.promise();2498 },2499 /**2500 * Whether there are more attachments that haven't been sync'd from the server2501 * that match the collection's query.2502 *2503 * Only works if the collection is mirroring a Query Attachments collection,2504 * and forwards to its `hasMore` method. This collection class doesn't have2505 * server persistence by itself.2506 *2507 * @returns {boolean}2508 */2509 hasMore: function() {2510 return this.mirroring ? this.mirroring.hasMore() : false;2511 },2512 /**2513 * A custom AJAX-response parser.2514 *2515 * See trac ticket #247532516 *2517 * @param {Object|Array} resp The raw response Object/Array.2518 * @param {Object} xhr2519 * @returns {Array} The array of model attributes to be added to the collection2520 */2521 parse: function( resp, xhr ) {2522 if ( ! _.isArray( resp ) ) {2523 resp = [resp];2524 }2525 2526 return _.map( resp, function( attrs ) {2527 var id, attachment, newAttributes;2528 2529 if ( attrs instanceof Backbone.Model ) {2530 id = attrs.get( 'id' );2531 attrs = attrs.attributes;2532 } else {2533 id = attrs.id;2534 }2535 2536 attachment = Attachment.get( id );2537 newAttributes = attachment.parse( attrs, xhr );2538 2539 if ( ! _.isEqual( attachment.attributes, newAttributes ) ) {2540 attachment.set( newAttributes );2541 }2542 2543 return attachment;2544 });2545 },2546 /**2547 * If the collection is a query, create and mirror an Attachments Query collection.2548 *2549 * @access private2550 */2551 _requery: function( refresh ) {2552 var props, Query;2553 if ( this.props.get('query') ) {2554 Query = require( './query.js' );2555 props = this.props.toJSON();2556 props.cache = ( true !== refresh );2557 this.mirror( Query.get( props ) );2558 }2559 },2560 /**2561 * If this collection is sorted by `menuOrder`, recalculates and saves2562 * the menu order to the database.2563 *2564 * @returns {undefined|Promise}2565 */2566 saveMenuOrder: function() {2567 if ( 'menuOrder' !== this.props.get('orderby') ) {2568 return;2569 }2570 2571 // Removes any uploading attachments, updates each attachment's2572 // menu order, and returns an object with an { id: menuOrder }2573 // mapping to pass to the request.2574 var attachments = this.chain().filter( function( attachment ) {2575 return ! _.isUndefined( attachment.id );2576 }).map( function( attachment, index ) {2577 // Indices start at 1.2578 index = index + 1;2579 attachment.set( 'menuOrder', index );2580 return [ attachment.id, index ];2581 }).object().value();2582 2583 if ( _.isEmpty( attachments ) ) {2584 return;2585 }2586 2587 return wp.media.post( 'save-attachment-order', {2588 nonce: wp.media.model.settings.post.nonce,2589 post_id: wp.media.model.settings.post.id,2590 attachments: attachments2591 });2592 }2593 }, {2594 /**2595 * A function to compare two attachment models in an attachments collection.2596 *2597 * Used as the default comparator for instances of wp.media.model.Attachments2598 * and its subclasses. @see wp.media.model.Attachments._changeOrderby().2599 *2600 * @static2601 *2602 * @param {Backbone.Model} a2603 * @param {Backbone.Model} b2604 * @param {Object} options2605 * @returns {Number} -1 if the first model should come before the second,2606 * 0 if they are of the same rank and2607 * 1 if the first model should come after.2608 */2609 comparator: function( a, b, options ) {2610 var key = this.props.get('orderby'),2611 order = this.props.get('order') || 'DESC',2612 ac = a.cid,2613 bc = b.cid;2614 2615 a = a.get( key );2616 b = b.get( key );2617 2618 if ( 'date' === key || 'modified' === key ) {2619 a = a || new Date();2620 b = b || new Date();2621 }2622 2623 // If `options.ties` is set, don't enforce the `cid` tiebreaker.2624 if ( options && options.ties ) {2625 ac = bc = null;2626 }2627 2628 return ( 'DESC' === order ) ? wp.media.compare( a, b, ac, bc ) : wp.media.compare( b, a, bc, ac );2629 },2630 /**2631 * @namespace2632 */2633 filters: {2634 /**2635 * @static2636 * Note that this client-side searching is *not* equivalent2637 * to our server-side searching.2638 *2639 * @param {wp.media.model.Attachment} attachment2640 *2641 * @this wp.media.model.Attachments2642 *2643 * @returns {Boolean}2644 */2645 search: function( attachment ) {2646 if ( ! this.props.get('search') ) {2647 return true;2648 }2649 2650 return _.any(['title','filename','description','caption','name'], function( key ) {2651 var value = attachment.get( key );2652 return value && -1 !== value.search( this.props.get('search') );2653 }, this );2654 },2655 /**2656 * @static2657 * @param {wp.media.model.Attachment} attachment2658 *2659 * @this wp.media.model.Attachments2660 *2661 * @returns {Boolean}2662 */2663 type: function( attachment ) {2664 var type = this.props.get('type');2665 return ! type || -1 !== type.indexOf( attachment.get('type') );2666 },2667 /**2668 * @static2669 * @param {wp.media.model.Attachment} attachment2670 *2671 * @this wp.media.model.Attachments2672 *2673 * @returns {Boolean}2674 */2675 uploadedTo: function( attachment ) {2676 var uploadedTo = this.props.get('uploadedTo');2677 if ( _.isUndefined( uploadedTo ) ) {2678 return true;2679 }2680 2681 return uploadedTo === attachment.get('uploadedTo');2682 },2683 /**2684 * @static2685 * @param {wp.media.model.Attachment} attachment2686 *2687 * @this wp.media.model.Attachments2688 *2689 * @returns {Boolean}2690 */2691 status: function( attachment ) {2692 var status = this.props.get('status');2693 if ( _.isUndefined( status ) ) {2694 return true;2695 }2696 2697 return status === attachment.get('status');2698 }2699 }2700 });2701 2702 module.exports = Attachments;2703 },{"./attachment.js":16,"./query.js":19}],18:[function(require,module,exports){2704 /*globals jQuery, Backbone */2705 2706 /**2707 * wp.media.model.PostImage2708 *2709 * An instance of an image that's been embedded into a post.2710 *2711 * Used in the embedded image attachment display settings modal - @see wp.media.view.MediaFrame.ImageDetails.2712 *2713 * @class2714 * @augments Backbone.Model2715 *2716 * @param {int} [attributes] Initial model attributes.2717 * @param {int} [attributes.attachment_id] ID of the attachment.2718 **/2719 var Attachment = require( './attachment' ),2720 PostImage;2721 2722 PostImage = Backbone.Model.extend({2723 2724 initialize: function( attributes ) {2725 this.attachment = false;2726 2727 if ( attributes.attachment_id ) {2728 this.attachment = Attachment.get( attributes.attachment_id );2729 if ( this.attachment.get( 'url' ) ) {2730 this.dfd = jQuery.Deferred();2731 this.dfd.resolve();2732 } else {2733 this.dfd = this.attachment.fetch();2734 }2735 this.bindAttachmentListeners();2736 }2737 2738 // keep url in sync with changes to the type of link2739 this.on( 'change:link', this.updateLinkUrl, this );2740 this.on( 'change:size', this.updateSize, this );2741 2742 this.setLinkTypeFromUrl();2743 this.setAspectRatio();2744 2745 this.set( 'originalUrl', attributes.url );2746 },2747 2748 bindAttachmentListeners: function() {2749 this.listenTo( this.attachment, 'sync', this.setLinkTypeFromUrl );2750 this.listenTo( this.attachment, 'sync', this.setAspectRatio );2751 this.listenTo( this.attachment, 'change', this.updateSize );2752 },2753 2754 changeAttachment: function( attachment, props ) {2755 this.stopListening( this.attachment );2756 this.attachment = attachment;2757 this.bindAttachmentListeners();2758 2759 this.set( 'attachment_id', this.attachment.get( 'id' ) );2760 this.set( 'caption', this.attachment.get( 'caption' ) );2761 this.set( 'alt', this.attachment.get( 'alt' ) );2762 this.set( 'size', props.get( 'size' ) );2763 this.set( 'align', props.get( 'align' ) );2764 this.set( 'link', props.get( 'link' ) );2765 this.updateLinkUrl();2766 this.updateSize();2767 },2768 2769 setLinkTypeFromUrl: function() {2770 var linkUrl = this.get( 'linkUrl' ),2771 type;2772 2773 if ( ! linkUrl ) {2774 this.set( 'link', 'none' );2775 return;2776 }2777 2778 // default to custom if there is a linkUrl2779 type = 'custom';2780 2781 if ( this.attachment ) {2782 if ( this.attachment.get( 'url' ) === linkUrl ) {2783 type = 'file';2784 } else if ( this.attachment.get( 'link' ) === linkUrl ) {2785 type = 'post';2786 }2787 } else {2788 if ( this.get( 'url' ) === linkUrl ) {2789 type = 'file';2790 }2791 }2792 2793 this.set( 'link', type );2794 },2795 2796 updateLinkUrl: function() {2797 var link = this.get( 'link' ),2798 url;2799 2800 switch( link ) {2801 case 'file':2802 if ( this.attachment ) {2803 url = this.attachment.get( 'url' );2804 } else {2805 url = this.get( 'url' );2806 }2807 this.set( 'linkUrl', url );2808 break;2809 case 'post':2810 this.set( 'linkUrl', this.attachment.get( 'link' ) );2811 break;2812 case 'none':2813 this.set( 'linkUrl', '' );2814 break;2815 }2816 },2817 2818 updateSize: function() {2819 var size;2820 2821 if ( ! this.attachment ) {2822 return;2823 }2824 2825 if ( this.get( 'size' ) === 'custom' ) {2826 this.set( 'width', this.get( 'customWidth' ) );2827 this.set( 'height', this.get( 'customHeight' ) );2828 this.set( 'url', this.get( 'originalUrl' ) );2829 return;2830 }2831 2832 size = this.attachment.get( 'sizes' )[ this.get( 'size' ) ];2833 2834 if ( ! size ) {2835 return;2836 }2837 2838 this.set( 'url', size.url );2839 this.set( 'width', size.width );2840 this.set( 'height', size.height );2841 },2842 2843 setAspectRatio: function() {2844 var full;2845 2846 if ( this.attachment && this.attachment.get( 'sizes' ) ) {2847 full = this.attachment.get( 'sizes' ).full;2848 2849 if ( full ) {2850 this.set( 'aspectRatio', full.width / full.height );2851 return;2852 }2853 }2854 2855 this.set( 'aspectRatio', this.get( 'customWidth' ) / this.get( 'customHeight' ) );2856 }2857 });2858 2859 module.exports = PostImage;2860 },{"./attachment":16}],19:[function(require,module,exports){2861 /*globals jQuery, _, wp */2862 2863 /**2864 * wp.media.model.Query2865 *2866 * A collection of attachments that match the supplied query arguments.2867 *2868 * Note: Do NOT change this.args after the query has been initialized.2869 * Things will break.2870 *2871 * @class2872 * @augments wp.media.model.Attachments2873 * @augments Backbone.Collection2874 *2875 * @param {array} [models] Models to initialize with the collection.2876 * @param {object} [options] Options hash.2877 * @param {object} [options.args] Attachments query arguments.2878 * @param {object} [options.args.posts_per_page]2879 */2880 var Attachments = require( './attachments.js' ),2881 Query;2882 2883 Query = Attachments.extend({2884 /**2885 * @global wp.Uploader2886 *2887 * @param {array} [models=[]] Array of initial models to populate the collection.2888 * @param {object} [options={}]2889 */2890 initialize: function( models, options ) {2891 var allowed;2892 2893 options = options || {};2894 Attachments.prototype.initialize.apply( this, arguments );2895 2896 this.args = options.args;2897 this._hasMore = true;2898 this.created = new Date();2899 2900 this.filters.order = function( attachment ) {2901 var orderby = this.props.get('orderby'),2902 order = this.props.get('order');2903 2904 if ( ! this.comparator ) {2905 return true;2906 }2907 2908 // We want any items that can be placed before the last2909 // item in the set. If we add any items after the last2910 // item, then we can't guarantee the set is complete.2911 if ( this.length ) {2912 return 1 !== this.comparator( attachment, this.last(), { ties: true });2913 2914 // Handle the case where there are no items yet and2915 // we're sorting for recent items. In that case, we want2916 // changes that occurred after we created the query.2917 } else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) {2918 return attachment.get( orderby ) >= this.created;2919 2920 // If we're sorting by menu order and we have no items,2921 // accept any items that have the default menu order (0).2922 } else if ( 'ASC' === order && 'menuOrder' === orderby ) {2923 return attachment.get( orderby ) === 0;2924 }2925 2926 // Otherwise, we don't want any items yet.2927 return false;2928 };2929 2930 // Observe the central `wp.Uploader.queue` collection to watch for2931 // new matches for the query.2932 //2933 // Only observe when a limited number of query args are set. There2934 // are no filters for other properties, so observing will result in2935 // false positives in those queries.2936 allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent' ];2937 if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) {2938 this.observe( wp.Uploader.queue );2939 }2940 },2941 /**2942 * Whether there are more attachments that haven't been sync'd from the server2943 * that match the collection's query.2944 *2945 * @returns {boolean}2946 */2947 hasMore: function() {2948 return this._hasMore;2949 },2950 /**2951 * Fetch more attachments from the server for the collection.2952 *2953 * @param {object} [options={}]2954 * @returns {Promise}2955 */2956 more: function( options ) {2957 var query = this;2958 2959 // If there is already a request pending, return early with the Deferred object.2960 if ( this._more && 'pending' === this._more.state() ) {2961 return this._more;2962 }2963 2964 if ( ! this.hasMore() ) {2965 return jQuery.Deferred().resolveWith( this ).promise();2966 }2967 2968 options = options || {};2969 options.remove = false;2970 2971 return this._more = this.fetch( options ).done( function( resp ) {2972 if ( _.isEmpty( resp ) || -1 === this.args.posts_per_page || resp.length < this.args.posts_per_page ) {2973 query._hasMore = false;2974 }2975 });2976 },2977 /**2978 * Overrides Backbone.Collection.sync2979 * Overrides wp.media.model.Attachments.sync2980 *2981 * @param {String} method2982 * @param {Backbone.Model} model2983 * @param {Object} [options={}]2984 * @returns {Promise}2985 */2986 sync: function( method, model, options ) {2987 var args, fallback;2988 2989 // Overload the read method so Attachment.fetch() functions correctly.2990 if ( 'read' === method ) {2991 options = options || {};2992 options.context = this;2993 options.data = _.extend( options.data || {}, {2994 action: 'query-attachments',2995 post_id: wp.media.model.settings.post.id2996 });2997 2998 // Clone the args so manipulation is non-destructive.2999 args = _.clone( this.args );3000 3001 // Determine which page to query.3002 if ( -1 !== args.posts_per_page ) {3003 args.paged = Math.floor( this.length / args.posts_per_page ) + 1;3004 }3005 3006 options.data.query = args;3007 return wp.media.ajax( options );3008 3009 // Otherwise, fall back to Backbone.sync()3010 } else {3011 /**3012 * Call wp.media.model.Attachments.sync or Backbone.sync3013 */3014 fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone;3015 return fallback.sync.apply( this, arguments );3016 }3017 }3018 }, {3019 /**3020 * @readonly3021 */3022 defaultProps: {3023 orderby: 'date',3024 order: 'DESC'3025 },3026 /**3027 * @readonly3028 */3029 defaultArgs: {3030 posts_per_page: 403031 },3032 /**3033 * @readonly3034 */3035 orderby: {3036 allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ],3037 /**3038 * A map of JavaScript orderby values to their WP_Query equivalents.3039 * @type {Object}3040 */3041 valuemap: {3042 'id': 'ID',3043 'uploadedTo': 'parent',3044 'menuOrder': 'menu_order ID'3045 }3046 },3047 /**3048 * A map of JavaScript query properties to their WP_Query equivalents.3049 *3050 * @readonly3051 */3052 propmap: {3053 'search': 's',3054 'type': 'post_mime_type',3055 'perPage': 'posts_per_page',3056 'menuOrder': 'menu_order',3057 'uploadedTo': 'post_parent',3058 'status': 'post_status',3059 'include': 'post__in',3060 'exclude': 'post__not_in'3061 },3062 /**3063 * Creates and returns an Attachments Query collection given the properties.3064 *3065 * Caches query objects and reuses where possible.3066 *3067 * @static3068 * @method3069 *3070 * @param {object} [props]3071 * @param {Object} [props.cache=true] Whether to use the query cache or not.3072 * @param {Object} [props.order]3073 * @param {Object} [props.orderby]3074 * @param {Object} [props.include]3075 * @param {Object} [props.exclude]3076 * @param {Object} [props.s]3077 * @param {Object} [props.post_mime_type]3078 * @param {Object} [props.posts_per_page]3079 * @param {Object} [props.menu_order]3080 * @param {Object} [props.post_parent]3081 * @param {Object} [props.post_status]3082 * @param {Object} [options]3083 *3084 * @returns {wp.media.model.Query} A new Attachments Query collection.3085 */3086 get: (function(){3087 /**3088 * @static3089 * @type Array3090 */3091 var queries = [];3092 3093 /**3094 * @returns {Query}3095 */3096 return function( props, options ) {3097 var args = {},3098 orderby = Query.orderby,3099 defaults = Query.defaultProps,3100 query,3101 cache = !! props.cache || _.isUndefined( props.cache );3102 3103 // Remove the `query` property. This isn't linked to a query,3104 // this *is* the query.3105 delete props.query;3106 delete props.cache;3107 3108 // Fill default args.3109 _.defaults( props, defaults );3110 3111 // Normalize the order.3112 props.order = props.order.toUpperCase();3113 if ( 'DESC' !== props.order && 'ASC' !== props.order ) {3114 props.order = defaults.order.toUpperCase();3115 }3116 3117 // Ensure we have a valid orderby value.3118 if ( ! _.contains( orderby.allowed, props.orderby ) ) {3119 props.orderby = defaults.orderby;3120 }3121 3122 _.each( [ 'include', 'exclude' ], function( prop ) {3123 if ( props[ prop ] && ! _.isArray( props[ prop ] ) ) {3124 props[ prop ] = [ props[ prop ] ];3125 }3126 } );3127 3128 // Generate the query `args` object.3129 // Correct any differing property names.3130 _.each( props, function( value, prop ) {3131 if ( _.isNull( value ) ) {3132 return;3133 }3134 3135 args[ Query.propmap[ prop ] || prop ] = value;3136 });3137 3138 // Fill any other default query args.3139 _.defaults( args, Query.defaultArgs );3140 3141 // `props.orderby` does not always map directly to `args.orderby`.3142 // Substitute exceptions specified in orderby.keymap.3143 args.orderby = orderby.valuemap[ props.orderby ] || props.orderby;3144 3145 // Search the query cache for a matching query.3146 if ( cache ) {3147 query = _.find( queries, function( query ) {3148 return _.isEqual( query.args, args );3149 });3150 } else {3151 queries = [];3152 }3153 3154 // Otherwise, create a new query and add it to the cache.3155 if ( ! query ) {3156 query = new Query( [], _.extend( options || {}, {3157 props: props,3158 args: args3159 } ) );3160 queries.push( query );3161 }3162 3163 return query;3164 };3165 }())3166 });3167 3168 module.exports = Query;3169 },{"./attachments.js":17}],20:[function(require,module,exports){3170 /*globals _ */3171 3172 /**3173 * wp.media.model.Selection3174 *3175 * A selection of attachments.3176 *3177 * @class3178 * @augments wp.media.model.Attachments3179 * @augments Backbone.Collection3180 */3181 var Attachments = require( './attachments.js' ),3182 Selection;3183 3184 Selection = Attachments.extend({3185 /**3186 * Refresh the `single` model whenever the selection changes.3187 * Binds `single` instead of using the context argument to ensure3188 * it receives no parameters.3189 *3190 * @param {Array} [models=[]] Array of models used to populate the collection.3191 * @param {Object} [options={}]3192 */3193 initialize: function( models, options ) {3194 /**3195 * call 'initialize' directly on the parent class3196 */3197 Attachments.prototype.initialize.apply( this, arguments );3198 this.multiple = options && options.multiple;3199 3200 this.on( 'add remove reset', _.bind( this.single, this, false ) );3201 },3202 3203 /**3204 * If the workflow does not support multi-select, clear out the selection3205 * before adding a new attachment to it.3206 *3207 * @param {Array} models3208 * @param {Object} options3209 * @returns {wp.media.model.Attachment[]}3210 */3211 add: function( models, options ) {3212 if ( ! this.multiple ) {3213 this.remove( this.models );3214 }3215 /**3216 * call 'add' directly on the parent class3217 */3218 return Attachments.prototype.add.call( this, models, options );3219 },3220 3221 /**3222 * Fired when toggling (clicking on) an attachment in the modal.3223 *3224 * @param {undefined|boolean|wp.media.model.Attachment} model3225 *3226 * @fires wp.media.model.Selection#selection:single3227 * @fires wp.media.model.Selection#selection:unsingle3228 *3229 * @returns {Backbone.Model}3230 */3231 single: function( model ) {3232 var previous = this._single;3233 3234 // If a `model` is provided, use it as the single model.3235 if ( model ) {3236 this._single = model;3237 }3238 // If the single model isn't in the selection, remove it.3239 if ( this._single && ! this.get( this._single.cid ) ) {3240 delete this._single;3241 }3242 3243 this._single = this._single || this.last();3244 3245 // If single has changed, fire an event.3246 if ( this._single !== previous ) {3247 if ( previous ) {3248 previous.trigger( 'selection:unsingle', previous, this );3249 3250 // If the model was already removed, trigger the collection3251 // event manually.3252 if ( ! this.get( previous.cid ) ) {3253 this.trigger( 'selection:unsingle', previous, this );3254 }3255 }3256 if ( this._single ) {3257 this._single.trigger( 'selection:single', this._single, this );3258 }3259 }3260 3261 // Return the single model, or the last model as a fallback.3262 return this._single;3263 }3264 });3265 3266 module.exports = Selection;3267 },{"./attachments.js":17}],21:[function(require,module,exports){3268 1996 /*globals _ */ 3269 1997 … … 3332 2060 3333 2061 module.exports = selectionSync; 3334 },{}], 22:[function(require,module,exports){2062 },{}],17:[function(require,module,exports){ 3335 2063 /* global _wpMediaViewsL10n, confirm, getUserSetting, setUserSetting */ 3336 2064 ( function( $, _ ) { … … 3481 2209 3482 2210 }(jQuery, _)); 3483 },{"./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){2211 },{"./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){ 3484 2212 /*globals _ */ 3485 2213 … … 3567 2295 3568 2296 module.exports = AttachmentCompat; 3569 },{"./view.js":7 6}],24:[function(require,module,exports){2297 },{"./view.js":71}],19:[function(require,module,exports){ 3570 2298 /*globals _, jQuery */ 3571 2299 … … 3646 2374 3647 2375 module.exports = AttachmentFilters; 3648 },{"./view.js":7 6}],25:[function(require,module,exports){2376 },{"./view.js":71}],20:[function(require,module,exports){ 3649 2377 /*globals _, wp */ 3650 2378 … … 3738 2466 3739 2467 module.exports = All; 3740 },{"../attachment-filters.js": 24}],26:[function(require,module,exports){2468 },{"../attachment-filters.js":19}],21:[function(require,module,exports){ 3741 2469 /*globals _, wp */ 3742 2470 … … 3781 2509 3782 2510 module.exports = DateFilter; 3783 },{"../attachment-filters.js": 24}],27:[function(require,module,exports){2511 },{"../attachment-filters.js":19}],22:[function(require,module,exports){ 3784 2512 /*globals wp */ 3785 2513 … … 3842 2570 3843 2571 module.exports = Uploaded; 3844 },{"../attachment-filters.js": 24}],28:[function(require,module,exports){2572 },{"../attachment-filters.js":19}],23:[function(require,module,exports){ 3845 2573 /*globals _, wp, jQuery */ 3846 2574 … … 4397 3125 4398 3126 module.exports = Attachment; 4399 },{"./view.js":7 6}],29:[function(require,module,exports){3127 },{"./view.js":71}],24:[function(require,module,exports){ 4400 3128 /*globals _, wp */ 4401 3129 … … 4538 3266 4539 3267 module.exports = Details; 4540 },{"../attachment.js":2 8}],30:[function(require,module,exports){3268 },{"../attachment.js":23}],25:[function(require,module,exports){ 4541 3269 /** 4542 3270 * wp.media.view.Attachment.EditLibrary … … 4558 3286 4559 3287 module.exports = EditLibrary; 4560 },{"../attachment.js":2 8}],31:[function(require,module,exports){3288 },{"../attachment.js":23}],26:[function(require,module,exports){ 4561 3289 /** 4562 3290 * wp.media.view.Attachments.EditSelection … … 4579 3307 4580 3308 module.exports = EditSelection; 4581 },{"./selection.js": 33}],32:[function(require,module,exports){3309 },{"./selection.js":28}],27:[function(require,module,exports){ 4582 3310 /** 4583 3311 * wp.media.view.Attachment.Library … … 4599 3327 4600 3328 module.exports = Library; 4601 },{"../attachment.js":2 8}],33:[function(require,module,exports){3329 },{"../attachment.js":23}],28:[function(require,module,exports){ 4602 3330 /** 4603 3331 * wp.media.view.Attachment.Selection … … 4623 3351 4624 3352 module.exports = Selection; 4625 },{"../attachment.js":2 8}],34:[function(require,module,exports){3353 },{"../attachment.js":23}],29:[function(require,module,exports){ 4626 3354 /*globals _, wp, jQuery */ 4627 3355 … … 4924 3652 4925 3653 module.exports = Attachments; 4926 },{"./attachment.js":2 8,"./view.js":76}],35:[function(require,module,exports){3654 },{"./attachment.js":23,"./view.js":71}],30:[function(require,module,exports){ 4927 3655 /*globals _, wp, jQuery */ 4928 3656 … … 5384 4112 5385 4113 module.exports = AttachmentsBrowser; 5386 },{"../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){4114 },{"../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){ 5387 4115 /*globals _ */ 5388 4116 … … 5416 4144 5417 4145 module.exports = Selection; 5418 },{"../attachment/selection.js": 33,"../attachments.js":34}],37:[function(require,module,exports){4146 },{"../attachment/selection.js":28,"../attachments.js":29}],32:[function(require,module,exports){ 5419 4147 /*globals _, Backbone, jQuery */ 5420 4148 … … 5465 4193 5466 4194 module.exports = ButtonGroup; 5467 },{"./button.js":3 8,"./view.js":76}],38:[function(require,module,exports){4195 },{"./button.js":33,"./view.js":71}],33:[function(require,module,exports){ 5468 4196 /*globals _, Backbone */ 5469 4197 … … 5555 4283 5556 4284 module.exports = Button; 5557 },{"./view.js":7 6}],39:[function(require,module,exports){4285 },{"./view.js":71}],34:[function(require,module,exports){ 5558 4286 /*globals _, wp, jQuery */ 5559 4287 … … 5624 4352 5625 4353 module.exports = Cropper; 5626 },{"./uploader/status-error.js": 73,"./uploader/status.js":74,"./view.js":76}],40:[function(require,module,exports){4354 },{"./uploader/status-error.js":68,"./uploader/status.js":69,"./view.js":71}],35:[function(require,module,exports){ 5627 4355 /*globals _, wp */ 5628 4356 … … 5679 4407 5680 4408 module.exports = EditImage; 5681 },{"./view.js":7 6}],41:[function(require,module,exports){4409 },{"./view.js":71}],36:[function(require,module,exports){ 5682 4410 /** 5683 4411 * wp.media.view.Embed … … 5748 4476 5749 4477 module.exports = Embed; 5750 },{"./embed/image.js": 42,"./embed/link.js":43,"./embed/url.js":44,"./view.js":76}],42:[function(require,module,exports){4478 },{"./embed/image.js":37,"./embed/link.js":38,"./embed/url.js":39,"./view.js":71}],37:[function(require,module,exports){ 5751 4479 /*globals wp */ 5752 4480 … … 5782 4510 5783 4511 module.exports = EmbedImage; 5784 },{"../settings/attachment-display.js": 63}],43:[function(require,module,exports){4512 },{"../settings/attachment-display.js":58}],38:[function(require,module,exports){ 5785 4513 /*globals _, wp, jQuery */ 5786 4514 … … 5850 4578 5851 4579 module.exports = EmbedLink; 5852 },{"../settings.js": 62}],44:[function(require,module,exports){4580 },{"../settings.js":57}],39:[function(require,module,exports){ 5853 4581 /*globals _, wp, jQuery */ 5854 4582 … … 5932 4660 5933 4661 module.exports = EmbedUrl; 5934 },{"../view.js":7 6}],45:[function(require,module,exports){4662 },{"../view.js":71}],40:[function(require,module,exports){ 5935 4663 /** 5936 4664 * wp.media.view.FocusManager … … 5980 4708 5981 4709 module.exports = FocusManager; 5982 },{"./view.js":7 6}],46:[function(require,module,exports){4710 },{"./view.js":71}],41:[function(require,module,exports){ 5983 4711 /*globals _, Backbone */ 5984 4712 … … 6153 4881 6154 4882 module.exports = Frame; 6155 },{"../controllers/region.js":12,"../controllers/state-machine.js":14,"../controllers/state.js":15,"./view.js":7 6}],47:[function(require,module,exports){4883 },{"../controllers/region.js":12,"../controllers/state-machine.js":14,"../controllers/state.js":15,"./view.js":71}],42:[function(require,module,exports){ 6156 4884 /*globals wp */ 6157 4885 … … 6173 4901 var Select = require( './select.js' ), 6174 4902 Toolbar = require( '../toolbar.js' ), 6175 PostImage = require( '../../models/post-image.js' ),6176 Selection = require( '../../models/selection.js' ),6177 4903 ImageDetailsController = require( '../../controllers/image-details.js' ), 6178 4904 ReplaceImageController = require( '../../controllers/replace-image.js' ), … … 6196 4922 6197 4923 initialize: function( options ) { 6198 this.image = new PostImage( options.metadata );6199 this.options.selection = new Selection( this.image.attachment, { multiple: false } );4924 this.image = new wp.media.model.PostImage( options.metadata ); 4925 this.options.selection = new wp.media.model.Selection( this.image.attachment, { multiple: false } ); 6200 4926 Select.prototype.initialize.apply( this, arguments ); 6201 4927 }, … … 6339 5065 6340 5066 module.exports = ImageDetails; 6341 },{"../../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){5067 },{"../../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){ 6342 5068 /*globals _, wp */ 6343 5069 … … 6366 5092 PlaylistSettings = require( '../settings/playlist.js' ), 6367 5093 AttachmentsBrowser = require( '../attachments/browser.js' ), 6368 SelectionModel = require( '../../models/selection.js' ),6369 5094 SelectionView = require( '../selection.js' ), 6370 5095 EmbedController = require( '../../controllers/embed.js' ), … … 6835 5560 models = selection.where({ type: 'image' }); 6836 5561 6837 edit.set( 'library', new SelectionModel( models, {5562 edit.set( 'library', new wp.media.model.Selection( models, { 6838 5563 props: selection.props.toJSON(), 6839 5564 multiple: true … … 6865 5590 models = selection.where({ type: 'audio' }); 6866 5591 6867 edit.set( 'library', new SelectionModel( models, {5592 edit.set( 'library', new wp.media.model.Selection( models, { 6868 5593 props: selection.props.toJSON(), 6869 5594 multiple: true … … 6895 5620 models = selection.where({ type: 'video' }); 6896 5621 6897 edit.set( 'library', new SelectionModel( models, {5622 edit.set( 'library', new wp.media.model.Selection( models, { 6898 5623 props: selection.props.toJSON(), 6899 5624 multiple: true … … 7092 5817 7093 5818 module.exports = Post; 7094 },{"../../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){5819 },{"../../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){ 7095 5820 /*globals _, wp */ 7096 5821 … … 7111 5836 var MediaFrame = require( '../media-frame.js' ), 7112 5837 Library = require( '../../controllers/library.js' ), 7113 AttachmentsModel = require( '../../models/attachments.js' ),7114 SelectionModel = require( '../../models/selection.js' ),7115 5838 AttachmentsBrowser = require( '../attachments/browser.js' ), 7116 5839 UploaderInline = require( '../uploader/inline.js' ), … … 7148 5871 var selection = this.options.selection; 7149 5872 7150 if ( ! (selection instanceof SelectionModel) ) {7151 this.options.selection = new SelectionModel( selection, {5873 if ( ! (selection instanceof wp.media.model.Selection) ) { 5874 this.options.selection = new wp.media.model.Selection( selection, { 7152 5875 multiple: this.options.multiple 7153 5876 }); … … 7155 5878 7156 5879 this._selection = { 7157 attachments: new AttachmentsModel(),5880 attachments: new wp.media.model.Attachments(), 7158 5881 difference: [] 7159 5882 }; … … 7269 5992 7270 5993 module.exports = Select; 7271 },{"../../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){5994 },{"../../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){ 7272 5995 /** 7273 5996 * wp.media.view.Iframe … … 7295 6018 7296 6019 module.exports = Iframe; 7297 },{"./view.js":7 6}],51:[function(require,module,exports){6020 },{"./view.js":71}],46:[function(require,module,exports){ 7298 6021 /*globals _, wp, jQuery */ 7299 6022 … … 7463 6186 7464 6187 module.exports = AttachmentDisplay; 7465 },{"./settings/attachment-display.js": 63}],52:[function(require,module,exports){6188 },{"./settings/attachment-display.js":58}],47:[function(require,module,exports){ 7466 6189 /** 7467 6190 * @class … … 7489 6212 7490 6213 module.exports = Label; 7491 },{"./view.js":7 6}],53:[function(require,module,exports){6214 },{"./view.js":71}],48:[function(require,module,exports){ 7492 6215 /*globals _, wp, jQuery */ 7493 6216 … … 7744 6467 7745 6468 module.exports = MediaFrame; 7746 },{"./frame.js":4 6,"./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){6469 },{"./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){ 7747 6470 /*globals wp, jQuery */ 7748 6471 … … 7818 6541 7819 6542 module.exports = MenuItem; 7820 },{"./view.js":7 6}],55:[function(require,module,exports){6543 },{"./view.js":71}],50:[function(require,module,exports){ 7821 6544 /** 7822 6545 * wp.media.view.Menu … … 7934 6657 7935 6658 module.exports = Menu; 7936 },{"./menu-item.js": 54,"./priority-list.js":57}],56:[function(require,module,exports){6659 },{"./menu-item.js":49,"./priority-list.js":52}],51:[function(require,module,exports){ 7937 6660 /*globals _, wp, jQuery */ 7938 6661 … … 8150 6873 8151 6874 module.exports = Modal; 8152 },{"./focus-manager.js":4 5,"./view.js":76}],57:[function(require,module,exports){6875 },{"./focus-manager.js":40,"./view.js":71}],52:[function(require,module,exports){ 8153 6876 /*globals _, Backbone */ 8154 6877 … … 8251 6974 8252 6975 module.exports = PriorityList; 8253 },{"./view.js":7 6}],58:[function(require,module,exports){6976 },{"./view.js":71}],53:[function(require,module,exports){ 8254 6977 /** 8255 6978 * wp.media.view.RouterItem … … 8277 7000 8278 7001 module.exports = RouterItem; 8279 },{"./menu-item.js": 54}],59:[function(require,module,exports){7002 },{"./menu-item.js":49}],54:[function(require,module,exports){ 8280 7003 /** 8281 7004 * wp.media.view.Router … … 8314 7037 8315 7038 module.exports = Router; 8316 },{"./menu.js":5 5,"./router-item.js":58}],60:[function(require,module,exports){7039 },{"./menu.js":50,"./router-item.js":53}],55:[function(require,module,exports){ 8317 7040 /*globals wp */ 8318 7041 … … 8364 7087 8365 7088 module.exports = Search; 8366 },{"./view.js":7 6}],61:[function(require,module,exports){7089 },{"./view.js":71}],56:[function(require,module,exports){ 8367 7090 /*globals _, Backbone, wp */ 8368 7091 … … 8450 7173 8451 7174 module.exports = Selection; 8452 },{"./attachments/selection.js":3 6,"./view.js":76}],62:[function(require,module,exports){7175 },{"./attachments/selection.js":31,"./view.js":71}],57:[function(require,module,exports){ 8453 7176 /*globals _, Backbone, jQuery */ 8454 7177 … … 8572 7295 8573 7296 module.exports = Settings; 8574 },{"./view.js":7 6}],63:[function(require,module,exports){7297 },{"./view.js":71}],58:[function(require,module,exports){ 8575 7298 /*globals _, wp */ 8576 7299 … … 8667 7390 8668 7391 module.exports = AttachmentDisplay; 8669 },{"../settings.js": 62}],64:[function(require,module,exports){7392 },{"../settings.js":57}],59:[function(require,module,exports){ 8670 7393 /*globals wp */ 8671 7394 … … 8688 7411 8689 7412 module.exports = Gallery; 8690 },{"../settings.js": 62}],65:[function(require,module,exports){7413 },{"../settings.js":57}],60:[function(require,module,exports){ 8691 7414 /*globals wp */ 8692 7415 … … 8709 7432 8710 7433 module.exports = Playlist; 8711 },{"../settings.js": 62}],66:[function(require,module,exports){7434 },{"../settings.js":57}],61:[function(require,module,exports){ 8712 7435 /** 8713 7436 * wp.media.view.Sidebar … … 8727 7450 8728 7451 module.exports = Sidebar; 8729 },{"./priority-list.js":5 7}],67:[function(require,module,exports){7452 },{"./priority-list.js":52}],62:[function(require,module,exports){ 8730 7453 /*globals _, wp */ 8731 7454 … … 8766 7489 8767 7490 module.exports = Spinner; 8768 },{"./view.js":7 6}],68:[function(require,module,exports){7491 },{"./view.js":71}],63:[function(require,module,exports){ 8769 7492 /*globals Backbone, _ */ 8770 7493 … … 8929 7652 8930 7653 module.exports = Toolbar; 8931 },{"./button.js":3 8,"./priority-list.js":57,"./view.js":76}],69:[function(require,module,exports){7654 },{"./button.js":33,"./priority-list.js":52,"./view.js":71}],64:[function(require,module,exports){ 8932 7655 /*globals _, wp */ 8933 7656 … … 8967 7690 8968 7691 module.exports = Embed; 8969 },{"./select.js": 70}],70:[function(require,module,exports){7692 },{"./select.js":65}],65:[function(require,module,exports){ 8970 7693 /*globals _, wp */ 8971 7694 … … 9038 7761 9039 7762 module.exports = Select; 9040 },{"../toolbar.js":6 8}],71:[function(require,module,exports){7763 },{"../toolbar.js":63}],66:[function(require,module,exports){ 9041 7764 /*globals _, wp, jQuery */ 9042 7765 … … 9260 7983 9261 7984 module.exports = EditorUploader; 9262 },{"../view.js":7 6}],72:[function(require,module,exports){7985 },{"../view.js":71}],67:[function(require,module,exports){ 9263 7986 /*globals _, wp */ 9264 7987 … … 9393 8116 9394 8117 module.exports = UploaderInline; 9395 },{"../view.js":7 6,"./status.js":74}],73:[function(require,module,exports){8118 },{"../view.js":71,"./status.js":69}],68:[function(require,module,exports){ 9396 8119 /*globals wp */ 9397 8120 … … 9413 8136 9414 8137 module.exports = UploaderStatusError; 9415 },{"../view.js":7 6}],74:[function(require,module,exports){8138 },{"../view.js":71}],69:[function(require,module,exports){ 9416 8139 /*globals _, wp */ 9417 8140 … … 9553 8276 9554 8277 module.exports = UploaderStatus; 9555 },{"../view.js":7 6,"./status-error.js":73}],75:[function(require,module,exports){8278 },{"../view.js":71,"./status-error.js":68}],70:[function(require,module,exports){ 9556 8279 /*globals _, wp, jQuery */ 9557 8280 … … 9666 8389 9667 8390 module.exports = UploaderWindow; 9668 },{"../view.js":7 6}],76:[function(require,module,exports){8391 },{"../view.js":71}],71:[function(require,module,exports){ 9669 8392 /*globals wp */ 9670 8393 … … 9733 8456 9734 8457 module.exports = View; 9735 },{}]},{},[ 22]);8458 },{}]},{},[17]); -
trunk/src/wp-includes/js/media/views/frame/image-details.js
r31373 r31379 18 18 var Select = require( './select.js' ), 19 19 Toolbar = require( '../toolbar.js' ), 20 PostImage = require( '../../models/post-image.js' ),21 Selection = require( '../../models/selection.js' ),22 20 ImageDetailsController = require( '../../controllers/image-details.js' ), 23 21 ReplaceImageController = require( '../../controllers/replace-image.js' ), … … 41 39 42 40 initialize: function( options ) { 43 this.image = new PostImage( options.metadata );44 this.options.selection = new Selection( this.image.attachment, { multiple: false } );41 this.image = new wp.media.model.PostImage( options.metadata ); 42 this.options.selection = new wp.media.model.Selection( this.image.attachment, { multiple: false } ); 45 43 Select.prototype.initialize.apply( this, arguments ); 46 44 }, -
trunk/src/wp-includes/js/media/views/frame/media-details.js
r31373 r31379 16 16 Toolbar = require( '../toolbar.js' ), 17 17 Select = require( './select.js' ), 18 Selection = require( '../../models/selection.js' ),19 PostMedia = require( '../../models/post-media.js' ),20 18 l10n = wp.media.view.l10n, 21 19 MediaDetails; … … 37 35 this.addText = options.addText; 38 36 39 this.media = new PostMedia( options.metadata );40 this.options.selection = new Selection( this.media.attachment, { multiple: false } );37 this.media = new wp.media.model.PostMedia( options.metadata ); 38 this.options.selection = new wp.media.model.Selection( this.media.attachment, { multiple: false } ); 41 39 Select.prototype.initialize.apply( this, arguments ); 42 40 }, -
trunk/src/wp-includes/js/media/views/frame/post.js
r31373 r31379 25 25 PlaylistSettings = require( '../settings/playlist.js' ), 26 26 AttachmentsBrowser = require( '../attachments/browser.js' ), 27 SelectionModel = require( '../../models/selection.js' ),28 27 SelectionView = require( '../selection.js' ), 29 28 EmbedController = require( '../../controllers/embed.js' ), … … 494 493 models = selection.where({ type: 'image' }); 495 494 496 edit.set( 'library', new SelectionModel( models, {495 edit.set( 'library', new wp.media.model.Selection( models, { 497 496 props: selection.props.toJSON(), 498 497 multiple: true … … 524 523 models = selection.where({ type: 'audio' }); 525 524 526 edit.set( 'library', new SelectionModel( models, {525 edit.set( 'library', new wp.media.model.Selection( models, { 527 526 props: selection.props.toJSON(), 528 527 multiple: true … … 554 553 models = selection.where({ type: 'video' }); 555 554 556 edit.set( 'library', new SelectionModel( models, {555 edit.set( 'library', new wp.media.model.Selection( models, { 557 556 props: selection.props.toJSON(), 558 557 multiple: true -
trunk/src/wp-includes/js/media/views/frame/select.js
r31373 r31379 17 17 var MediaFrame = require( '../media-frame.js' ), 18 18 Library = require( '../../controllers/library.js' ), 19 AttachmentsModel = require( '../../models/attachments.js' ),20 SelectionModel = require( '../../models/selection.js' ),21 19 AttachmentsBrowser = require( '../attachments/browser.js' ), 22 20 UploaderInline = require( '../uploader/inline.js' ), … … 54 52 var selection = this.options.selection; 55 53 56 if ( ! (selection instanceof SelectionModel) ) {57 this.options.selection = new SelectionModel( selection, {54 if ( ! (selection instanceof wp.media.model.Selection) ) { 55 this.options.selection = new wp.media.model.Selection( selection, { 58 56 multiple: this.options.multiple 59 57 }); … … 61 59 62 60 this._selection = { 63 attachments: new AttachmentsModel(),61 attachments: new wp.media.model.Attachments(), 64 62 difference: [] 65 63 };
Note: See TracChangeset
for help on using the changeset viewer.