diff --git src/wp-admin/js/edit-comments.js src/wp-admin/js/edit-comments.js
index 0b0d0846bc..ff75b4b3e6 100644
|
|
setCommentsList = function() { |
288 | 288 | $('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside'); |
289 | 289 | |
290 | 290 | a.click(function( e ){ |
| 291 | |
| 292 | // Abort undo if there is an unfinished AJAX request involving the same comment. |
| 293 | if ( wpList.xhrs.inProgress( 'comment-' + id ) ) { |
| 294 | return false; |
| 295 | } |
291 | 296 | e.preventDefault(); |
292 | 297 | e.stopPropagation(); // ticket #35904 |
293 | 298 | list.wpList.del(this); |
diff --git src/wp-includes/js/wp-lists.js src/wp-includes/js/wp-lists.js
index c73471dbcb..9877c5baf6 100644
|
|
wpList = { |
187 | 187 | dimAfter: null |
188 | 188 | }, |
189 | 189 | |
| 190 | /** |
| 191 | * Track XHR connections. |
| 192 | * @type {Object} |
| 193 | */ |
| 194 | xhrs: wp.xhrs(), |
| 195 | |
190 | 196 | /** |
191 | 197 | * Finds a nonce. |
192 | 198 | * |
… |
… |
wpList = { |
384 | 390 | parsed: parsedResponse |
385 | 391 | }, settings ) ); |
386 | 392 | } |
| 393 | wpList.xhrs.clear(); |
387 | 394 | }; |
388 | 395 | |
389 | | $.ajax( settings ); |
| 396 | wpList.xhrs.setXhrs( settings.element, $.ajax( settings ) ); |
390 | 397 | |
391 | 398 | return false; |
392 | 399 | }, |
… |
… |
wpList = { |
410 | 417 | settings.element = data[2] || settings.element || null; |
411 | 418 | settings.delColor = data[3] ? '#' + data[3] : settings.delColor; |
412 | 419 | |
| 420 | // Return if there is already an AJAX request in progress involving the same element. |
| 421 | if ( wpList.xhrs.inProgress( settings.element ) ) { |
| 422 | return false; |
| 423 | } |
| 424 | |
413 | 425 | if ( ! settings || ! settings.element ) { |
414 | 426 | return false; |
415 | 427 | } |
… |
… |
wpList = { |
473 | 485 | } |
474 | 486 | }; |
475 | 487 | |
476 | | $.ajax( settings ); |
| 488 | wpList.xhrs.setXhrs( settings.element, $.ajax( settings ) ); |
477 | 489 | |
478 | 490 | return false; |
479 | 491 | }, |
… |
… |
wpList = { |
504 | 516 | settings.dimAddColor = data[4] ? '#' + data[4] : settings.dimAddColor; |
505 | 517 | settings.dimDelColor = data[5] ? '#' + data[5] : settings.dimDelColor; |
506 | 518 | |
| 519 | // Return if there is already an AJAX request in progress involving the same element. |
| 520 | if ( wpList.xhrs.inProgress( settings.element ) ) { |
| 521 | return false; |
| 522 | } |
| 523 | |
507 | 524 | if ( ! settings || ! settings.element || ! settings.dimClass ) { |
508 | 525 | return true; |
509 | 526 | } |
… |
… |
wpList = { |
587 | 604 | }; |
588 | 605 | |
589 | 606 | settings.complete = function( jqXHR, status ) { |
| 607 | |
| 608 | // Clear all finished AJAX requests from xhrs object. |
| 609 | wpList.xhrs.clear(); |
| 610 | |
590 | 611 | if ( $.isFunction( settings.dimAfter ) ) { |
591 | 612 | $eventTarget.queue( function() { |
592 | 613 | settings.dimAfter( returnedResponse, $.extend( { |
… |
… |
wpList = { |
598 | 619 | } |
599 | 620 | }; |
600 | 621 | |
601 | | $.ajax( settings ); |
| 622 | wpList.xhrs.setXhrs( settings.element, $.ajax( settings ) ); |
602 | 623 | |
603 | 624 | return false; |
604 | 625 | }, |
… |
… |
wpList = { |
836 | 857 | $.fn.wpList = function( settings ) { |
837 | 858 | this.each( function( index, list ) { |
838 | 859 | list.wpList = { |
839 | | settings: $.extend( {}, wpList.settings, { what: wpList.parseData( list, 'list' )[1] || '' }, settings ) |
| 860 | settings: $.extend( {}, wpList.settings, { what: wpList.parseData( list, 'list' )[1] || '' }, { xhrs: wpList.xhrs }, settings ) |
840 | 861 | }; |
841 | 862 | |
842 | 863 | $.each( functions, function( func, callback ) { |
diff --git src/wp-includes/js/xhrs.js src/wp-includes/js/xhrs.js
new file mode 100644
index 0000000000..744b4484b3
-
|
+
|
|
| 1 | ( function() { |
| 2 | var wp = window.wp || {}; |
| 3 | |
| 4 | /** |
| 5 | * Track XHR requests in progress. |
| 6 | */ |
| 7 | wp.xhrs = function() { |
| 8 | return { |
| 9 | xhrs: {}, |
| 10 | |
| 11 | // Clear all tracked xhrs. |
| 12 | clear: function() { |
| 13 | |
| 14 | // Clear all finished AJAX requests from xhrs object. |
| 15 | if ( 'undefined' !== typeof this.xhrs ) { |
| 16 | for ( var key in this.xhrs ) { |
| 17 | if ( 4 === this.xhrs[ key ].readyState ) { |
| 18 | delete this.xhrs[ key ]; |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | }, |
| 24 | |
| 25 | // Does the element in question have a request in progress? |
| 26 | inProgress: function( element ) { |
| 27 | return ( |
| 28 | this.xhrs && |
| 29 | 'undefined' !== typeof this.xhrs[ element ] && |
| 30 | 4 !== this.xhrs[ element ].readyState |
| 31 | ); |
| 32 | }, |
| 33 | |
| 34 | // Set up xhr record for an element. |
| 35 | setXhrs: function( element, xhr ) { |
| 36 | this.xhrs[ element ] = xhr; |
| 37 | } |
| 38 | } |
| 39 | }(); |
| 40 | } ) (); |
diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php
index 45cb46348d..8b866a94d3 100644
|
|
function wp_default_scripts( &$scripts ) { |
190 | 190 | ) |
191 | 191 | ); |
192 | 192 | |
193 | | $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array( 'wp-ajax-response', 'jquery-color' ), false, 1 ); |
| 193 | $scripts->add( 'xhrs', "/wp-includes/js/xhrs$suffix.js", array(), false, 1 ); |
| 194 | $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array( 'wp-ajax-response', 'jquery-color', 'xhrs' ), false, 1 ); |
194 | 195 | |
195 | 196 | // WordPress no longer uses or bundles Prototype or script.aculo.us. These are now pulled from an external source. |
196 | 197 | $scripts->add( 'prototype', 'https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1' ); |
… |
… |
function wp_default_scripts( &$scripts ) { |
693 | 694 | ) |
694 | 695 | ); |
695 | 696 | |
696 | | $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array( 'wp-lists', 'quicktags', 'jquery-query' ), false, 1 ); |
| 697 | $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array( 'wp-lists', 'quicktags', 'jquery-query', 'xhrs' ), false, 1 ); |
697 | 698 | did_action( 'init' ) && $scripts->localize( |
698 | 699 | 'admin-comments', 'adminCommentsL10n', array( |
699 | 700 | 'hotkeys_highlight_first' => isset( $_GET['hotkeys_highlight_first'] ), |