PHP 8.2.29
Preview: wp-util.js Size: 4.57 KB
/home/medyaist/vetplusveteriner.com/wp-includes/js/wp-util.js
/**
 * @output wp-includes/js/wp-util.js
 */

/* global _wpUtilSettings */

/** @namespace wp */
window.wp = window.wp || {};

(function ($) {
	// Check for the utility settings.
	var settings = typeof _wpUtilSettings === 'undefined' ? {} : _wpUtilSettings;

	/**
	 * wp.template( id )
	 *
	 * 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.
	 */
	wp.template = _.memoize(function ( id ) {
		var compiled,
			/*
			 * Underscore's default ERB-style templates are incompatible with PHP
			 * when asp_tags is enabled, so WordPress uses Mustache-inspired templating syntax.
			 *
			 * @see trac ticket #22344.
			 */
			options = {
				evaluate:    /<#([\s\S]+?)#>/g,
				interpolate: /\{\{\{([\s\S]+?)\}\}\}/g,
				escape:      /\{\{([^\}]+?)\}\}(?!\})/g,
				variable:    'data'
			};

		return function ( data ) {
			if ( ! document.getElementById( 'tmpl-' + id ) ) {
				throw new Error( 'Template not found: ' + '#tmpl-' + id );
			}
			compiled = compiled || _.template( $( '#tmpl-' + id ).html(),  options );
			return compiled( data );
		};
	});

	/*
	 * 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 || {},

		/**
		 * wp.ajax.post( [action], [data] )
		 *
		 * 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.
		 */
		post: function( action, data ) {
			return wp.ajax.send({
				data: _.isObject( action ) ? action : _.extend( data || {}, { action: action })
			});
		},

		/**
		 * wp.ajax.send( [action], [options] )
		 *
		 * 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.
		 */
		send: function( action, options ) {
			var promise, deferred;
			if ( _.isObject( action ) ) {
				options = action;
			} else {
				options = options || {};
				options.data = _.extend( options.data || {}, { action: action });
			}

			options = _.defaults( options || {}, {
				type:    'POST',
				url:     wp.ajax.settings.url,
				context: this
			});

			deferred = $.Deferred( function( deferred ) {
				// Transfer success/error callbacks.
				if ( options.success ) {
					deferred.done( options.success );
				}

				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().
				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 ) {
						response = { success: true };
					}

					if ( _.isObject( response ) && ! _.isUndefined( response.success ) ) {

						// When handling a media attachments request, get the total attachments from response headers.
						var context = this;
						deferred.done( function() {
							if (
								action &&
								action.data &&
								'query-attachments' === action.data.action &&
								deferred.jqXHR.hasOwnProperty( 'getResponseHeader' ) &&
								deferred.jqXHR.getResponseHeader( 'X-WP-Total' )
							) {
								context.totalAttachments = parseInt( deferred.jqXHR.getResponseHeader( 'X-WP-Total' ), 10 );
							} else {
								context.totalAttachments = 0;
							}
						} );
						deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( this, [response.data] );
					} else {
						deferred.rejectWith( this, [response] );
					}
				}).fail( function() {
					deferred.rejectWith( this, arguments );
				});
			});

			promise = deferred.promise();
			promise.abort = function() {
				deferred.jqXHR.abort();
				return this;
			};

			return promise;
		}
	};

}(jQuery));

Directory Contents

Dirs: 11 × Files: 31
Name Size Perms Modified Actions
- drwxr-xr-x 2026-01-13 23:30:27
Edit Download
crop DIR
- drwxr-xr-x 2026-01-13 23:58:38
Edit Download
dist DIR
- drwxr-xr-x 2026-01-13 23:58:57
Edit Download
- drwxr-xr-x 2026-01-13 23:30:09
Edit Download
jcrop DIR
- drwxr-xr-x 2025-10-15 22:49:45
Edit Download
jquery DIR
- drwxr-xr-x 2025-10-15 22:49:45
Edit Download
- drwxr-xr-x 2025-10-15 22:49:45
Edit Download
plupload DIR
- drwxr-xr-x 2026-01-14 00:06:10
Edit Download
swfupload DIR
- drwxr-xr-x 2026-01-13 23:30:16
Edit Download
thickbox DIR
- drwxr-xr-x 2026-01-13 23:30:22
Edit Download
tinymce DIR
- drwxr-xr-x 2026-01-14 00:06:07
Edit Download
25.24 KB lrw-r--r-- 2023-10-09 18:31:28
Edit Download
9.54 KB lrw-r--r-- 2025-02-06 14:27:26
Edit Download
3.81 KB lrw-r--r-- 2025-02-08 12:53:18
Edit Download
2.51 KB lrw-r--r-- 2025-02-08 12:53:18
Edit Download
45.88 KB lrw-r--r-- 2023-01-10 06:30:14
Edit Download
14.34 KB lrw-r--r-- 2025-02-06 14:27:26
Edit Download
4.11 KB lrw-r--r-- 2021-03-18 16:01:04
Edit Download
1.62 KB lrw-r--r-- 2025-02-06 14:27:26
Edit Download
14.88 KB lrw-r--r-- 2024-04-12 14:47:14
Edit Download
2.97 KB lrw-r--r-- 2025-02-06 14:27:26
Edit Download
10.22 KB lrw-r--r-- 2021-04-10 09:40:06
Edit Download
4.34 KB lrw-r--r-- 2025-02-06 14:27:26
Edit Download
6.62 KB lrw-r--r-- 2021-11-10 23:49:18
Edit Download
3.10 KB lrw-r--r-- 2025-02-06 14:27:26
Edit Download
3.14 KB lrw-r--r-- 2023-08-10 16:49:18
Edit Download
1.22 KB lrw-r--r-- 2025-02-06 14:27:26
Edit Download
12.89 KB lrw-r--r-- 2025-12-03 17:56:33
Edit Download
2.82 KB lrw-r--r-- 2025-12-03 17:56:33
Edit Download
22.23 KB lrw-r--r-- 2025-12-03 17:56:33
Edit Download
8.59 KB lrw-r--r-- 2025-12-03 17:56:33
Edit Download
2.79 KB lrw-r--r-- 2025-12-03 17:56:32
Edit Download
970 B lrw-r--r-- 2018-06-27 23:30:16
Edit Download
597 B lrw-r--r-- 2025-02-06 14:27:26
Edit Download
24.72 KB lrw-r--r-- 2023-06-24 11:32:20
Edit Download
7.34 KB lrw-r--r-- 2025-02-06 14:27:26
Edit Download
9.99 KB lrw-r--r-- 2021-02-16 17:25:04
Edit Download
3.54 KB lrw-r--r-- 2025-02-06 14:27:26
Edit Download
1.30 KB lrw-r--r-- 2025-12-03 17:56:32
Edit Download
444 B lrw-r--r-- 2025-12-03 17:56:33
Edit Download
4.57 KB lrw-r--r-- 2022-09-20 00:52:10
Edit Download
1.39 KB lrw-r--r-- 2025-02-06 14:27:26
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).