WordPress.org

Make WordPress Core

Ticket #23220: disable_save_while_disconnected.2.diff

File disable_save_while_disconnected.2.diff, 3.6 KB (added by dh-shredder, 13 months ago)

Only disabling buttons during after autosave if wp.heartbeat.connectionLost

  • wp-admin/edit-form-advanced.php

    diff --git wp-admin/edit-form-advanced.php wp-admin/edit-form-advanced.php
    index 6df9234..770c851 100644
    wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); 
    329329wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); 
    330330?> 
    331331 
     332<div id="lost-connection-notice" class="error hidden"> 
     333        <p id="lost-connection-message"> 
     334        <?php _e("You have lost your connection with the server, and saving has been disabled. This message will vanish once you've reconnected."); ?> 
     335        </p> 
     336</div> 
     337 
    332338<div id="poststuff"> 
    333339 
    334340<?php 
  • wp-includes/js/autosave.js

    diff --git wp-includes/js/autosave.js wp-includes/js/autosave.js
    index d1914d1..5e1c3f1 100644
    function autosave_parse_response(response) { 
    180180function autosave_saved(response) { 
    181181        blockSave = false; 
    182182        autosave_parse_response(response); // parse the ajax response 
    183         autosave_enable_buttons(); // re-enable disabled form buttons 
     183 
     184        if ( ! wp.heartbeat.connectionLost ) 
     185                autosave_enable_buttons(); // re-enable disabled form buttons 
    184186} 
    185187 
    186188// called when autosaving new post 
    function autosave_saved_new(response) { 
    200202                        autosaveDelayPreview = false; 
    201203                        doPreview(); 
    202204                } 
    203         } else { 
     205        } else if ( ! wp.heartbeat.connectionLost ) { 
    204206                autosave_enable_buttons(); // re-enable disabled form buttons 
    205207        } 
    206208} 
    function autosave_enable_buttons() { 
    238240 
    239241function autosave_disable_buttons() { 
    240242        jQuery(':button, :submit', '#submitpost').prop('disabled', true); 
    241         // Re-enable 5 sec later. Just gives autosave a head start to avoid collisions. 
    242         setTimeout(autosave_enable_buttons, 5000); 
     243 
     244        if ( ! wp.heartbeat.connectionLost ) { 
     245                // Re-enable 5 sec later. Just gives autosave a head start to avoid collisions. 
     246                setTimeout(autosave_enable_buttons, 5000); 
     247        } 
    243248} 
    244249 
    245250function delayed_autosave() { 
    autosave = function() { 
    256261        var rich = (typeof tinymce != "undefined") && tinymce.activeEditor && !tinymce.activeEditor.isHidden(), 
    257262                post_data, doAutoSave, ed, origStatus, successCallback; 
    258263 
     264        // Disable buttons until we know the save completed. 
    259265        autosave_disable_buttons(); 
    260266 
    261267        post_data = wp.autosave.getPostData(); 
    wp.autosave.local = { 
    668674wp.autosave.local.init(); 
    669675 
    670676}(jQuery)); 
     677 
     678 
     679// When connection is lost, keep user from submitting changes. 
     680jQuery(document).on('heartbeat-connection-lost', function() { 
     681        autosave_disable_buttons(); 
     682        jQuery('#lost-connection-notice').show(); 
     683}); 
     684 
     685// When connection returns, make work all the things. 
     686jQuery(document).on('heartbeat-connection-restored', function() { 
     687        autosave_enable_buttons(); 
     688        jQuery('#lost-connection-notice').hide(); 
     689}); 
  • wp-includes/js/heartbeat.js

    diff --git wp-includes/js/heartbeat.js wp-includes/js/heartbeat.js
    index a382599..1060786 100644
    window.wp = window.wp || {}; 
    2828 
    2929                this.url = typeof ajaxurl != 'undefined' ? ajaxurl : 'wp-admin/admin-ajax.php'; 
    3030                this.autostart = true; 
     31                this.connectionLost = false; 
    3132 
    3233                if ( typeof( window.heartbeatSettings != 'undefined' ) ) { 
    3334                        settings = $.extend( {}, window.heartbeatSettings ); 
    window.wp = window.wp || {}; 
    171172 
    172173                        // temp debug 
    173174                        if ( self.debug ) 
    174                                 console.log('### blurred(), slow down...') 
     175                                console.log('### blurred(), slow down...'); 
    175176                } 
    176177 
    177178                function focused() { 
    window.wp = window.wp || {}; 
    192193 
    193194                        // temp debug 
    194195                        if ( self.debug ) 
    195                                 console.log('### focused(), speed up... ') 
     196                                console.log('### focused(), speed up... '); 
    196197                } 
    197198 
    198199                function setFrameEvents() {