diff --git a/wp-includes/js/wp-util.js b/wp-includes/js/wp-util.js index 1985b35e6f..84cb5510bb 100644 --- a/wp-includes/js/wp-util.js +++ b/wp-includes/js/wp-util.js @@ -50,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({ @@ -65,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 { @@ -81,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 ); @@ -92,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 ) @@ -105,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; } }; diff --git a/wp-includes/js/wp-util.min.js b/wp-includes/js/wp-util.min.js index a74a80f8e5..18db8302e0 100644 --- a/wp-includes/js/wp-util.min.js +++ b/wp-includes/js/wp-util.min.js @@ -1 +1 @@ -window.wp=window.wp||{},function(a){var b="undefined"==typeof _wpUtilSettings?{}:_wpUtilSettings;wp.template=_.memoize(function(b){var c,d={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g,variable:"data"};return function(e){return(c=c||_.template(a("#tmpl-"+b).html(),null,d))(e)}}),wp.ajax={settings:b.ajax||{},post:function(a,b){return wp.ajax.send({data:_.isObject(a)?a:_.extend(b||{},{action:a})})},send:function(b,c){return _.isObject(b)?c=b:(c=c||{},c.data=_.extend(c.data||{},{action:b})),c=_.defaults(c||{},{type:"POST",url:wp.ajax.settings.url,context:this}),a.Deferred(function(b){c.success&&b.done(c.success),c.error&&b.fail(c.error),delete c.success,delete c.error,a.ajax(c).done(function(a){("1"===a||1===a)&&(a={success:!0}),_.isObject(a)&&!_.isUndefined(a.success)?b[a.success?"resolveWith":"rejectWith"](this,[a.data]):b.rejectWith(this,[a])}).fail(function(){b.rejectWith(this,arguments)})}).promise()}}}(jQuery); \ No newline at end of file +window.wp=window.wp||{},function(a){var b="undefined"==typeof _wpUtilSettings?{}:_wpUtilSettings;wp.template=_.memoize(function(b){var c,d={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g,variable:"data"};return function(e){return(c=c||_.template(a("#tmpl-"+b).html(),null,d))(e)}}),wp.ajax={settings:b.ajax||{},post:function(a,b){return wp.ajax.send({data:_.isObject(a)?a:_.extend(b||{},{action:a})})},send:function(b,c){var d,e;return _.isObject(b)?c=b:(c=c||{},c.data=_.extend(c.data||{},{action:b})),c=_.defaults(c||{},{type:"POST",url:wp.ajax.settings.url,context:this}),e=a.Deferred(function(b){c.success&&b.done(c.success),c.error&&b.fail(c.error),delete c.success,delete c.error,b.jqXHR=a.ajax(c).done(function(a){("1"===a||1===a)&&(a={success:!0}),_.isObject(a)&&!_.isUndefined(a.success)?b[a.success?"resolveWith":"rejectWith"](this,[a.data]):b.rejectWith(this,[a])}).fail(function(){b.rejectWith(this,arguments)})}),d=e.promise(),d.abort=function(){return e.jqXHR.abort(),this},d}}}(jQuery); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index c9739ad1a3..f395e143e1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.3-alpha-32746'; +$wp_version = '4.3-alpha-32747'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.