PHP 7.4.33
Preview: wp-util.js Size: 4.57 KB
/var/www/fresco.wpress.dk/httpdocs/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: 100
Name Size Perms Modified Actions
- drwxr-xr-x 2023-08-29 14:14:52
Edit Download
crop DIR
- drwxr-xr-x 2023-08-29 14:14:52
Edit Download
dist DIR
- drwxr-xr-x 2023-08-29 14:14:52
Edit Download
- drwxr-xr-x 2023-08-29 14:14:52
Edit Download
jcrop DIR
- drwxr-xr-x 2023-08-29 14:14:52
Edit Download
jquery DIR
- drwxr-xr-x 2023-08-29 14:14:52
Edit Download
- drwxr-xr-x 2023-08-29 14:14:52
Edit Download
plupload DIR
- drwxr-xr-x 2023-08-29 14:14:52
Edit Download
swfupload DIR
- drwxr-xr-x 2023-08-29 14:14:52
Edit Download
thickbox DIR
- drwxr-xr-x 2023-08-29 14:14:52
Edit Download
tinymce DIR
- drwxr-xr-x 2023-08-29 14:14:52
Edit Download
10.51 KB lrw-r--r-- 2020-07-27 23:35:02
Edit Download
3.45 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
3.25 KB lrw-r--r-- 2020-12-01 03:44:05
Edit Download
1023 B lrw-r--r-- 2022-04-08 20:07:18
Edit Download
21.95 KB lrw-r--r-- 2021-03-18 19:01:03
Edit Download
5.67 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
76.35 KB lrw-r--r-- 2022-04-12 17:17:22
Edit Download
23.29 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
26.18 KB lrw-r--r-- 2022-10-04 15:55:23
Edit Download
8.80 KB lrw-r--r-- 2022-10-04 15:55:23
Edit Download
28.40 KB lrw-r--r-- 2012-11-17 15:11:29
Edit Download
16.13 KB lrw-r--r-- 2022-09-23 19:55:30
Edit Download
12.17 KB lrw-r--r-- 2023-01-10 09:30:13
Edit Download
2.91 KB lrw-r--r-- 2022-04-08 20:07:18
Edit Download
25.22 KB lrw-r--r-- 2023-05-20 10:19:23
Edit Download
7.67 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
7.72 KB lrw-r--r-- 2020-06-20 12:58:10
Edit Download
3.47 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
6.66 KB lrw-r--r-- 2020-06-25 12:43:07
Edit Download
3.59 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
14.67 KB lrw-r--r-- 2020-07-27 23:35:02
Edit Download
4.92 KB lrw-r--r-- 2022-04-08 20:07:18
Edit Download
22.71 KB lrw-r--r-- 2020-06-20 12:58:10
Edit Download
7.64 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
27.30 KB lrw-r--r-- 2020-07-27 23:35:02
Edit Download
10.45 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
32.55 KB lrw-r--r-- 2020-07-28 00:07:03
Edit Download
10.44 KB lrw-r--r-- 2022-04-08 20:07:18
Edit Download
4.95 KB lrw-r--r-- 2018-06-28 02:30:15
Edit Download
2.39 KB lrw-r--r-- 2021-01-06 15:29:24
Edit Download
22.69 KB lrw-r--r-- 2022-04-20 05:55:06
Edit Download
5.79 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
1.68 KB lrw-r--r-- 2019-12-10 01:03:02
Edit Download
7.06 KB lrw-r--r-- 2022-01-03 15:03:18
Edit Download
1.46 KB lrw-r--r-- 2022-04-08 20:07:18
Edit Download
5.50 KB lrw-r--r-- 2020-06-13 18:53:27
Edit Download
17.99 KB lrw-r--r-- 2015-10-06 14:02:25
Edit Download
3.07 KB lrw-r--r-- 2022-09-23 19:55:30
Edit Download
23.57 KB lrw-r--r-- 2020-06-13 18:53:27
Edit Download
25.45 KB lrw-r--r-- 2020-07-27 23:35:02
Edit Download
9.65 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
24.45 KB lrw-r--r-- 2023-05-16 14:27:21
Edit Download
11.85 KB lrw-r--r-- 2023-05-16 14:27:21
Edit Download
28.44 KB lrw-r--r-- 2020-07-27 23:35:02
Edit Download
10.63 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
26.23 KB lrw-r--r-- 2022-04-11 12:04:30
Edit Download
13.03 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
42.88 KB lrw-r--r-- 2022-04-11 12:04:30
Edit Download
13.08 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
265.05 KB lrw-r--r-- 2023-04-12 23:44:22
Edit Download
107.69 KB lrw-r--r-- 2023-04-12 23:44:22
Edit Download
22.07 KB lrw-r--r-- 2021-09-08 23:29:58
Edit Download
10.87 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
10.51 KB lrw-r--r-- 2020-01-29 00:45:18
Edit Download
2.58 KB lrw-r--r-- 2022-09-23 19:55:30
Edit Download
9.99 KB lrw-r--r-- 2012-04-17 23:09:29
Edit Download
4.85 KB lrw-r--r-- 2012-08-23 00:04:18
Edit Download
3.21 KB lrw-r--r-- 2022-04-08 20:07:18
Edit Download
32.31 KB lrw-r--r-- 2023-02-02 00:53:25
Edit Download
15.38 KB lrw-r--r-- 2023-02-02 00:53:25
Edit Download
66.77 KB lrw-r--r-- 2022-09-27 15:18:25
Edit Download
18.39 KB lrw-r--r-- 2022-09-27 15:18:25
Edit Download
4.56 KB lrw-r--r-- 2020-01-29 00:45:18
Edit Download
1.82 KB lrw-r--r-- 2022-09-23 19:55:30
Edit Download
3.68 KB lrw-r--r-- 2022-07-16 01:08:10
Edit Download
2.38 KB lrw-r--r-- 2022-09-23 19:55:30
Edit Download
45.88 KB lrw-r--r-- 2023-01-10 09:30:13
Edit Download
14.34 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
4.11 KB lrw-r--r-- 2021-03-18 19:01:03
Edit Download
1.62 KB lrw-r--r-- 2021-03-18 19:01:03
Edit Download
14.88 KB lrw-r--r-- 2020-06-20 12:58:10
Edit Download
2.97 KB lrw-r--r-- 2022-04-08 20:07:18
Edit Download
10.22 KB lrw-r--r-- 2021-04-10 12:40:05
Edit Download
4.34 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
6.62 KB lrw-r--r-- 2021-11-11 02:49:18
Edit Download
3.10 KB lrw-r--r-- 2022-04-08 20:07:18
Edit Download
3.83 KB lrw-r--r-- 2023-05-16 14:25:21
Edit Download
1.55 KB lrw-r--r-- 2023-05-16 14:25:21
Edit Download
12.23 KB lrw-r--r-- 2023-08-07 16:54:35
Edit Download
2.92 KB lrw-r--r-- 2023-08-07 16:54:35
Edit Download
18.25 KB lrw-r--r-- 2023-02-02 00:53:25
Edit Download
8.76 KB lrw-r--r-- 2023-02-02 00:53:25
Edit Download
2.82 KB lrw-r--r-- 2023-02-02 00:53:25
Edit Download
970 B lrw-r--r-- 2018-06-28 02:30:15
Edit Download
597 B lrw-r--r-- 2021-01-06 15:29:24
Edit Download
24.72 KB lrw-r--r-- 2023-06-24 14:32:20
Edit Download
7.34 KB lrw-r--r-- 2023-06-24 14:32:20
Edit Download
9.99 KB lrw-r--r-- 2021-02-16 20:25:03
Edit Download
3.54 KB lrw-r--r-- 2022-04-08 20:07:18
Edit Download
1.32 KB lrw-r--r-- 2019-09-04 17:13:21
Edit Download
458 B lrw-r--r-- 2022-04-08 20:07:18
Edit Download
4.57 KB lrw-r--r-- 2022-09-20 03:52:10
Edit Download
1.39 KB lrw-r--r-- 2022-09-20 03:52:10
Edit Download
569 B lrw-r--r-- 2023-01-24 21:13:12
Edit Download
281 B lrw-r--r-- 2023-01-24 21:13:12
Edit Download
20.66 KB lrw-r--r-- 2021-03-18 19:01:03
Edit Download
10.99 KB lrw-r--r-- 2023-02-02 16:36:32
Edit Download
821 B lrw-r--r-- 2018-06-28 02:30:15
Edit Download
351 B lrw-r--r-- 2021-02-23 16:45:19
Edit Download
802.97 KB lrw-r--r-- 2019-10-26 00:17:07
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).