wp/wp-includes/js/media-editor.js
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
--- a/wp/wp-includes/js/media-editor.js	Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-includes/js/media-editor.js	Mon Oct 14 17:39:30 2019 +0200
@@ -30,39 +30,21 @@
 		return attrs[ key ];
 	};
 
-	/**
-	 * wp.media.string
-	 * @namespace
-	 */
+	/** @namespace wp.media.string */
 	wp.media.string = {
 		/**
 		 * Joins the `props` and `attachment` objects,
 		 * outputting the proper object format based on the
 		 * attachment's type.
 		 *
-		 * @global wp.media.view.settings
-		 * @global getUserSetting()
-		 *
 		 * @param {Object} [props={}] Attachment details (align, link, size, etc).
 		 * @param {Object} attachment The attachment object, media version of Post.
 		 * @returns {Object} Joined props
 		 */
 		props: function( props, attachment ) {
-			var link, linkUrl, size, sizes, fallbacks,
+			var link, linkUrl, size, sizes,
 				defaultProps = wp.media.view.settings.defaultProps;
 
-			// Final fallbacks run after all processing has been completed.
-			fallbacks = function( props ) {
-				// Generate alt fallbacks and strip tags.
-				if ( 'image' === props.type && ! props.alt ) {
-					props.alt = props.caption || props.title || '';
-					props.alt = props.alt.replace( /<\/?[^>]+>/g, '' );
-					props.alt = props.alt.replace( /[\r\n]+/g, ' ' );
-				}
-
-				return props;
-			};
-
 			props = props ? _.clone( props ) : {};
 
 			if ( attachment && attachment.type ) {
@@ -80,7 +62,7 @@
 
 			// All attachment-specific settings follow.
 			if ( ! attachment ) {
-				return fallbacks( props );
+				return props;
 			}
 
 			props.title = props.title || attachment.title;
@@ -116,13 +98,11 @@
 				props.rel = props.rel || 'attachment wp-att-' + attachment.id;
 			}
 
-			return fallbacks( props );
+			return props;
 		},
 		/**
 		 * Create link markup that is suitable for passing to the editor
 		 *
-		 * @global wp.html.string
-		 *
 		 * @param {Object} props Attachment details (align, link, size, etc).
 		 * @param {Object} attachment The attachment object, media version of Post.
 		 * @returns {string} The link markup
@@ -171,9 +151,6 @@
 		 *
 		 * @access private
 		 *
-		 * @global wp.shortcode
-		 * @global wp.media.view.settings
-		 *
 		 * @param {string} type The shortcode tag name: 'audio' or 'video'.
 		 * @param {Object} props Attachment details (align, link, size, etc).
 		 * @param {Object} attachment The attachment object, media version of Post.
@@ -222,9 +199,6 @@
 		 * Create image markup, optionally with a link and/or wrapped in a caption shortcode,
 		 *  that is suitable for passing to the editor
 		 *
-		 * @global wp.html
-		 * @global wp.shortcode
-		 *
 		 * @param {Object} props Attachment details (align, link, size, etc).
 		 * @param {Object} attachment The attachment object, media version of Post.
 		 * @returns {string}
@@ -233,6 +207,7 @@
 			var img = {},
 				options, classes, shortcode, html;
 
+			props.type = 'image';
 			props = wp.media.string.props( props, attachment );
 			classes = props.classes || [];
 
@@ -352,16 +327,19 @@
 		}
 	};
 
+	/**
+	 * @class wp.media.collection
+	 *
+	 * @param {Object} attributes
+	 */
 	wp.media.collection = function(attributes) {
 		var collections = {};
 
-		return _.extend( {
+		return _.extend(/** @lends wp.media.collection.prototype */{
 			coerce : wp.media.coerce,
 			/**
 			 * Retrieve attachments based on the properties of the passed shortcode
 			 *
-			 * @global wp.media.query
-			 *
 			 * @param {wp.shortcode} shortcode An instance of wp.shortcode().
 			 * @returns {wp.media.model.Attachments} A Backbone.Collection containing
 			 *      the media items belonging to a collection.
@@ -428,9 +406,6 @@
 			/**
 			 * Triggered when clicking 'Insert {label}' or 'Update {label}'
 			 *
-			 * @global wp.shortcode
-			 * @global wp.media.model.Attachments
-			 *
 			 * @param {wp.media.model.Attachments} attachments A Backbone.Collection containing
 			 *      the media items belonging to a collection.
 			 *      The query[ this.tag ] property is a Backbone.Model
@@ -499,10 +474,6 @@
 			 * Triggered when double-clicking a collection shortcode placeholder
 			 *   in the editor
 			 *
-			 * @global wp.shortcode
-			 * @global wp.media.model.Selection
-			 * @global wp.media.view.l10n
-			 *
 			 * @param {string} content Content that is searched for possible
 			 *    shortcode markup matching the passed tag name,
 			 *
@@ -621,15 +592,13 @@
 	});
 
 	/**
-	 * wp.media.featuredImage
-	 * @namespace
+	 * @namespace wp.media.featuredImage
+	 * @memberOf wp.media
 	 */
 	wp.media.featuredImage = {
 		/**
 		 * Get the featured image post ID
 		 *
-		 * @global wp.media.view.settings
-		 *
 		 * @returns {wp.media.view.settings.post.featuredImageId|number}
 		 */
 		get: function() {
@@ -639,9 +608,6 @@
 		 * 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 The post ID of the featured image, or -1 to unset it.
 		 */
 		set: function( id ) {
@@ -649,27 +615,35 @@
 
 			settings.post.featuredImageId = id;
 
-			wp.media.post( 'set-post-thumbnail', {
-				json:         true,
+			wp.media.post( 'get-post-thumbnail-html', {
 				post_id:      settings.post.id,
 				thumbnail_id: settings.post.featuredImageId,
 				_wpnonce:     settings.post.nonce
 			}).done( function( html ) {
+				if ( html == '0' ) {
+					window.alert( window.setPostThumbnailL10n.error );
+					return;
+				}
 				$( '.inside', '#postimagediv' ).html( html );
 			});
 		},
 		/**
+		 * Remove the featured image id, save the post thumbnail data and
+		 * set the HTML in the post meta box to no featured image.
+		 */
+		remove: function() {
+			wp.media.featuredImage.set( -1 );
+		},
+		/**
 		 * The Featured Image workflow
 		 *
-		 * @global wp.media.controller.FeaturedImage
-		 * @global wp.media.view.l10n
-		 *
 		 * @this wp.media.featuredImage
 		 *
 		 * @returns {wp.media.view.MediaFrame.Select} A media workflow.
 		 */
 		frame: function() {
 			if ( this._frame ) {
+				wp.media.frame = this._frame;
 				return this._frame;
 			}
 
@@ -705,8 +679,6 @@
 		 * 'select' callback for Featured Image workflow, triggered when
 		 *  the 'Set Featured Image' button is clicked in the media modal.
 		 *
-		 * @global wp.media.view.settings
-		 *
 		 * @this wp.media.controller.FeaturedImage
 		 */
 		select: function() {
@@ -723,8 +695,6 @@
 		 * the post thumbnail is clicked.
 		 *
 		 * Update the featured image id when the 'remove' link is clicked.
-		 *
-		 * @global wp.media.view.settings
 		 */
 		init: function() {
 			$('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) {
@@ -734,26 +704,19 @@
 
 				wp.media.featuredImage.frame().open();
 			}).on( 'click', '#remove-post-thumbnail', function() {
-				wp.media.view.settings.post.featuredImageId = -1;
+				wp.media.featuredImage.remove();
+				return false;
 			});
 		}
 	};
 
 	$( wp.media.featuredImage.init );
 
-	/**
-	 * wp.media.editor
-	 * @namespace
-	 */
+	/** @namespace wp.media.editor */
 	wp.media.editor = {
 		/**
 		 * Send content to the editor
 		 *
-		 * @global tinymce
-		 * @global QTags
-		 * @global wpActiveEditor
-		 * @global tb_remove() - Possibly overloaded by legacy plugins
-		 *
 		 * @param {string} html Content to send to the editor
 		 */
 		insert: function( html ) {
@@ -804,8 +767,6 @@
 		 * Setup 'workflow' and add to the 'workflows' cache. 'open' can
 		 *  subsequently be called upon it.
 		 *
-		 * @global wp.media.view.l10n
-		 *
 		 * @param {string} id A slug used to identify the workflow.
 		 * @param {Object} [options={}]
 		 *
@@ -913,9 +874,6 @@
 		/**
 		 * Determines the proper current workflow id
 		 *
-		 * @global wpActiveEditor
-		 * @global tinymce
-		 *
 		 * @param {string} [id=''] A slug used to identify the workflow.
 		 *
 		 * @returns {wpActiveEditor|string|tinymce.activeEditor.id}
@@ -961,17 +919,12 @@
 			id = this.id( id );
 			delete workflows[ id ];
 		},
-		/**
-		 * @namespace
-		 */
+		/** @namespace wp.media.editor.send */
 		send: {
 			/**
 			 * Called when sending an attachment to the editor
 			 *   from the medial modal.
 			 *
-			 * @global wp.media.view.settings
-			 * @global wp.media.post
-			 *
 			 * @param {Object} props Attachment details (align, link, size, etc).
 			 * @param {Object} attachment The attachment object, media version of Post.
 			 * @returns {Promise}
@@ -1027,8 +980,6 @@
 			/**
 			 * Called when 'Insert From URL' source is not an image. Example: YouTube url.
 			 *
-			 * @global wp.media.view.settings
-			 *
 			 * @param {Object} embed
 			 * @returns {Promise}
 			 */
@@ -1067,13 +1018,13 @@
 				workflow = this.add( id, options );
 			}
 
+			wp.media.frame = workflow;
+
 			return workflow.open();
 		},
 
 		/**
 		 * Bind click event for .insert-media using event delegation
-		 *
-		 * @global wp.media.view.l10n
 		 */
 		init: function() {
 			$(document.body)
@@ -1089,13 +1040,6 @@
 
 					event.preventDefault();
 
-					// Remove focus from the `.insert-media` button.
-					// Prevents Opera from showing the outline of the button
-					// above the modal.
-					//
-					// See: https://core.trac.wordpress.org/ticket/22445
-					elem.blur();
-
 					if ( elem.hasClass( 'gallery' ) ) {
 						options.state = 'gallery';
 						options.title = wp.media.view.l10n.createGalleryTitle;