+ if ( 'select' === attributes.frame && MediaFrame.Select ) {
+ frame = new MediaFrame.Select( attributes );
+ } else if ( 'post' === attributes.frame && MediaFrame.Post ) {
+ frame = new MediaFrame.Post( attributes );
+ } else if ( 'manage' === attributes.frame && MediaFrame.Manage ) {
+ frame = new MediaFrame.Manage( attributes );
+ } else if ( 'image' === attributes.frame && MediaFrame.ImageDetails ) {
+ frame = new MediaFrame.ImageDetails( attributes );
+ } else if ( 'audio' === attributes.frame && MediaFrame.AudioDetails ) {
+ frame = new MediaFrame.AudioDetails( attributes );
+ } else if ( 'video' === attributes.frame && MediaFrame.VideoDetails ) {
+ frame = new MediaFrame.VideoDetails( attributes );
+ } else if ( 'edit-attachments' === attributes.frame && MediaFrame.EditAttachments ) {
+ frame = new MediaFrame.EditAttachments( attributes );
+ }
+
+ delete attributes.frame;
+
+ media.frame = frame;
+
+ return frame;
+};
+
+_.extend( media, { model: {}, view: {}, controller: {}, frames: {} });
+
+// Link any localized strings.
+l10n = media.model.l10n = window._wpMediaModelsL10n || {};
+
+// Link any settings.
+media.model.settings = l10n.settings || {};
+delete l10n.settings;
+
+Attachment = media.model.Attachment = require( './models/attachment.js' );
+Attachments = media.model.Attachments = require( './models/attachments.js' );
+
+media.model.Query = require( './models/query.js' );
+media.model.PostImage = require( './models/post-image.js' );
+media.model.Selection = require( './models/selection.js' );
+
+/**
+ * ========================================================================
+ * UTILITIES
+ * ========================================================================
+ */
+
+/**
+ * A basic equality comparator for Backbone models.
+ *
+ * Used to order models within a collection - @see wp.media.model.Attachments.comparator().
+ *
+ * @param {mixed} a The primary parameter to compare.
+ * @param {mixed} b The primary parameter to compare.
+ * @param {string} ac The fallback parameter to compare, a's cid.
+ * @param {string} bc The fallback parameter to compare, b's cid.
+ * @return {number} -1: a should come before b.
+ * 0: a and b are of the same rank.
+ * 1: b should come before a.
+ */
+media.compare = function( a, b, ac, bc ) {
+ if ( _.isEqual( a, b ) ) {
+ return ac === bc ? 0 : (ac > bc ? -1 : 1);
+ } else {
+ return a > b ? -1 : 1;
+ }
+};
+
+_.extend( media, {