Make WordPress Core

Ticket #35501: 35501.7.patch

File 35501.7.patch, 3.8 KB (added by adamsilverstein, 6 years ago)
  • src/wp-admin/js/edit-comments.js

    diff --git src/wp-admin/js/edit-comments.js src/wp-admin/js/edit-comments.js
    index b9a9f2cf85..35938d5961 100644
    setCommentsList = function() { 
    288288                        $('.avatar', el).first().clone().prependTo('#undo-' + id + ' .' + action + '-undo-inside');
    289289
    290290                        a.click(function( e ){
     291
     292                                // Abort undo if there is an unfinished AJAX request involving the same comment.
     293                                if ( settings.xhrs && 'undefined' !== typeof settings.xhrs['comment-' + id] && 4 !== settings.xhrs['comment-' + id].readyState ) {
     294                                        return false;
     295                                }
    291296                                e.preventDefault();
    292297                                e.stopPropagation(); // ticket #35904
    293298                                list.wpList.del(this);
  • src/wp-includes/js/wp-lists.js

    diff --git src/wp-includes/js/wp-lists.js src/wp-includes/js/wp-lists.js
    index c73471dbcb..33282196ed 100644
    wpList = { 
    184184                 *                                  'timeout', 'abort', or 'parsererror'.
    185185                 * @param {object} settings.parsed  Parsed response object.
    186186                 */
    187                 dimAfter: null
     187                dimAfter: null,
     188
     189                /**
     190                 * Track XHR connections.
     191                 * @type {Object}
     192                 */
     193                xhrs: {}
    188194        },
    189195
    190196        /**
    wpList = { 
    404410                        data     = wpList.parseData( $element, 'delete' ),
    405411                        $eventTarget, parsedResponse, returnedResponse;
    406412
     413                // Clear all finished AJAX requests from xhrs object.
     414                if ( 'undefined' !== typeof wpList.xhrs ) {
     415                        for ( var key in wpList.xhrs ) {
     416                                if ( 4 === wpList.xhrs[ key ].readyState ) {
     417                                        delete wpList.xhrs[ key ];
     418                                }
     419                        }
     420                }
     421
     422
    407423                settings = settings || {};
    408424                settings = wpList.pre.call( list, $element, settings, 'delete' );
    409425
    410426                settings.element  = data[2] || settings.element || null;
    411427                settings.delColor = data[3] ? '#' + data[3] : settings.delColor;
    412428
     429                // Return if there is already an AJAX request in progress involving the same element.
     430                if ( wpList.xhrs && 'undefined' !== typeof wpList.xhrs[ s.element ] && 4 !== wpList.xhrs[ s.element ].readyState ) {
     431                        return false;
     432                }
     433
    413434                if ( ! settings || ! settings.element ) {
    414435                        return false;
    415436                }
    wpList = { 
    473494                        }
    474495                };
    475496
    476                 $.ajax( settings );
     497                wpList.xhrs = wpList.xhrs || {};
     498                wpList.xhrs[ s.element ] = $.ajax( settings );
    477499
    478500                return false;
    479501        },
    wpList = { 
    504526                settings.dimAddColor = data[4] ? '#' + data[4] : settings.dimAddColor;
    505527                settings.dimDelColor = data[5] ? '#' + data[5] : settings.dimDelColor;
    506528
     529                // Return if there is already an AJAX request in progress involving the same element.
     530                if ( wpList.xhrs && 'undefined' !== typeof wpList.xhrs[ s.element ] && 4 !== wpList.xhrs[ s.element ].readyState ) {
     531                        return false;
     532                }
     533
    507534                if ( ! settings || ! settings.element || ! settings.dimClass ) {
    508535                        return true;
    509536                }
    wpList = { 
    587614                };
    588615
    589616                settings.complete = function( jqXHR, status ) {
     617
     618                        // Clear all finished AJAX requests from xhrs object.
     619                        if ( 'undefined' !== typeof wpList.xhrs ) {
     620                                for ( var key in wpList.xhrs ) {
     621                                        if ( 4 === wpList.xhrs[ key ].readyState ) {
     622                                                delete wpList.xhrs[ key ];
     623                                        }
     624                                }
     625                        }
     626
    590627                        if ( $.isFunction( settings.dimAfter ) ) {
    591628                                $eventTarget.queue( function() {
    592629                                        settings.dimAfter( returnedResponse, $.extend( {
    wpList = { 
    598635                        }
    599636                };
    600637
    601                 $.ajax( settings );
     638                wpList.xhrs = wpList.xhrs || {};
     639                wpList.xhrs[ s.element ] = $.ajax( settings );
    602640
    603641                return false;
    604642        },
    wpList = { 
    836874$.fn.wpList = function( settings ) {
    837875        this.each( function( index, list ) {
    838876                list.wpList = {
    839                         settings: $.extend( {}, wpList.settings, { what: wpList.parseData( list, 'list' )[1] || '' }, settings )
     877                        settings: $.extend( {}, wpList.settings, { what: wpList.parseData( list, 'list' )[1] || '' }, { xhrs: wpList.xhrs }, settings )
    840878                };
    841879
    842880                $.each( functions, function( func, callback ) {