<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[26985] trunk/src/wp-includes/js/media-models.js: Add initial JSDoc blocks to `media-models.js`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/26985">26985</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-01-20 23:39:44 +0000 (Mon, 20 Jan 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add initial JSDoc blocks to `media-models.js`. The initial blocks are a baseline to work from and invite future iterations. Initial commit is to avoid commits this large in the future.
See <a href="http://core.trac.wordpress.org/ticket/26870">#26870</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesjsmediamodelsjs">trunk/src/wp-includes/js/media-models.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesjsmediamodelsjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/media-models.js (26984 => 26985)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/media-models.js 2014-01-20 23:34:57 UTC (rev 26984)
+++ trunk/src/wp-includes/js/media-models.js 2014-01-20 23:39:44 UTC (rev 26985)
</span><span class="lines">@@ -12,23 +12,25 @@
</span><span class="cx"> * Does nothing if the controllers do not exist.
</span><span class="cx"> *
</span><span class="cx"> * @param {object} attributes The properties passed to the main media controller.
</span><del>- * @return {object} A media workflow.
</del><ins>+ * @return {wp.media.view.MediaFrame} A media workflow.
</ins><span class="cx"> */
</span><span class="cx"> media = wp.media = function( attributes ) {
</span><span class="cx"> var MediaFrame = media.view.MediaFrame,
</span><span class="cx"> frame;
</span><span class="cx">
</span><del>- if ( ! MediaFrame )
</del><ins>+ if ( ! MediaFrame ) {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> attributes = _.defaults( attributes || {}, {
</span><span class="cx"> frame: 'select'
</span><span class="cx"> });
</span><span class="cx">
</span><del>- if ( 'select' === attributes.frame && MediaFrame.Select )
</del><ins>+ if ( 'select' === attributes.frame && MediaFrame.Select ) {
</ins><span class="cx"> frame = new MediaFrame.Select( attributes );
</span><del>- else if ( 'post' === attributes.frame && MediaFrame.Post )
</del><ins>+ } else if ( 'post' === attributes.frame && MediaFrame.Post ) {
</ins><span class="cx"> frame = new MediaFrame.Post( attributes );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> delete attributes.frame;
</span><span class="cx">
</span><span class="lines">@@ -62,10 +64,11 @@
</span><span class="cx"> * 1: b should come before a.
</span><span class="cx"> */
</span><span class="cx"> compare = function( a, b, ac, bc ) {
</span><del>- if ( _.isEqual( a, b ) )
</del><ins>+ if ( _.isEqual( a, b ) ) {
</ins><span class="cx"> return ac === bc ? 0 : (ac > bc ? -1 : 1);
</span><del>- else
</del><ins>+ } else {
</ins><span class="cx"> return a > b ? -1 : 1;
</span><ins>+ }
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> _.extend( media, {
</span><span class="lines">@@ -93,7 +96,12 @@
</span><span class="cx"> */
</span><span class="cx"> ajax: wp.ajax.send,
</span><span class="cx">
</span><del>- // Scales a set of dimensions to fit within bounding dimensions.
</del><ins>+ /**
+ * Scales a set of dimensions to fit within bounding dimensions.
+ *
+ * @param {Object} dimensions
+ * @returns {Object}
+ */
</ins><span class="cx"> fit: function( dimensions ) {
</span><span class="cx"> var width = dimensions.width,
</span><span class="cx"> height = dimensions.height,
</span><span class="lines">@@ -131,29 +139,38 @@
</span><span class="cx"> };
</span><span class="cx"> }
</span><span class="cx"> },
</span><del>-
- // Truncates a string by injecting an ellipsis into the middle.
- // Useful for filenames.
</del><ins>+ /**
+ * Truncates a string by injecting an ellipsis into the middle.
+ * Useful for filenames.
+ *
+ * @param {String} string
+ * @param {Number} [length=30]
+ * @param {String} [replacement=…]
+ * @returns {String}
+ */
</ins><span class="cx"> truncate: function( string, length, replacement ) {
</span><span class="cx"> length = length || 30;
</span><span class="cx"> replacement = replacement || '…';
</span><span class="cx">
</span><del>- if ( string.length <= length )
</del><ins>+ if ( string.length <= length ) {
</ins><span class="cx"> return string;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> return string.substr( 0, length / 2 ) + replacement + string.substr( -1 * length / 2 );
</span><span class="cx"> }
</span><span class="cx"> });
</span><span class="cx">
</span><del>-
</del><span class="cx"> /**
</span><span class="cx"> * ========================================================================
</span><span class="cx"> * MODELS
</span><span class="cx"> * ========================================================================
</span><span class="cx"> */
</span><del>-
</del><span class="cx"> /**
</span><span class="cx"> * wp.media.attachment
</span><ins>+ *
+ * @static
+ * @param {String} id
+ * @returns {wp.media.model.Attachment}
</ins><span class="cx"> */
</span><span class="cx"> media.attachment = function( id ) {
</span><span class="cx"> return Attachment.get( id );
</span><span class="lines">@@ -161,13 +178,23 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * wp.media.model.Attachment
</span><ins>+ *
+ * @constructor
+ * @augments Backbone.Model
</ins><span class="cx"> */
</span><span class="cx"> Attachment = media.model.Attachment = Backbone.Model.extend({
</span><ins>+ /**
+ * @param {string} method
+ * @param {Backbone.Model} model
+ * @param {Object} [options={}]
+ * @returns {Promise}
+ */
</ins><span class="cx"> sync: function( method, model, options ) {
</span><span class="cx"> // If the attachment does not yet have an `id`, return an instantly
</span><span class="cx"> // rejected promise. Otherwise, all of our requests will fail.
</span><del>- if ( _.isUndefined( this.id ) )
</del><ins>+ if ( _.isUndefined( this.id ) ) {
</ins><span class="cx"> return $.Deferred().rejectWith( this ).promise();
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Overload the `read` request so Attachment.fetch() functions correctly.
</span><span class="cx"> if ( 'read' === method ) {
</span><span class="lines">@@ -182,8 +209,9 @@
</span><span class="cx"> // Overload the `update` request so properties can be saved.
</span><span class="cx"> } else if ( 'update' === method ) {
</span><span class="cx"> // If we do not have the necessary nonce, fail immeditately.
</span><del>- if ( ! this.get('nonces') || ! this.get('nonces').update )
</del><ins>+ if ( ! this.get('nonces') || ! this.get('nonces').update ) {
</ins><span class="cx"> return $.Deferred().rejectWith( this ).promise();
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> options = options || {};
</span><span class="cx"> options.context = this;
</span><span class="lines">@@ -212,8 +240,9 @@
</span><span class="cx"> } else if ( 'delete' === method ) {
</span><span class="cx"> options = options || {};
</span><span class="cx">
</span><del>- if ( ! options.wait )
</del><ins>+ if ( ! options.wait ) {
</ins><span class="cx"> this.destroyed = true;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> options.context = this;
</span><span class="cx"> options.data = _.extend( options.data || {}, {
</span><span class="lines">@@ -230,26 +259,38 @@
</span><span class="cx">
</span><span class="cx"> // Otherwise, fall back to `Backbone.sync()`.
</span><span class="cx"> } else {
</span><ins>+ /**
+ * Call `sync` directly on Backbone.Model
+ */
</ins><span class="cx"> return Backbone.Model.prototype.sync.apply( this, arguments );
</span><span class="cx"> }
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {Object} resp
+ * @returns {Object}
+ */
</ins><span class="cx"> parse: function( resp ) {
</span><del>- if ( ! resp )
</del><ins>+ if ( ! resp ) {
</ins><span class="cx"> return resp;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Convert date strings into Date objects.
</span><span class="cx"> resp.date = new Date( resp.date );
</span><span class="cx"> resp.modified = new Date( resp.modified );
</span><span class="cx"> return resp;
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {Object} data
+ * @param {Object} options
+ * @returns {Promise}
+ */
</ins><span class="cx"> saveCompat: function( data, options ) {
</span><span class="cx"> var model = this;
</span><span class="cx">
</span><span class="cx"> // If we do not have the necessary nonce, fail immeditately.
</span><del>- if ( ! this.get('nonces') || ! this.get('nonces').update )
</del><ins>+ if ( ! this.get('nonces') || ! this.get('nonces').update ) {
</ins><span class="cx"> return $.Deferred().rejectWith( this ).promise();
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> return media.post( 'save-attachment-compat', _.defaults({
</span><span class="cx"> id: this.id,
</span><span class="lines">@@ -260,10 +301,18 @@
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx"> }, {
</span><ins>+ /**
+ * @param {Object} attrs
+ * @returns {wp.media.model.Attachment}
+ */
</ins><span class="cx"> create: function( attrs ) {
</span><span class="cx"> return Attachments.all.push( attrs );
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {string} id
+ * @param {Backbone.Model} attachment
+ * @returns {wp.media.model.Attachment}
+ */
</ins><span class="cx"> get: _.memoize( function( id, attachment ) {
</span><span class="cx"> return Attachments.all.push( attachment || { id: id } );
</span><span class="cx"> })
</span><span class="lines">@@ -271,10 +320,19 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * wp.media.model.Attachments
</span><ins>+ *
+ * @constructor
+ * @augments Backbone.Collection
</ins><span class="cx"> */
</span><span class="cx"> Attachments = media.model.Attachments = Backbone.Collection.extend({
</span><ins>+ /**
+ * @type {wp.media.model.Attachment}
+ */
</ins><span class="cx"> model: Attachment,
</span><del>-
</del><ins>+ /**
+ * @param {Array|Object} models
+ * @param {Object} [options={}]
+ */
</ins><span class="cx"> initialize: function( models, options ) {
</span><span class="cx"> options = options || {};
</span><span class="cx">
</span><span class="lines">@@ -292,30 +350,49 @@
</span><span class="cx"> this.props.set( _.defaults( options.props || {} ) );
</span><span class="cx">
</span><span class="cx"> // Observe another `Attachments` collection if one is provided.
</span><del>- if ( options.observe )
</del><ins>+ if ( options.observe ) {
</ins><span class="cx"> this.observe( options.observe );
</span><ins>+ }
</ins><span class="cx"> },
</span><del>-
- // Automatically sort the collection when the order changes.
</del><ins>+ /**
+ * Automatically sort the collection when the order changes.
+ *
+ * @access private
+ */
</ins><span class="cx"> _changeOrder: function() {
</span><del>- if ( this.comparator )
</del><ins>+ if ( this.comparator ) {
</ins><span class="cx"> this.sort();
</span><ins>+ }
</ins><span class="cx"> },
</span><del>-
- // Set the default comparator only when the `orderby` property is set.
</del><ins>+ /**
+ * Set the default comparator only when the `orderby` property is set.
+ *
+ * @access private
+ *
+ * @param {Backbone.Model} model
+ * @param {string} orderby
+ */
</ins><span class="cx"> _changeOrderby: function( model, orderby ) {
</span><span class="cx"> // If a different comparator is defined, bail.
</span><del>- if ( this.comparator && this.comparator !== Attachments.comparator )
</del><ins>+ if ( this.comparator && this.comparator !== Attachments.comparator ) {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><del>- if ( orderby && 'post__in' !== orderby )
</del><ins>+ if ( orderby && 'post__in' !== orderby ) {
</ins><span class="cx"> this.comparator = Attachments.comparator;
</span><del>- else
</del><ins>+ } else {
</ins><span class="cx"> delete this.comparator;
</span><ins>+ }
</ins><span class="cx"> },
</span><del>-
- // If the `query` property is set to true, query the server using
- // the `props` values, and sync the results to this collection.
</del><ins>+ /**
+ * If the `query` property is set to true, query the server using
+ * the `props` values, and sync the results to this collection.
+ *
+ * @access private
+ *
+ * @param {Backbone.Model} model
+ * @param {Boolean} query
+ */
</ins><span class="cx"> _changeQuery: function( model, query ) {
</span><span class="cx"> if ( query ) {
</span><span class="cx"> this.props.on( 'change', this._requery, this );
</span><span class="lines">@@ -324,65 +401,88 @@
</span><span class="cx"> this.props.off( 'change', this._requery, this );
</span><span class="cx"> }
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @access private
+ *
+ * @param {Backbone.Model} model
+ */
</ins><span class="cx"> _changeFilteredProps: function( model ) {
</span><span class="cx"> // If this is a query, updating the collection will be handled by
</span><span class="cx"> // `this._requery()`.
</span><del>- if ( this.props.get('query') )
</del><ins>+ if ( this.props.get('query') ) {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> var changed = _.chain( model.changed ).map( function( t, prop ) {
</span><span class="cx"> var filter = Attachments.filters[ prop ],
</span><span class="cx"> term = model.get( prop );
</span><span class="cx">
</span><del>- if ( ! filter )
</del><ins>+ if ( ! filter ) {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><del>- if ( term && ! this.filters[ prop ] )
</del><ins>+ if ( term && ! this.filters[ prop ] ) {
</ins><span class="cx"> this.filters[ prop ] = filter;
</span><del>- else if ( ! term && this.filters[ prop ] === filter )
</del><ins>+ } else if ( ! term && this.filters[ prop ] === filter ) {
</ins><span class="cx"> delete this.filters[ prop ];
</span><del>- else
</del><ins>+ } else {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Record the change.
</span><span class="cx"> return true;
</span><span class="cx"> }, this ).any().value();
</span><span class="cx">
</span><del>- if ( ! changed )
</del><ins>+ if ( ! changed ) {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // If no `Attachments` model is provided to source the searches
</span><span class="cx"> // from, then automatically generate a source from the existing
</span><span class="cx"> // models.
</span><del>- if ( ! this._source )
</del><ins>+ if ( ! this._source ) {
</ins><span class="cx"> this._source = new Attachments( this.models );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> this.reset( this._source.filter( this.validator, this ) );
</span><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> validateDestroyed: false,
</span><del>-
</del><ins>+ /**
+ * @param {wp.media.model.Attachment} attachment
+ * @returns {Boolean}
+ */
</ins><span class="cx"> validator: function( attachment ) {
</span><del>- if ( ! this.validateDestroyed && attachment.destroyed )
</del><ins>+ if ( ! this.validateDestroyed && attachment.destroyed ) {
</ins><span class="cx"> return false;
</span><ins>+ }
</ins><span class="cx"> return _.all( this.filters, function( filter ) {
</span><span class="cx"> return !! filter.call( this, attachment );
</span><span class="cx"> }, this );
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {wp.media.model.Attachment} attachment
+ * @param {Object} options
+ * @returns {wp.media.model.Attachments} Returns itself to allow chaining
+ */
</ins><span class="cx"> validate: function( attachment, options ) {
</span><span class="cx"> var valid = this.validator( attachment ),
</span><span class="cx"> hasAttachment = !! this.get( attachment.cid );
</span><span class="cx">
</span><del>- if ( ! valid && hasAttachment )
</del><ins>+ if ( ! valid && hasAttachment ) {
</ins><span class="cx"> this.remove( attachment, options );
</span><del>- else if ( valid && ! hasAttachment )
</del><ins>+ } else if ( valid && ! hasAttachment ) {
</ins><span class="cx"> this.add( attachment, options );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> return this;
</span><span class="cx"> },
</span><span class="cx">
</span><ins>+ /**
+ * @param {Backbone.Collection} attachments
+ * @param {object} [options={}]
+ * @returns {wp.media.model.Attachments} Returns itself to allow chaining
+ */
</ins><span class="cx"> validateAll: function( attachments, options ) {
</span><span class="cx"> options = options || {};
</span><span class="cx">
</span><span class="lines">@@ -390,12 +490,15 @@
</span><span class="cx"> this.validate( attachment, { silent: true });
</span><span class="cx"> }, this );
</span><span class="cx">
</span><del>- if ( ! options.silent )
</del><ins>+ if ( ! options.silent ) {
</ins><span class="cx"> this.trigger( 'reset', this, options );
</span><del>-
</del><ins>+ }
</ins><span class="cx"> return this;
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {Backbone.Collection} attachments
+ * @returns {wp.media.model.Attachments} Returns itself to allow chaining
+ */
</ins><span class="cx"> observe: function( attachments ) {
</span><span class="cx"> this.observers = this.observers || [];
</span><span class="cx"> this.observers.push( attachments );
</span><span class="lines">@@ -405,7 +508,10 @@
</span><span class="cx"> this.validateAll( attachments );
</span><span class="cx"> return this;
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {Backbone.Collection} attachments
+ * @returns {wp.media.model.Attachments} Returns itself to allow chaining
+ */
</ins><span class="cx"> unobserve: function( attachments ) {
</span><span class="cx"> if ( attachments ) {
</span><span class="cx"> attachments.off( null, null, this );
</span><span class="lines">@@ -420,7 +526,14 @@
</span><span class="cx">
</span><span class="cx"> return this;
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @access private
+ *
+ * @param {Backbone.Model} attachment
+ * @param {Backbone.Collction} attachments
+ * @param {Object} options
+ * @returns {wp.media.model.Attachments} Returns itself to allow chaining
+ */
</ins><span class="cx"> _validateHandler: function( attachment, attachments, options ) {
</span><span class="cx"> // If we're not mirroring this `attachments` collection,
</span><span class="cx"> // only retain the `silent` option.
</span><span class="lines">@@ -430,14 +543,24 @@
</span><span class="cx">
</span><span class="cx"> return this.validate( attachment, options );
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @access private
+ *
+ * @param {Backbone.Collction} attachments
+ * @param {Object} options
+ * @returns {wp.media.model.Attachments} Returns itself to allow chaining
+ */
</ins><span class="cx"> _validateAllHandler: function( attachments, options ) {
</span><span class="cx"> return this.validateAll( attachments, options );
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {Backbone.Collction} attachments
+ * @returns {wp.media.model.Attachments} Returns itself to allow chaining
+ */
</ins><span class="cx"> mirror: function( attachments ) {
</span><del>- if ( this.mirroring && this.mirroring === attachments )
</del><ins>+ if ( this.mirroring && this.mirroring === attachments ) {
</ins><span class="cx"> return this;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> this.unmirror();
</span><span class="cx"> this.mirroring = attachments;
</span><span class="lines">@@ -449,23 +572,26 @@
</span><span class="cx">
</span><span class="cx"> return this;
</span><span class="cx"> },
</span><del>-
</del><span class="cx"> unmirror: function() {
</span><del>- if ( ! this.mirroring )
</del><ins>+ if ( ! this.mirroring ) {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> this.unobserve( this.mirroring );
</span><span class="cx"> delete this.mirroring;
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {Object} options
+ * @returns {Promise}
+ */
</ins><span class="cx"> more: function( options ) {
</span><span class="cx"> var deferred = $.Deferred(),
</span><span class="cx"> mirroring = this.mirroring,
</span><span class="cx"> attachments = this;
</span><span class="cx">
</span><del>- if ( ! mirroring || ! mirroring.more )
</del><ins>+ if ( ! mirroring || ! mirroring.more ) {
</ins><span class="cx"> return deferred.resolveWith( this ).promise();
</span><del>-
</del><ins>+ }
</ins><span class="cx"> // If we're mirroring another collection, forward `more` to
</span><span class="cx"> // the mirrored collection. Account for a race condition by
</span><span class="cx"> // checking if we're still mirroring that collection when
</span><span class="lines">@@ -477,14 +603,21 @@
</span><span class="cx">
</span><span class="cx"> return deferred.promise();
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @returns {Boolean}
+ */
</ins><span class="cx"> hasMore: function() {
</span><span class="cx"> return this.mirroring ? this.mirroring.hasMore() : false;
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {Object} resp
+ * @param {XMLHttpRequest} xhr
+ * @returns {Array}
+ */
</ins><span class="cx"> parse: function( resp, xhr ) {
</span><del>- if ( ! _.isArray( resp ) )
</del><ins>+ if ( ! _.isArray( resp ) ) {
</ins><span class="cx"> resp = [resp];
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> return _.map( resp, function( attrs ) {
</span><span class="cx"> var id, attachment, newAttributes;
</span><span class="lines">@@ -499,23 +632,31 @@
</span><span class="cx"> attachment = Attachment.get( id );
</span><span class="cx"> newAttributes = attachment.parse( attrs, xhr );
</span><span class="cx">
</span><del>- if ( ! _.isEqual( attachment.attributes, newAttributes ) )
</del><ins>+ if ( ! _.isEqual( attachment.attributes, newAttributes ) ) {
</ins><span class="cx"> attachment.set( newAttributes );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> return attachment;
</span><span class="cx"> });
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @access private
+ */
</ins><span class="cx"> _requery: function() {
</span><del>- if ( this.props.get('query') )
</del><ins>+ if ( this.props.get('query') ) {
</ins><span class="cx"> this.mirror( Query.get( this.props.toJSON() ) );
</span><ins>+ }
</ins><span class="cx"> },
</span><del>-
- // If this collection is sorted by `menuOrder`, recalculates and saves
- // the menu order to the database.
</del><ins>+ /**
+ * If this collection is sorted by `menuOrder`, recalculates and saves
+ * the menu order to the database.
+ *
+ * @returns {undefined|Promise}
+ */
</ins><span class="cx"> saveMenuOrder: function() {
</span><del>- if ( 'menuOrder' !== this.props.get('orderby') )
</del><ins>+ if ( 'menuOrder' !== this.props.get('orderby') ) {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Removes any uploading attachments, updates each attachment's
</span><span class="cx"> // menu order, and returns an object with an { id: menuOrder }
</span><span class="lines">@@ -529,8 +670,9 @@
</span><span class="cx"> return [ attachment.id, index ];
</span><span class="cx"> }).object().value();
</span><span class="cx">
</span><del>- if ( _.isEmpty( attachments ) )
</del><ins>+ if ( _.isEmpty( attachments ) ) {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> return media.post( 'save-attachment-order', {
</span><span class="cx"> nonce: media.model.settings.post.nonce,
</span><span class="lines">@@ -539,6 +681,12 @@
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx"> }, {
</span><ins>+ /**
+ * @param {Backbone.Model} a
+ * @param {Backbone.Model} b
+ * @param {Object} options
+ * @returns {Number}
+ */
</ins><span class="cx"> comparator: function( a, b, options ) {
</span><span class="cx"> var key = this.props.get('orderby'),
</span><span class="cx"> order = this.props.get('order') || 'DESC',
</span><span class="lines">@@ -554,44 +702,64 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // If `options.ties` is set, don't enforce the `cid` tiebreaker.
</span><del>- if ( options && options.ties )
</del><ins>+ if ( options && options.ties ) {
</ins><span class="cx"> ac = bc = null;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> return ( 'DESC' === order ) ? compare( a, b, ac, bc ) : compare( b, a, bc, ac );
</span><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> filters: {
</span><del>- // Note that this client-side searching is *not* equivalent
- // to our server-side searching.
</del><ins>+ /**
+ * Note that this client-side searching is *not* equivalent
+ * to our server-side searching.
+ *
+ * @param {wp.media.model.Attachment} attachment
+ * @returns {Boolean}
+ */
</ins><span class="cx"> search: function( attachment ) {
</span><del>- if ( ! this.props.get('search') )
</del><ins>+ if ( ! this.props.get('search') ) {
</ins><span class="cx"> return true;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> return _.any(['title','filename','description','caption','name'], function( key ) {
</span><span class="cx"> var value = attachment.get( key );
</span><span class="cx"> return value && -1 !== value.search( this.props.get('search') );
</span><span class="cx"> }, this );
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {wp.media.model.Attachment} attachment
+ * @returns {Boolean}
+ */
</ins><span class="cx"> type: function( attachment ) {
</span><span class="cx"> var type = this.props.get('type');
</span><span class="cx"> return ! type || -1 !== type.indexOf( attachment.get('type') );
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {wp.media.model.Attachment} attachment
+ * @returns {Boolean}
+ */
</ins><span class="cx"> uploadedTo: function( attachment ) {
</span><span class="cx"> var uploadedTo = this.props.get('uploadedTo');
</span><del>- if ( _.isUndefined( uploadedTo ) )
</del><ins>+ if ( _.isUndefined( uploadedTo ) ) {
</ins><span class="cx"> return true;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> return uploadedTo === attachment.get('uploadedTo');
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> });
</span><span class="cx">
</span><ins>+ /**
+ * @member {wp.media.model.Attachments}
+ */
</ins><span class="cx"> Attachments.all = new Attachments();
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * wp.media.query
</span><ins>+ *
+ * @static
+ * @returns {Attachments}
</ins><span class="cx"> */
</span><span class="cx"> media.query = function( props ) {
</span><span class="cx"> return new Attachments( null, {
</span><span class="lines">@@ -607,8 +775,18 @@
</span><span class="cx"> *
</span><span class="cx"> * Note: Do NOT change this.args after the query has been initialized.
</span><span class="cx"> * Things will break.
</span><ins>+ *
+ * @constructor
+ * @augments wp.media.model.Attachments
+ * @augments Backbone.Collection
</ins><span class="cx"> */
</span><span class="cx"> Query = media.model.Query = Attachments.extend({
</span><ins>+ /**
+ * @global wp.Uploader
+ *
+ * @param {Array} models
+ * @param {Object} [options={}]
+ */
</ins><span class="cx"> initialize: function( models, options ) {
</span><span class="cx"> var allowed;
</span><span class="cx">
</span><span class="lines">@@ -623,8 +801,9 @@
</span><span class="cx"> var orderby = this.props.get('orderby'),
</span><span class="cx"> order = this.props.get('order');
</span><span class="cx">
</span><del>- if ( ! this.comparator )
</del><ins>+ if ( ! this.comparator ) {
</ins><span class="cx"> return true;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // We want any items that can be placed before the last
</span><span class="cx"> // item in the set. If we add any items after the last
</span><span class="lines">@@ -655,32 +834,46 @@
</span><span class="cx"> // are no filters for other properties, so observing will result in
</span><span class="cx"> // false positives in those queries.
</span><span class="cx"> allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent' ];
</span><del>- if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() )
</del><ins>+ if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) {
</ins><span class="cx"> this.observe( wp.Uploader.queue );
</span><ins>+ }
</ins><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @returns {Boolean}
+ */
</ins><span class="cx"> hasMore: function() {
</span><span class="cx"> return this._hasMore;
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {Object} [options={}]
+ * @returns {Promise}
+ */
</ins><span class="cx"> more: function( options ) {
</span><span class="cx"> var query = this;
</span><span class="cx">
</span><del>- if ( this._more && 'pending' === this._more.state() )
</del><ins>+ if ( this._more && 'pending' === this._more.state() ) {
</ins><span class="cx"> return this._more;
</span><ins>+ }
</ins><span class="cx">
</span><del>- if ( ! this.hasMore() )
</del><ins>+ if ( ! this.hasMore() ) {
</ins><span class="cx"> return $.Deferred().resolveWith( this ).promise();
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> options = options || {};
</span><span class="cx"> options.remove = false;
</span><span class="cx">
</span><span class="cx"> return this._more = this.fetch( options ).done( function( resp ) {
</span><del>- if ( _.isEmpty( resp ) || -1 === this.args.posts_per_page || resp.length < this.args.posts_per_page )
</del><ins>+ if ( _.isEmpty( resp ) || -1 === this.args.posts_per_page || resp.length < this.args.posts_per_page ) {
</ins><span class="cx"> query._hasMore = false;
</span><ins>+ }
</ins><span class="cx"> });
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {String} method
+ * @param {Backbone.Model} model
+ * @param {Object} [options={}]
+ * @returns {Promise}
+ */
</ins><span class="cx"> sync: function( method, model, options ) {
</span><span class="cx"> var args, fallback;
</span><span class="cx">
</span><span class="lines">@@ -697,14 +890,18 @@
</span><span class="cx"> args = _.clone( this.args );
</span><span class="cx">
</span><span class="cx"> // Determine which page to query.
</span><del>- if ( -1 !== args.posts_per_page )
</del><ins>+ if ( -1 !== args.posts_per_page ) {
</ins><span class="cx"> args.paged = Math.floor( this.length / args.posts_per_page ) + 1;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> options.data.query = args;
</span><span class="cx"> return media.ajax( options );
</span><span class="cx">
</span><span class="cx"> // Otherwise, fall back to Backbone.sync()
</span><span class="cx"> } else {
</span><ins>+ /**
+ * Call wp.media.model.Attachments.sync or Backbone.sync
+ */
</ins><span class="cx"> fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone;
</span><span class="cx"> return fallback.sync.apply( this, arguments );
</span><span class="cx"> }
</span><span class="lines">@@ -738,8 +935,17 @@
</span><span class="cx">
</span><span class="cx"> // Caches query objects so queries can be easily reused.
</span><span class="cx"> get: (function(){
</span><ins>+ /**
+ * @static
+ * @type Array
+ */
</ins><span class="cx"> var queries = [];
</span><span class="cx">
</span><ins>+ /**
+ * @param {Object} props
+ * @param {Object} options
+ * @returns {Query}
+ */
</ins><span class="cx"> return function( props, options ) {
</span><span class="cx"> var args = {},
</span><span class="cx"> orderby = Query.orderby,
</span><span class="lines">@@ -755,18 +961,21 @@
</span><span class="cx">
</span><span class="cx"> // Normalize the order.
</span><span class="cx"> props.order = props.order.toUpperCase();
</span><del>- if ( 'DESC' !== props.order && 'ASC' !== props.order )
</del><ins>+ if ( 'DESC' !== props.order && 'ASC' !== props.order ) {
</ins><span class="cx"> props.order = defaults.order.toUpperCase();
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Ensure we have a valid orderby value.
</span><del>- if ( ! _.contains( orderby.allowed, props.orderby ) )
</del><ins>+ if ( ! _.contains( orderby.allowed, props.orderby ) ) {
</ins><span class="cx"> props.orderby = defaults.orderby;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Generate the query `args` object.
</span><span class="cx"> // Correct any differing property names.
</span><span class="cx"> _.each( props, function( value, prop ) {
</span><del>- if ( _.isNull( value ) )
</del><ins>+ if ( _.isNull( value ) ) {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> args[ Query.propmap[ prop ] || prop ] = value;
</span><span class="cx"> });
</span><span class="lines">@@ -801,38 +1010,69 @@
</span><span class="cx"> * wp.media.model.Selection
</span><span class="cx"> *
</span><span class="cx"> * Used to manage a selection of attachments in the views.
</span><ins>+ *
+ * @constructor
+ * @augments wp.media.model.Attachments
+ * @augments Backbone.Collection
</ins><span class="cx"> */
</span><span class="cx"> media.model.Selection = Attachments.extend({
</span><ins>+ /**
+ * Refresh the `single` model whenever the selection changes.
+ * Binds `single` instead of using the context argument to ensure
+ * it receives no parameters.
+ *
+ * @param {Array} models
+ * @param {Object} options
+ */
</ins><span class="cx"> initialize: function( models, options ) {
</span><ins>+ /**
+ * call 'initialize' directly on the parent class
+ */
</ins><span class="cx"> Attachments.prototype.initialize.apply( this, arguments );
</span><span class="cx"> this.multiple = options && options.multiple;
</span><span class="cx">
</span><del>- // Refresh the `single` model whenever the selection changes.
- // Binds `single` instead of using the context argument to ensure
- // it receives no parameters.
</del><span class="cx"> this.on( 'add remove reset', _.bind( this.single, this, false ) );
</span><span class="cx"> },
</span><span class="cx">
</span><del>- // Override the selection's add method.
- // If the workflow does not support multiple
- // selected attachments, reset the selection.
</del><ins>+ /**
+ * Override the selection's add method.
+ * If the workflow does not support multiple
+ * selected attachments, reset the selection.
+ *
+ * @param {Array} models
+ * @param {Object} options
+ * @returns {wp.media.model.Attachment[]}
+ */
</ins><span class="cx"> add: function( models, options ) {
</span><del>- if ( ! this.multiple )
</del><ins>+ if ( ! this.multiple ) {
</ins><span class="cx"> this.remove( this.models );
</span><del>-
</del><ins>+ }
+ /**
+ * call 'add' directly on the parent class
+ */
</ins><span class="cx"> return Attachments.prototype.add.call( this, models, options );
</span><span class="cx"> },
</span><span class="cx">
</span><ins>+ /**
+ *
+ * @param {Backbone.Model} model
+ *
+ * @fires wp.media.model.Selection#selection:single
+ * @fires wp.media.model.Selection#selection:unsingle
+ *
+ * @returns {Backbone.Model}
+ */
</ins><span class="cx"> single: function( model ) {
</span><span class="cx"> var previous = this._single;
</span><span class="cx">
</span><span class="cx"> // If a `model` is provided, use it as the single model.
</span><del>- if ( model )
</del><ins>+ if ( model ) {
</ins><span class="cx"> this._single = model;
</span><del>-
</del><ins>+ }
</ins><span class="cx"> // If the single model isn't in the selection, remove it.
</span><del>- if ( this._single && ! this.get( this._single.cid ) )
</del><ins>+ if ( this._single && ! this.get( this._single.cid ) ) {
</ins><span class="cx"> delete this._single;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> this._single = this._single || this.last();
</span><span class="cx">
</span><span class="lines">@@ -843,11 +1083,13 @@
</span><span class="cx">
</span><span class="cx"> // If the model was already removed, trigger the collection
</span><span class="cx"> // event manually.
</span><del>- if ( ! this.get( previous.cid ) )
</del><ins>+ if ( ! this.get( previous.cid ) ) {
</ins><span class="cx"> this.trigger( 'selection:unsingle', previous, this );
</span><ins>+ }
</ins><span class="cx"> }
</span><del>- if ( this._single )
</del><ins>+ if ( this._single ) {
</ins><span class="cx"> this._single.trigger( 'selection:single', this._single, this );
</span><ins>+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Return the single model, or the last model as a fallback.
</span></span></pre>
</div>
</div>
</body>
</html>