X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/256a3b381f63716209b3527d0a14442ae570c283..9441756a895fb4fdc4bcf20e0d228cef622663ca:/wp-includes/js/wp-util.js diff --git a/wp-includes/js/wp-util.js b/wp-includes/js/wp-util.js index 867d3a08..84cb5510 100644 --- a/wp-includes/js/wp-util.js +++ b/wp-includes/js/wp-util.js @@ -8,7 +8,7 @@ window.wp = window.wp || {}; /** * wp.template( id ) * - * Fetches a template by 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". @@ -16,6 +16,12 @@ window.wp = window.wp || {}; */ 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, @@ -44,7 +50,8 @@ window.wp = window.wp || {}; * * @param {string} action The slug of the action to fire in WordPress. * @param {object} data The data to populate $_POST with. - * @return {$.promise} A jQuery promise that represents the request. + * @return {$.promise} A jQuery promise that represents the request, + * decorated with an abort() method. */ post: function( action, data ) { return wp.ajax.send({ @@ -59,9 +66,11 @@ window.wp = window.wp || {}; * * @param {string} action The slug of the action to fire in WordPress. * @param {object} options The options passed to jQuery.ajax. - * @return {$.promise} A jQuery promise that represents the request. + * @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 { @@ -75,7 +84,7 @@ window.wp = window.wp || {}; context: this }); - return $.Deferred( function( deferred ) { + deferred = $.Deferred( function( deferred ) { // Transfer success/error callbacks. if ( options.success ) deferred.done( options.success ); @@ -86,7 +95,7 @@ window.wp = window.wp || {}; delete options.error; // Use with PHP's wp_send_json_success() and wp_send_json_error() - $.ajax( options ).done( function( response ) { + deferred.jqXHR = $.ajax( options ).done( function( response ) { // Treat a response of `1` as successful for backwards // compatibility with existing handlers. if ( response === '1' || response === 1 ) @@ -99,7 +108,15 @@ window.wp = window.wp || {}; }).fail( function() { deferred.rejectWith( this, arguments ); }); - }).promise(); + }); + + promise = deferred.promise(); + promise.abort = function() { + deferred.jqXHR.abort(); + return this; + }; + + return promise; } };