wp/wp-includes/js/wp-util.js
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-includes/js/wp-util.js	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/js/wp-util.js	Tue Dec 15 13:49:49 2020 +0100
@@ -16,9 +16,9 @@
 	 *
 	 * Fetch a JavaScript template for an id, and return a templating function for it.
 	 *
-	 * @param  {string} id   A string that corresponds to a DOM element with an id prefixed with "tmpl-".
-	 *                       For example, "attachment" maps to "tmpl-attachment".
-	 * @return {function}    A function that lazily-compiles the template requested.
+	 * @param {string} id A string that corresponds to a DOM element with an id prefixed with "tmpl-".
+	 *                    For example, "attachment" maps to "tmpl-attachment".
+	 * @return {function} A function that lazily-compiles the template requested.
 	 */
 	wp.template = _.memoize(function ( id ) {
 		var compiled,
@@ -41,11 +41,13 @@
 		};
 	});
 
-	// wp.ajax
-	// ------
-	//
-	// Tools for sending ajax requests with JSON responses and built in error handling.
-	// Mirrors and wraps jQuery's ajax APIs.
+	/*
+	 * wp.ajax
+	 * ------
+	 *
+	 * Tools for sending ajax requests with JSON responses and built in error handling.
+	 * Mirrors and wraps jQuery's ajax APIs.
+	 */
 	wp.ajax = {
 		settings: settings.ajax || {},
 
@@ -54,11 +56,11 @@
 		 *
 		 * Sends a POST request to WordPress.
 		 *
-		 * @param  {(string|object)} action  The slug of the action to fire in WordPress or options passed
-		 *                                   to jQuery.ajax.
-		 * @param  {object=}         data    Optional. The data to populate $_POST with.
-		 * @return {$.promise}     A jQuery promise that represents the request,
-		 *                         decorated with an abort() method.
+		 * @param {(string|Object)} action The slug of the action to fire in WordPress or options passed
+		 *                                 to jQuery.ajax.
+		 * @param {Object=}         data   Optional. The data to populate $_POST with.
+		 * @return {$.promise} A jQuery promise that represents the request,
+		 *                     decorated with an abort() method.
 		 */
 		post: function( action, data ) {
 			return wp.ajax.send({
@@ -71,11 +73,11 @@
 		 *
 		 * Sends a POST request to WordPress.
 		 *
-		 * @param  {(string|object)} action  The slug of the action to fire in WordPress or options passed
-		 *                                   to jQuery.ajax.
-		 * @param  {object=}         options Optional. The options passed to jQuery.ajax.
-		 * @return {$.promise}      A jQuery promise that represents the request,
-		 *                          decorated with an abort() method.
+		 * @param {(string|Object)} action  The slug of the action to fire in WordPress or options passed
+		 *                                  to jQuery.ajax.
+		 * @param {Object=}         options Optional. The options passed to jQuery.ajax.
+		 * @return {$.promise} A jQuery promise that represents the request,
+		 *                     decorated with an abort() method.
 		 */
 		send: function( action, options ) {
 			var promise, deferred;
@@ -94,24 +96,29 @@
 
 			deferred = $.Deferred( function( deferred ) {
 				// Transfer success/error callbacks.
-				if ( options.success )
+				if ( options.success ) {
 					deferred.done( options.success );
-				if ( options.error )
+				}
+
+				if ( options.error ) {
 					deferred.fail( options.error );
+				}
 
 				delete options.success;
 				delete options.error;
 
-				// Use with PHP's wp_send_json_success() and wp_send_json_error()
+				// Use with PHP's wp_send_json_success() and wp_send_json_error().
 				deferred.jqXHR = $.ajax( options ).done( function( response ) {
 					// Treat a response of 1 as successful for backward compatibility with existing handlers.
-					if ( response === '1' || response === 1 )
+					if ( response === '1' || response === 1 ) {
 						response = { success: true };
+					}
 
-					if ( _.isObject( response ) && ! _.isUndefined( response.success ) )
+					if ( _.isObject( response ) && ! _.isUndefined( response.success ) ) {
 						deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( this, [response.data] );
-					else
+					} else {
 						deferred.rejectWith( this, [response] );
+					}
 				}).fail( function() {
 					deferred.rejectWith( this, arguments );
 				});