Edit File by line
/home/barbar84/public_h.../wp-inclu.../js
File: wp-util.js
/**
[0] Fix | Delete
* @output wp-includes/js/wp-util.js
[1] Fix | Delete
*/
[2] Fix | Delete
[3] Fix | Delete
/* global _wpUtilSettings */
[4] Fix | Delete
[5] Fix | Delete
/** @namespace wp */
[6] Fix | Delete
window.wp = window.wp || {};
[7] Fix | Delete
[8] Fix | Delete
(function ($) {
[9] Fix | Delete
// Check for the utility settings.
[10] Fix | Delete
var settings = typeof _wpUtilSettings === 'undefined' ? {} : _wpUtilSettings;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* wp.template( id )
[14] Fix | Delete
*
[15] Fix | Delete
* Fetch a JavaScript template for an id, and return a templating function for it.
[16] Fix | Delete
*
[17] Fix | Delete
* @param {string} id A string that corresponds to a DOM element with an id prefixed with "tmpl-".
[18] Fix | Delete
* For example, "attachment" maps to "tmpl-attachment".
[19] Fix | Delete
* @return {function} A function that lazily-compiles the template requested.
[20] Fix | Delete
*/
[21] Fix | Delete
wp.template = _.memoize(function ( id ) {
[22] Fix | Delete
var compiled,
[23] Fix | Delete
/*
[24] Fix | Delete
* Underscore's default ERB-style templates are incompatible with PHP
[25] Fix | Delete
* when asp_tags is enabled, so WordPress uses Mustache-inspired templating syntax.
[26] Fix | Delete
*
[27] Fix | Delete
* @see trac ticket #22344.
[28] Fix | Delete
*/
[29] Fix | Delete
options = {
[30] Fix | Delete
evaluate: /<#([\s\S]+?)#>/g,
[31] Fix | Delete
interpolate: /\{\{\{([\s\S]+?)\}\}\}/g,
[32] Fix | Delete
escape: /\{\{([^\}]+?)\}\}(?!\})/g,
[33] Fix | Delete
variable: 'data'
[34] Fix | Delete
};
[35] Fix | Delete
[36] Fix | Delete
return function ( data ) {
[37] Fix | Delete
compiled = compiled || _.template( $( '#tmpl-' + id ).html(), options );
[38] Fix | Delete
return compiled( data );
[39] Fix | Delete
};
[40] Fix | Delete
});
[41] Fix | Delete
[42] Fix | Delete
/*
[43] Fix | Delete
* wp.ajax
[44] Fix | Delete
* ------
[45] Fix | Delete
*
[46] Fix | Delete
* Tools for sending ajax requests with JSON responses and built in error handling.
[47] Fix | Delete
* Mirrors and wraps jQuery's ajax APIs.
[48] Fix | Delete
*/
[49] Fix | Delete
wp.ajax = {
[50] Fix | Delete
settings: settings.ajax || {},
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* wp.ajax.post( [action], [data] )
[54] Fix | Delete
*
[55] Fix | Delete
* Sends a POST request to WordPress.
[56] Fix | Delete
*
[57] Fix | Delete
* @param {(string|Object)} action The slug of the action to fire in WordPress or options passed
[58] Fix | Delete
* to jQuery.ajax.
[59] Fix | Delete
* @param {Object=} data Optional. The data to populate $_POST with.
[60] Fix | Delete
* @return {$.promise} A jQuery promise that represents the request,
[61] Fix | Delete
* decorated with an abort() method.
[62] Fix | Delete
*/
[63] Fix | Delete
post: function( action, data ) {
[64] Fix | Delete
return wp.ajax.send({
[65] Fix | Delete
data: _.isObject( action ) ? action : _.extend( data || {}, { action: action })
[66] Fix | Delete
});
[67] Fix | Delete
},
[68] Fix | Delete
[69] Fix | Delete
/**
[70] Fix | Delete
* wp.ajax.send( [action], [options] )
[71] Fix | Delete
*
[72] Fix | Delete
* Sends a POST request to WordPress.
[73] Fix | Delete
*
[74] Fix | Delete
* @param {(string|Object)} action The slug of the action to fire in WordPress or options passed
[75] Fix | Delete
* to jQuery.ajax.
[76] Fix | Delete
* @param {Object=} options Optional. The options passed to jQuery.ajax.
[77] Fix | Delete
* @return {$.promise} A jQuery promise that represents the request,
[78] Fix | Delete
* decorated with an abort() method.
[79] Fix | Delete
*/
[80] Fix | Delete
send: function( action, options ) {
[81] Fix | Delete
var promise, deferred;
[82] Fix | Delete
if ( _.isObject( action ) ) {
[83] Fix | Delete
options = action;
[84] Fix | Delete
} else {
[85] Fix | Delete
options = options || {};
[86] Fix | Delete
options.data = _.extend( options.data || {}, { action: action });
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
options = _.defaults( options || {}, {
[90] Fix | Delete
type: 'POST',
[91] Fix | Delete
url: wp.ajax.settings.url,
[92] Fix | Delete
context: this
[93] Fix | Delete
});
[94] Fix | Delete
[95] Fix | Delete
deferred = $.Deferred( function( deferred ) {
[96] Fix | Delete
// Transfer success/error callbacks.
[97] Fix | Delete
if ( options.success ) {
[98] Fix | Delete
deferred.done( options.success );
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
if ( options.error ) {
[102] Fix | Delete
deferred.fail( options.error );
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
delete options.success;
[106] Fix | Delete
delete options.error;
[107] Fix | Delete
[108] Fix | Delete
// Use with PHP's wp_send_json_success() and wp_send_json_error().
[109] Fix | Delete
deferred.jqXHR = $.ajax( options ).done( function( response ) {
[110] Fix | Delete
// Treat a response of 1 as successful for backward compatibility with existing handlers.
[111] Fix | Delete
if ( response === '1' || response === 1 ) {
[112] Fix | Delete
response = { success: true };
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
if ( _.isObject( response ) && ! _.isUndefined( response.success ) ) {
[116] Fix | Delete
deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( this, [response.data] );
[117] Fix | Delete
} else {
[118] Fix | Delete
deferred.rejectWith( this, [response] );
[119] Fix | Delete
}
[120] Fix | Delete
}).fail( function() {
[121] Fix | Delete
deferred.rejectWith( this, arguments );
[122] Fix | Delete
});
[123] Fix | Delete
});
[124] Fix | Delete
[125] Fix | Delete
promise = deferred.promise();
[126] Fix | Delete
promise.abort = function() {
[127] Fix | Delete
deferred.jqXHR.abort();
[128] Fix | Delete
return this;
[129] Fix | Delete
};
[130] Fix | Delete
[131] Fix | Delete
return promise;
[132] Fix | Delete
}
[133] Fix | Delete
};
[134] Fix | Delete
[135] Fix | Delete
}(jQuery));
[136] Fix | Delete
[137] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function