diff --git a/src/js/_enqueues/admin/inline-edit-post.js b/src/js/_enqueues/admin/inline-edit-post.js index 36ffaf18ef778..698636fb039cd 100644 --- a/src/js/_enqueues/admin/inline-edit-post.js +++ b/src/js/_enqueues/admin/inline-edit-post.js @@ -20,12 +20,20 @@ window.wp = window.wp || {}; * * @property {string} type The type of inline editor. * @property {string} what The prefix before the post ID. + * @property {boolean} saving Whether a save request is active. * */ ( function( $, wp ) { window.inlineEditPost = { + /** + * Whether a save request is active. + * + * @type {boolean} + */ + saving: false, + /** * Initializes the inline and bulk post editor. * @@ -488,6 +496,11 @@ window.wp = window.wp || {}; save : function(id) { var params, fields, page = $('.post_status_page').val() || ''; + if ( this.saving ) { + return false; + } + this.saving = true; + if ( typeof(id) === 'object' ) { id = this.getId(id); } @@ -536,7 +549,10 @@ window.wp = window.wp || {}; wp.a11y.speak( wp.i18n.__( 'Error while saving the changes.' ) ); } }, - 'html'); + 'html' + ).always( function() { + inlineEditPost.saving = false; + } ); // Prevent submitting the form when pressing Enter on a focused field. return false; diff --git a/src/js/_enqueues/admin/inline-edit-tax.js b/src/js/_enqueues/admin/inline-edit-tax.js index 86e3498cd1eac..ddc91b49036ef 100644 --- a/src/js/_enqueues/admin/inline-edit-tax.js +++ b/src/js/_enqueues/admin/inline-edit-tax.js @@ -20,6 +20,12 @@ window.wp = window.wp || {}; ( function( $, wp ) { window.inlineEditTax = { + /** + * Whether a save request is active. + * + * @type {boolean} + */ + saving: false, /** * Initializes the inline taxonomy editor by adding event handlers to be able to @@ -167,6 +173,11 @@ window.inlineEditTax = { save : function(id) { var params, fields, tax = $('input[name="taxonomy"]').val() || ''; + if ( this.saving ) { + return false; + } + this.saving = true; + // Makes sure we can pass an HTMLElement as the ID. if( typeof(id) === 'object' ) { id = this.getId(id); @@ -242,7 +253,9 @@ window.inlineEditTax = { wp.a11y.speak( wp.i18n.__( 'Error while saving the changes.' ) ); } } - ); + ).always( function() { + inlineEditTax.saving = false; + } ); // Prevent submitting the form when pressing Enter on a focused field. return false; diff --git a/tests/qunit/index.html b/tests/qunit/index.html index d0e81acedb502..6dee28ce4b62d 100644 --- a/tests/qunit/index.html +++ b/tests/qunit/index.html @@ -76,6 +76,7 @@