File Editor
Directories:
.. (Back)
codemirror
crop
dist
imgareaselect
jcrop
jquery
mediaelement
plupload
swfupload
thickbox
tinymce
Files:
admin-bar.js
admin-bar.min.js
api-request.js
api-request.min.js
autosave.js
autosave.min.js
backbone.js
backbone.min.js
clipboard.js
clipboard.min.js
colorpicker.js
colorpicker.min.js
comment-reply.js
comment-reply.min.js
customize-base.js
customize-base.min.js
customize-loader.js
customize-loader.min.js
customize-models.js
customize-models.min.js
customize-preview-nav-menus.js
customize-preview-nav-menus.min.js
customize-preview-widgets.js
customize-preview-widgets.min.js
customize-preview.js
customize-preview.min.js
customize-selective-refresh.js
customize-selective-refresh.min.js
customize-views.js
customize-views.min.js
heartbeat.js
heartbeat.min.js
hoverIntent.js
hoverIntent.min.js
hoverintent-js.min.js
imagesloaded.min.js
json2.js
json2.min.js
masonry.min.js
mce-view.js
mce-view.min.js
media-audiovideo.js
media-audiovideo.min.js
media-editor.js
media-editor.min.js
media-grid.js
media-grid.min.js
media-models.js
media-models.min.js
media-views.js
media-views.min.js
quicktags.js
quicktags.min.js
shortcode.js
shortcode.min.js
swfobject.js
tw-sack.js
tw-sack.min.js
twemoji.js
twemoji.min.js
underscore.js
underscore.min.js
utils.js
utils.min.js
wp-ajax-response.js
wp-ajax-response.min.js
wp-api.js
wp-api.min.js
wp-auth-check.js
wp-auth-check.min.js
wp-backbone.js
wp-backbone.min.js
wp-custom-header.js
wp-custom-header.min.js
wp-embed-template.js
wp-embed-template.min.js
wp-embed.js
wp-embed.min.js
wp-emoji-loader.js
wp-emoji-loader.min.js
wp-emoji-release.min.js
wp-emoji.js
wp-emoji.min.js
wp-list-revisions.js
wp-list-revisions.min.js
wp-lists.js
wp-lists.min.js
wp-pointer.js
wp-pointer.min.js
wp-sanitize.js
wp-sanitize.min.js
wp-util.js
wp-util.min.js
wpdialog.js
wpdialog.min.js
wplink.js
wplink.min.js
zxcvbn-async.js
zxcvbn-async.min.js
zxcvbn.min.js
Create New File
Create
Edit File: 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 ) { 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 ) ) { 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));
Save Changes
Rename File
Rename