Edit File by line
/home/zeestwma/richards.../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
if ( ! document.getElementById( 'tmpl-' + id ) ) {
[38] Fix | Delete
throw new Error( 'Template not found: ' + '#tmpl-' + id );
[39] Fix | Delete
}
[40] Fix | Delete
compiled = compiled || _.template( $( '#tmpl-' + id ).html(), options );
[41] Fix | Delete
return compiled( data );
[42] Fix | Delete
};
[43] Fix | Delete
});
[44] Fix | Delete
[45] Fix | Delete
/*
[46] Fix | Delete
* wp.ajax
[47] Fix | Delete
* ------
[48] Fix | Delete
*
[49] Fix | Delete
* Tools for sending ajax requests with JSON responses and built in error handling.
[50] Fix | Delete
* Mirrors and wraps jQuery's ajax APIs.
[51] Fix | Delete
*/
[52] Fix | Delete
wp.ajax = {
[53] Fix | Delete
settings: settings.ajax || {},
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* wp.ajax.post( [action], [data] )
[57] Fix | Delete
*
[58] Fix | Delete
* Sends a POST request to WordPress.
[59] Fix | Delete
*
[60] Fix | Delete
* @param {(string|Object)} action The slug of the action to fire in WordPress or options passed
[61] Fix | Delete
* to jQuery.ajax.
[62] Fix | Delete
* @param {Object=} data Optional. The data to populate $_POST with.
[63] Fix | Delete
* @return {$.promise} A jQuery promise that represents the request,
[64] Fix | Delete
* decorated with an abort() method.
[65] Fix | Delete
*/
[66] Fix | Delete
post: function( action, data ) {
[67] Fix | Delete
return wp.ajax.send({
[68] Fix | Delete
data: _.isObject( action ) ? action : _.extend( data || {}, { action: action })
[69] Fix | Delete
});
[70] Fix | Delete
},
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* wp.ajax.send( [action], [options] )
[74] Fix | Delete
*
[75] Fix | Delete
* Sends a POST request to WordPress.
[76] Fix | Delete
*
[77] Fix | Delete
* @param {(string|Object)} action The slug of the action to fire in WordPress or options passed
[78] Fix | Delete
* to jQuery.ajax.
[79] Fix | Delete
* @param {Object=} options Optional. The options passed to jQuery.ajax.
[80] Fix | Delete
* @return {$.promise} A jQuery promise that represents the request,
[81] Fix | Delete
* decorated with an abort() method.
[82] Fix | Delete
*/
[83] Fix | Delete
send: function( action, options ) {
[84] Fix | Delete
var promise, deferred;
[85] Fix | Delete
if ( _.isObject( action ) ) {
[86] Fix | Delete
options = action;
[87] Fix | Delete
} else {
[88] Fix | Delete
options = options || {};
[89] Fix | Delete
options.data = _.extend( options.data || {}, { action: action });
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
options = _.defaults( options || {}, {
[93] Fix | Delete
type: 'POST',
[94] Fix | Delete
url: wp.ajax.settings.url,
[95] Fix | Delete
context: this
[96] Fix | Delete
});
[97] Fix | Delete
[98] Fix | Delete
deferred = $.Deferred( function( deferred ) {
[99] Fix | Delete
// Transfer success/error callbacks.
[100] Fix | Delete
if ( options.success ) {
[101] Fix | Delete
deferred.done( options.success );
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
if ( options.error ) {
[105] Fix | Delete
deferred.fail( options.error );
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
delete options.success;
[109] Fix | Delete
delete options.error;
[110] Fix | Delete
[111] Fix | Delete
// Use with PHP's wp_send_json_success() and wp_send_json_error().
[112] Fix | Delete
deferred.jqXHR = $.ajax( options ).done( function( response ) {
[113] Fix | Delete
// Treat a response of 1 as successful for backward compatibility with existing handlers.
[114] Fix | Delete
if ( response === '1' || response === 1 ) {
[115] Fix | Delete
response = { success: true };
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
if ( _.isObject( response ) && ! _.isUndefined( response.success ) ) {
[119] Fix | Delete
[120] Fix | Delete
// When handling a media attachments request, get the total attachments from response headers.
[121] Fix | Delete
var context = this;
[122] Fix | Delete
deferred.done( function() {
[123] Fix | Delete
if (
[124] Fix | Delete
action &&
[125] Fix | Delete
action.data &&
[126] Fix | Delete
'query-attachments' === action.data.action &&
[127] Fix | Delete
deferred.jqXHR.hasOwnProperty( 'getResponseHeader' ) &&
[128] Fix | Delete
deferred.jqXHR.getResponseHeader( 'X-WP-Total' )
[129] Fix | Delete
) {
[130] Fix | Delete
context.totalAttachments = parseInt( deferred.jqXHR.getResponseHeader( 'X-WP-Total' ), 10 );
[131] Fix | Delete
} else {
[132] Fix | Delete
context.totalAttachments = 0;
[133] Fix | Delete
}
[134] Fix | Delete
} );
[135] Fix | Delete
deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( this, [response.data] );
[136] Fix | Delete
} else {
[137] Fix | Delete
deferred.rejectWith( this, [response] );
[138] Fix | Delete
}
[139] Fix | Delete
}).fail( function() {
[140] Fix | Delete
deferred.rejectWith( this, arguments );
[141] Fix | Delete
});
[142] Fix | Delete
});
[143] Fix | Delete
[144] Fix | Delete
promise = deferred.promise();
[145] Fix | Delete
promise.abort = function() {
[146] Fix | Delete
deferred.jqXHR.abort();
[147] Fix | Delete
return this;
[148] Fix | Delete
};
[149] Fix | Delete
[150] Fix | Delete
return promise;
[151] Fix | Delete
}
[152] Fix | Delete
};
[153] Fix | Delete
[154] Fix | Delete
}(jQuery));
[155] Fix | Delete
[156] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function