<!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>[26984] trunk/src/wp-includes/js/media-editor.js: Add initial JSDoc blocks to `media-editor.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/26984">26984</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-01-20 23:34:57 +0000 (Mon, 20 Jan 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add initial JSDoc blocks to `media-editor.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="#trunksrcwpincludesjsmediaeditorjs">trunk/src/wp-includes/js/media-editor.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesjsmediaeditorjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/media-editor.js (26983 => 26984)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/media-editor.js 2014-01-19 23:21:07 UTC (rev 26983)
+++ trunk/src/wp-includes/js/media-editor.js 2014-01-20 23:34:57 UTC (rev 26984)
</span><span class="lines">@@ -3,13 +3,28 @@
</span><span class="cx"> // WordPress, TinyMCE, and Media
</span><span class="cx"> // -----------------------------
</span><span class="cx"> (function($){
</span><del>- // Stores the editors' `wp.media.controller.Frame` instances.
</del><ins>+ /**
+ * Stores the editors' `wp.media.controller.Frame` instances.
+ *
+ * @static
+ */
</ins><span class="cx"> var workflows = {};
</span><span class="cx">
</span><ins>+ /**
+ * wp.media.string
+ */
</ins><span class="cx"> wp.media.string = {
</span><del>- // Joins the `props` and `attachment` objects,
- // outputting the proper object format based on the
- // attachment's type.
</del><ins>+ /**
+ * Joins the `props` and `attachment` objects,
+ * outputting the proper object format based on the
+ * attachment's type.
+ *
+ * @global wp.media.view.settings.defaultProps
+ *
+ * @param {Object} props
+ * @param {Object} attachment
+ * @returns {Object} Joined props
+ */
</ins><span class="cx"> props: function( props, attachment ) {
</span><span class="cx"> var link, linkUrl, size, sizes, fallbacks,
</span><span class="cx"> defaultProps = wp.media.view.settings.defaultProps;
</span><span class="lines">@@ -28,8 +43,9 @@
</span><span class="cx">
</span><span class="cx"> props = props ? _.clone( props ) : {};
</span><span class="cx">
</span><del>- if ( attachment && attachment.type )
</del><ins>+ if ( attachment && attachment.type ) {
</ins><span class="cx"> props.type = attachment.type;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> if ( 'image' === props.type ) {
</span><span class="cx"> props = _.defaults( props || {}, {
</span><span class="lines">@@ -41,18 +57,20 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // All attachment-specific settings follow.
</span><del>- if ( ! attachment )
</del><ins>+ if ( ! attachment ) {
</ins><span class="cx"> return fallbacks( props );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> props.title = props.title || attachment.title;
</span><span class="cx">
</span><span class="cx"> link = props.link || defaultProps.link || getUserSetting( 'urlbutton', 'file' );
</span><del>- if ( 'file' === link || 'embed' === link )
</del><ins>+ if ( 'file' === link || 'embed' === link ) {
</ins><span class="cx"> linkUrl = attachment.url;
</span><del>- else if ( 'post' === link )
</del><ins>+ } else if ( 'post' === link ) {
</ins><span class="cx"> linkUrl = attachment.link;
</span><del>- else if ( 'custom' === link )
</del><ins>+ } else if ( 'custom' === link ) {
</ins><span class="cx"> linkUrl = props.linkUrl;
</span><ins>+ }
</ins><span class="cx"> props.linkUrl = linkUrl || '';
</span><span class="cx">
</span><span class="cx"> // Format properties for images.
</span><span class="lines">@@ -79,6 +97,15 @@
</span><span class="cx"> return fallbacks( props );
</span><span class="cx"> },
</span><span class="cx">
</span><ins>+ /**
+ * Create the markup for a link
+ *
+ * @global wp.html.string
+ *
+ * @param {Object} props
+ * @param {Object} attachment
+ * @returns {string} The link markup
+ */
</ins><span class="cx"> link: function( props, attachment ) {
</span><span class="cx"> var options;
</span><span class="cx">
</span><span class="lines">@@ -92,20 +119,45 @@
</span><span class="cx"> }
</span><span class="cx"> };
</span><span class="cx">
</span><del>- if ( props.rel )
</del><ins>+ if ( props.rel ) {
</ins><span class="cx"> options.attrs.rel = props.rel;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> return wp.html.string( options );
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * Create an Audio shortcode
+ *
+ * @param {Object} props
+ * @param {Object} attachment
+ * @returns {string} The audio shortcode
+ */
</ins><span class="cx"> audio: function( props, attachment ) {
</span><span class="cx"> return wp.media.string._audioVideo( 'audio', props, attachment );
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * Create a Video shortcode
+ *
+ * @param {Object} props
+ * @param {Object} attachment
+ * @returns {string} The video shortcode
+ */
</ins><span class="cx"> video: function( props, attachment ) {
</span><span class="cx"> return wp.media.string._audioVideo( 'video', props, attachment );
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * Helper function to create a media shortcode
+ *
+ * @access private
+ *
+ * @global wp.shortcode
+ * @global wp.media.view.settings
+ *
+ * @param {string} type The shortcode tag name: 'audio' or 'video'.
+ * @param {Object} props
+ * @param {Object} attachment
+ * @returns {string} The media shortcode
+ */
</ins><span class="cx"> _audioVideo: function( type, props, attachment ) {
</span><span class="cx"> var shortcode, html, extension;
</span><span class="cx">
</span><span class="lines">@@ -116,11 +168,13 @@
</span><span class="cx"> shortcode = {};
</span><span class="cx">
</span><span class="cx"> if ( 'video' === type ) {
</span><del>- if ( attachment.width )
</del><ins>+ if ( attachment.width ) {
</ins><span class="cx"> shortcode.width = attachment.width;
</span><ins>+ }
</ins><span class="cx">
</span><del>- if ( attachment.height )
</del><ins>+ if ( attachment.height ) {
</ins><span class="cx"> shortcode.height = attachment.height;
</span><ins>+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> extension = attachment.filename.split('.').pop();
</span><span class="lines">@@ -139,7 +193,16 @@
</span><span class="cx">
</span><span class="cx"> return html;
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * Create image markup, optionally with a link and/or wrapped in a caption shortcode
+ *
+ * @global wp.html
+ * @global wp.shortcode
+ *
+ * @param {Object} props
+ * @param {Object} attachment
+ * @returns {string}
+ */
</ins><span class="cx"> image: function( props, attachment ) {
</span><span class="cx"> var img = {},
</span><span class="cx"> options, classes, shortcode, html;
</span><span class="lines">@@ -152,11 +215,13 @@
</span><span class="cx">
</span><span class="cx"> // Only assign the align class to the image if we're not printing
</span><span class="cx"> // a caption, since the alignment is sent to the shortcode.
</span><del>- if ( props.align && ! props.caption )
</del><ins>+ if ( props.align && ! props.caption ) {
</ins><span class="cx"> classes.push( 'align' + props.align );
</span><ins>+ }
</ins><span class="cx">
</span><del>- if ( props.size )
</del><ins>+ if ( props.size ) {
</ins><span class="cx"> classes.push( 'size-' + props.size );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> img['class'] = _.compact( classes ).join(' ');
</span><span class="cx">
</span><span class="lines">@@ -184,14 +249,17 @@
</span><span class="cx"> if ( props.caption ) {
</span><span class="cx"> shortcode = {};
</span><span class="cx">
</span><del>- if ( img.width )
</del><ins>+ if ( img.width ) {
</ins><span class="cx"> shortcode.width = img.width;
</span><ins>+ }
</ins><span class="cx">
</span><del>- if ( props.captionId )
</del><ins>+ if ( props.captionId ) {
</ins><span class="cx"> shortcode.id = props.captionId;
</span><ins>+ }
</ins><span class="cx">
</span><del>- if ( props.align )
</del><ins>+ if ( props.align ) {
</ins><span class="cx"> shortcode.align = 'align' + props.align;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> html = wp.shortcode.string({
</span><span class="cx"> tag: 'caption',
</span><span class="lines">@@ -204,10 +272,23 @@
</span><span class="cx"> }
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+ /**
+ * wp.media.gallery
+ *
+ * @type {Object}
+ */
</ins><span class="cx"> wp.media.gallery = (function() {
</span><ins>+ /**
+ *
+ * @static
+ * @type object
+ */
</ins><span class="cx"> var galleries = {};
</span><span class="cx">
</span><span class="cx"> return {
</span><ins>+ /**
+ * @global wp.media.view.settings
+ */
</ins><span class="cx"> defaults: {
</span><span class="cx"> order: 'ASC',
</span><span class="cx"> id: wp.media.view.settings.post.id,
</span><span class="lines">@@ -220,6 +301,12 @@
</span><span class="cx"> orderby: 'menu_order ID'
</span><span class="cx"> },
</span><span class="cx">
</span><ins>+ /**
+ * @global wp.media.query
+ *
+ * @param {Object} shortcode
+ * @returns {Object}
+ */
</ins><span class="cx"> attachments: function( shortcode ) {
</span><span class="cx"> var shortcodeString = shortcode.string(),
</span><span class="cx"> result = galleries[ shortcodeString ],
</span><span class="lines">@@ -227,8 +314,9 @@
</span><span class="cx">
</span><span class="cx"> delete galleries[ shortcodeString ];
</span><span class="cx">
</span><del>- if ( result )
</del><ins>+ if ( result ) {
</ins><span class="cx"> return result;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Fill the default shortcode attributes.
</span><span class="cx"> attrs = _.defaults( shortcode.attrs.named, wp.media.gallery.defaults );
</span><span class="lines">@@ -238,15 +326,17 @@
</span><span class="cx"> args.perPage = -1;
</span><span class="cx">
</span><span class="cx"> // Mark the `orderby` override attribute.
</span><del>- if( undefined !== attrs.orderby )
</del><ins>+ if( undefined !== attrs.orderby ) {
</ins><span class="cx"> attrs._orderByField = attrs.orderby;
</span><del>-
- if ( 'rand' === attrs.orderby )
</del><ins>+ }
+ if ( 'rand' === attrs.orderby ) {
</ins><span class="cx"> attrs._orderbyRandom = true;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Map the `orderby` attribute to the corresponding model property.
</span><del>- if ( ! attrs.orderby || /^menu_order(?: ID)?$/i.test( attrs.orderby ) )
</del><ins>+ if ( ! attrs.orderby || /^menu_order(?: ID)?$/i.test( attrs.orderby ) ) {
</ins><span class="cx"> args.orderby = 'menuOrder';
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Map the `ids` param to the correct query args.
</span><span class="cx"> if ( attrs.ids ) {
</span><span class="lines">@@ -256,11 +346,13 @@
</span><span class="cx"> args.post__in = attrs.include.split(',');
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if ( attrs.exclude )
</del><ins>+ if ( attrs.exclude ) {
</ins><span class="cx"> args.post__not_in = attrs.exclude.split(',');
</span><ins>+ }
</ins><span class="cx">
</span><del>- if ( ! args.post__in )
</del><ins>+ if ( ! args.post__in ) {
</ins><span class="cx"> args.uploadedTo = attrs.id;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Collect the attributes that were not included in `args`.
</span><span class="cx"> others = _.omit( attrs, 'id', 'ids', 'include', 'exclude', 'orderby', 'order' );
</span><span class="lines">@@ -270,13 +362,21 @@
</span><span class="cx"> return query;
</span><span class="cx"> },
</span><span class="cx">
</span><ins>+ /**
+ * @global wp.shortcode
+ * @global wp.media.model.Attachments
+ *
+ * @param {Object} attachments
+ * @returns {wp.shortcode}
+ */
</ins><span class="cx"> shortcode: function( attachments ) {
</span><span class="cx"> var props = attachments.props.toJSON(),
</span><span class="cx"> attrs = _.pick( props, 'orderby', 'order' ),
</span><span class="cx"> shortcode, clone;
</span><span class="cx">
</span><del>- if ( attachments.gallery )
</del><ins>+ if ( attachments.gallery ) {
</ins><span class="cx"> _.extend( attrs, attachments.gallery.toJSON() );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Convert all gallery shortcodes to use the `ids` property.
</span><span class="cx"> // Ignore `post__in` and `post__not_in`; the attachments in
</span><span class="lines">@@ -284,24 +384,27 @@
</span><span class="cx"> attrs.ids = attachments.pluck('id');
</span><span class="cx">
</span><span class="cx"> // Copy the `uploadedTo` post ID.
</span><del>- if ( props.uploadedTo )
</del><ins>+ if ( props.uploadedTo ) {
</ins><span class="cx"> attrs.id = props.uploadedTo;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Check if the gallery is randomly ordered.
</span><span class="cx"> delete attrs.orderby;
</span><span class="cx">
</span><del>- if ( attrs._orderbyRandom )
</del><ins>+ if ( attrs._orderbyRandom ) {
</ins><span class="cx"> attrs.orderby = 'rand';
</span><del>- else if ( attrs._orderByField && attrs._orderByField != 'rand' )
</del><ins>+ } else if ( attrs._orderByField && attrs._orderByField != 'rand' ) {
</ins><span class="cx"> attrs.orderby = attrs._orderByField;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> delete attrs._orderbyRandom;
</span><span class="cx"> delete attrs._orderByField;
</span><span class="cx">
</span><span class="cx"> // If the `ids` attribute is set and `orderby` attribute
</span><span class="cx"> // is the default value, clear it for cleaner output.
</span><del>- if ( attrs.ids && 'post__in' === attrs.orderby )
</del><ins>+ if ( attrs.ids && 'post__in' === attrs.orderby ) {
</ins><span class="cx"> delete attrs.orderby;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Remove default attributes from the shortcode.
</span><span class="cx"> _.each( wp.media.gallery.defaults, function( value, key ) {
</span><span class="lines">@@ -324,21 +427,30 @@
</span><span class="cx">
</span><span class="cx"> return shortcode;
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @global wp.shortcode
+ * @global wp.media.model.Selection
+ * @global wp.media.view.l10n
+ *
+ * @param {string} content
+ * @returns {wp.media.view.MediaFrame} A media workflow.
+ */
</ins><span class="cx"> edit: function( content ) {
</span><span class="cx"> var shortcode = wp.shortcode.next( 'gallery', content ),
</span><span class="cx"> defaultPostId = wp.media.gallery.defaults.id,
</span><span class="cx"> attachments, selection;
</span><span class="cx">
</span><span class="cx"> // Bail if we didn't match the shortcode or all of the content.
</span><del>- if ( ! shortcode || shortcode.content !== content )
</del><ins>+ if ( ! shortcode || shortcode.content !== content ) {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Ignore the rest of the match object.
</span><span class="cx"> shortcode = shortcode.shortcode;
</span><span class="cx">
</span><del>- if ( _.isUndefined( shortcode.get('id') ) && ! _.isUndefined( defaultPostId ) )
</del><ins>+ if ( _.isUndefined( shortcode.get('id') ) && ! _.isUndefined( defaultPostId ) ) {
</ins><span class="cx"> shortcode.set( 'id', defaultPostId );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> attachments = wp.media.gallery.attachments( shortcode );
</span><span class="cx">
</span><span class="lines">@@ -359,8 +471,9 @@
</span><span class="cx"> });
</span><span class="cx">
</span><span class="cx"> // Destroy the previous gallery frame.
</span><del>- if ( this.frame )
</del><ins>+ if ( this.frame ) {
</ins><span class="cx"> this.frame.dispose();
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Store the current gallery frame.
</span><span class="cx"> this.frame = wp.media({
</span><span class="lines">@@ -377,11 +490,30 @@
</span><span class="cx"> };
</span><span class="cx"> }());
</span><span class="cx">
</span><ins>+ /**
+ * wp.media.featuredImage
+ */
</ins><span class="cx"> wp.media.featuredImage = {
</span><ins>+ /**
+ * Get the featured image post ID
+ *
+ * @global wp.media.view.settings
+ *
+ * @returns {wp.media.view.settings.post.featuredImageId|Number}
+ */
</ins><span class="cx"> get: function() {
</span><span class="cx"> return wp.media.view.settings.post.featuredImageId;
</span><span class="cx"> },
</span><span class="cx">
</span><ins>+ /**
+ * Set the featured image id, save the post thumbnail data and
+ * set the HTML in the post meta box to the new featured image.
+ *
+ * @global wp.media.view.settings
+ * @global wp.media.post
+ *
+ * @param {number} id
+ */
</ins><span class="cx"> set: function( id ) {
</span><span class="cx"> var settings = wp.media.view.settings;
</span><span class="cx">
</span><span class="lines">@@ -396,10 +528,18 @@
</span><span class="cx"> $( '.inside', '#postimagediv' ).html( html );
</span><span class="cx"> });
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * The Featured Image workflow
+ *
+ * @global wp.media.controller.FeaturedImage
+ * @global wp.media.view.l10n
+ *
+ * @returns {wp.media.view.MediaFrame} A media workflow.
+ */
</ins><span class="cx"> frame: function() {
</span><del>- if ( this._frame )
</del><ins>+ if ( this._frame ) {
</ins><span class="cx"> return this._frame;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> this._frame = wp.media({
</span><span class="cx"> state: 'featured-image',
</span><span class="lines">@@ -415,28 +555,35 @@
</span><span class="cx"> this._frame.state('featured-image').on( 'select', this.select );
</span><span class="cx"> return this._frame;
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @global wp.media.view.settings
+ */
</ins><span class="cx"> select: function() {
</span><span class="cx"> var settings = wp.media.view.settings,
</span><span class="cx"> selection = this.get('selection').single();
</span><span class="cx">
</span><del>- if ( ! settings.post.featuredImageId )
</del><ins>+ if ( ! settings.post.featuredImageId ) {
</ins><span class="cx"> return;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> wp.media.featuredImage.set( selection ? selection.id : -1 );
</span><span class="cx"> },
</span><span class="cx">
</span><ins>+ /**
+ * Open the content media manager to the 'featured image' tab when
+ * the post thumbnail is clicked.
+ *
+ * Update the featured image id when the 'remove' link is clicked.
+ *
+ * @global wp.media.view.settings
+ */
</ins><span class="cx"> init: function() {
</span><del>- // Open the content media manager to the 'featured image' tab when
- // the post thumbnail is clicked.
</del><span class="cx"> $('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) {
</span><span class="cx"> event.preventDefault();
</span><span class="cx"> // Stop propagation to prevent thickbox from activating.
</span><span class="cx"> event.stopPropagation();
</span><span class="cx">
</span><span class="cx"> wp.media.featuredImage.frame().open();
</span><del>-
- // Update the featured image id when the 'remove' link is clicked.
</del><span class="cx"> }).on( 'click', '#remove-post-thumbnail', function() {
</span><span class="cx"> wp.media.view.settings.post.featuredImageId = -1;
</span><span class="cx"> });
</span><span class="lines">@@ -445,7 +592,16 @@
</span><span class="cx">
</span><span class="cx"> $( wp.media.featuredImage.init );
</span><span class="cx">
</span><ins>+ /**
+ * wp.media.editor
+ */
</ins><span class="cx"> wp.media.editor = {
</span><ins>+ /**
+ * @global tinymce
+ * @global QTags
+ *
+ * @param {string} html
+ */
</ins><span class="cx"> insert: function( html ) {
</span><span class="cx"> var editor,
</span><span class="cx"> hasTinymce = typeof tinymce !== 'undefined',
</span><span class="lines">@@ -485,11 +641,21 @@
</span><span class="cx"> }
</span><span class="cx"> },
</span><span class="cx">
</span><ins>+ /**
+ * @global wp.media.view.l10n
+ *
+ * @param {string} id A slug used to identify the workflow.
+ * @param {Object} [options={}]
+ *
+ * @returns {wp.media.view.MediaFrame} A media workflow.
+ */
</ins><span class="cx"> add: function( id, options ) {
</span><span class="cx"> var workflow = this.get( id );
</span><span class="cx">
</span><del>- if ( workflow ) // only add once: if exists return existing
</del><ins>+ // only add once: if exists return existing
+ if ( workflow ) {
</ins><span class="cx"> return workflow;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> workflow = workflows[ id ] = wp.media( _.defaults( options || {}, {
</span><span class="cx"> frame: 'post',
</span><span class="lines">@@ -543,10 +709,11 @@
</span><span class="cx"> link: 'none'
</span><span class="cx"> });
</span><span class="cx">
</span><del>- if ( 'none' === embed.link )
</del><ins>+ if ( 'none' === embed.link ) {
</ins><span class="cx"> embed.linkUrl = '';
</span><del>- else if ( 'file' === embed.link )
</del><ins>+ } else if ( 'file' === embed.link ) {
</ins><span class="cx"> embed.linkUrl = embed.url;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> this.insert( wp.media.string.image( embed ) );
</span><span class="cx"> }
</span><span class="lines">@@ -557,40 +724,69 @@
</span><span class="cx"> return workflow;
</span><span class="cx"> },
</span><span class="cx">
</span><ins>+ /**
+ * Determines the proper current workflow id
+ *
+ * @global wpActiveEditor
+ * @global tinymce
+ *
+ * @param {string} id
+ * @returns {wpActiveEditor|String|tinymce.activeEditor.id}
+ */
</ins><span class="cx"> id: function( id ) {
</span><del>- if ( id )
</del><ins>+ if ( id ) {
</ins><span class="cx"> return id;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // If an empty `id` is provided, default to `wpActiveEditor`.
</span><span class="cx"> id = wpActiveEditor;
</span><span class="cx">
</span><span class="cx"> // If that doesn't work, fall back to `tinymce.activeEditor.id`.
</span><del>- if ( ! id && typeof tinymce !== 'undefined' && tinymce.activeEditor )
</del><ins>+ if ( ! id && typeof tinymce !== 'undefined' && tinymce.activeEditor ) {
</ins><span class="cx"> id = tinymce.activeEditor.id;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> // Last but not least, fall back to the empty string.
</span><span class="cx"> id = id || '';
</span><span class="cx"> return id;
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * Return the workflow specified by id
+ *
+ * @param {string} id
+ * @returns {wp.media.view.MediaFrame} A media workflow.
+ */
</ins><span class="cx"> get: function( id ) {
</span><span class="cx"> id = this.id( id );
</span><span class="cx"> return workflows[ id ];
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * Remove the workflow represented by id from the workflow cache
+ *
+ * @param {string} id
+ */
</ins><span class="cx"> remove: function( id ) {
</span><span class="cx"> id = this.id( id );
</span><span class="cx"> delete workflows[ id ];
</span><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> send: {
</span><ins>+ /**
+ * @global wp.media.view.settings
+ * @global wp.media.post
+ *
+ * @param {Object} props
+ * @param {Object} attachment
+ * @returns {Promise}
+ */
</ins><span class="cx"> attachment: function( props, attachment ) {
</span><span class="cx"> var caption = attachment.caption,
</span><span class="cx"> options, html;
</span><span class="cx">
</span><span class="cx"> // If captions are disabled, clear the caption.
</span><del>- if ( ! wp.media.view.settings.captions )
</del><ins>+ if ( ! wp.media.view.settings.captions ) {
</ins><span class="cx"> delete attachment.caption;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> props = wp.media.string.props( props, attachment );
</span><span class="cx">
</span><span class="lines">@@ -600,8 +796,9 @@
</span><span class="cx"> post_excerpt: caption
</span><span class="cx"> };
</span><span class="cx">
</span><del>- if ( props.linkUrl )
</del><ins>+ if ( props.linkUrl ) {
</ins><span class="cx"> options.url = props.linkUrl;
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> if ( 'image' === attachment.type ) {
</span><span class="cx"> html = wp.media.string.image( props );
</span><span class="lines">@@ -630,7 +827,12 @@
</span><span class="cx"> post_id: wp.media.view.settings.post.id
</span><span class="cx"> });
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @global wp.media.view.settings
+ *
+ * @param {Object} embed
+ * @returns {Promise}
+ */
</ins><span class="cx"> link: function( embed ) {
</span><span class="cx"> return wp.media.post( 'send-link-to-editor', {
</span><span class="cx"> nonce: wp.media.view.settings.nonce.sendToEditor,
</span><span class="lines">@@ -641,7 +843,11 @@
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx"> },
</span><del>-
</del><ins>+ /**
+ * @param {string} id
+ * @param {Object} options
+ * @returns {wp.media.view.MediaFrame}
+ */
</ins><span class="cx"> open: function( id, options ) {
</span><span class="cx"> var workflow, editor;
</span><span class="cx">
</span><span class="lines">@@ -662,12 +868,18 @@
</span><span class="cx"> workflow = this.get( id );
</span><span class="cx">
</span><span class="cx"> // Redo workflow if state has changed
</span><del>- if ( ! workflow || ( workflow.options && options.state !== workflow.options.state ) )
</del><ins>+ if ( ! workflow || ( workflow.options && options.state !== workflow.options.state ) ) {
</ins><span class="cx"> workflow = this.add( id, options );
</span><ins>+ }
</ins><span class="cx">
</span><span class="cx"> return workflow.open();
</span><span class="cx"> },
</span><span class="cx">
</span><ins>+ /**
+ * Bind click event for .insert-media using event delegation
+ *
+ * @global wp.media.view.l10n
+ */
</ins><span class="cx"> init: function() {
</span><span class="cx"> $(document.body).on( 'click', '.insert-media', function( event ) {
</span><span class="cx"> var $this = $(this),
</span></span></pre>
</div>
</div>
</body>
</html>