Make WordPress Core

Changeset 23886


Ignore:
Timestamp:
04/02/2013 10:51:09 PM (12 years ago)
Author:
azaozz
Message:

Autosave: use heartbeat to determine when connection is lost and disable the Save and Publish buttons. Re-enable the buttons when connection is restored. Props dh-shredder, see #23220

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r23868 r23886  
    366366<div id="message" class="updated"><p><?php echo $message; ?></p></div>
    367367<?php endif; ?>
     368<div id="lost-connection-notice" class="error hidden">
     369    <p><?php _e("You have lost your connection with the server, and saving has been disabled. This message will vanish once you've reconnected."); ?></p>
     370</div>
    368371<form name="post" action="post.php" method="post" id="post"<?php do_action('post_edit_form_tag'); ?>>
    369372<?php wp_nonce_field($nonce_action); ?>
  • trunk/wp-includes/js/autosave.js

    r23843 r23886  
    129129        });
    130130    }
     131
     132    // When connection is lost, keep user from submitting changes.
     133    $(document).on('heartbeat-connection-lost.autosave', function() {
     134        autosave_disable_buttons();
     135        $('#lost-connection-notice').show();
     136    }).on('heartbeat-connection-restored.autosave', function() {
     137        autosave_enable_buttons();
     138        $('#lost-connection-notice').hide();
     139    });
    131140});
    132141
     
    219228
    220229function autosave_enable_buttons() {
    221     // delay that a bit to avoid some rare collisions while the DOM is being updated.
    222     setTimeout(function(){
    223         jQuery(':button, :submit', '#submitpost').removeAttr('disabled');
    224         jQuery('.spinner', '#submitpost').hide();
    225     }, 500);
     230    if ( ! wp.heartbeat.connectionLost ) {
     231        // delay that a bit to avoid some rare collisions while the DOM is being updated.
     232        setTimeout(function(){
     233            var parent = jQuery('#submitpost');
     234            parent.find(':button, :submit').removeAttr('disabled');
     235            parent.find('.spinner').hide();
     236        }, 500);
     237    }
    226238}
    227239
    228240function autosave_disable_buttons() {
    229     jQuery(':button, :submit', '#submitpost').prop('disabled', true);
     241    jQuery('#submitpost').find(':button, :submit').prop('disabled', true);
    230242    // Re-enable 5 sec later. Just gives autosave a head start to avoid collisions.
    231     setTimeout(autosave_enable_buttons, 5000);
     243    setTimeout( autosave_enable_buttons, 5000 );
    232244}
    233245
     
    246258        post_data, doAutoSave, ed, origStatus, successCallback;
    247259
     260    // Disable buttons until we know the save completed.
    248261    autosave_disable_buttons();
    249262
  • trunk/wp-includes/js/heartbeat.js

    r23882 r23886  
    384384                self.xhr.abort();
    385385
     386            // Reset the error state
     387            errorstate();
    386388            running = false;
    387389            return true;
Note: See TracChangeset for help on using the changeset viewer.