WordPress.org

Make WordPress Core

Ticket #23220: disable_save_while_disconnected.3.diff

File disable_save_while_disconnected.3.diff, 3.1 KB (added by dh-shredder, 9 years ago)

Simplified code per @azaozz's suggestions.

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

    diff --git wp-admin/edit-form-advanced.php wp-admin/edit-form-advanced.php
    index c7e8dc6..8af539c 100644
    wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); 
    336336wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
    337337?>
    338338
     339<div id="lost-connection-notice" class="error hidden">
     340        <p id="lost-connection-message">
     341        <?php _e("You have lost your connection with the server, and saving has been disabled. This message will vanish once you've reconnected."); ?>
     342        </p>
     343</div>
     344
    339345<div id="poststuff">
    340346
    341347<?php
  • wp-includes/js/autosave.js

    diff --git wp-includes/js/autosave.js wp-includes/js/autosave.js
    index 43b2b4e..8658f23 100644
    function autosave_loading() { 
    212212}
    213213
    214214function autosave_enable_buttons() {
    215         // delay that a bit to avoid some rare collisions while the DOM is being updated.
    216         setTimeout(function(){
    217                 jQuery(':button, :submit', '#submitpost').removeAttr('disabled');
    218                 jQuery('.spinner', '#submitpost').hide();
    219         }, 500);
     215        if ( ! wp.heartbeat.connectionLost ) {
     216                // delay that a bit to avoid some rare collisions while the DOM is being updated.
     217                setTimeout(function(){
     218                        jQuery(':button, :submit', '#submitpost').removeAttr('disabled');
     219                        jQuery('.spinner', '#submitpost').hide();
     220                }, 500);
     221        }
    220222}
    221223
    222224function autosave_disable_buttons() {
    autosave = function() { 
    239241        var rich = (typeof tinymce != "undefined") && tinymce.activeEditor && !tinymce.activeEditor.isHidden(),
    240242                post_data, doAutoSave, ed, origStatus, successCallback;
    241243
     244        // Disable buttons until we know the save completed.
    242245        autosave_disable_buttons();
    243246
    244247        post_data = wp.autosave.getPostData();
    wp.autosave.local = { 
    664667wp.autosave.local.init();
    665668
    666669}(jQuery));
     670
     671
     672// When connection is lost, keep user from submitting changes.
     673jQuery(document).on('heartbeat-connection-lost', function() {
     674        autosave_disable_buttons();
     675        jQuery('#lost-connection-notice').show();
     676});
     677
     678// When connection returns, make work all the things.
     679jQuery(document).on('heartbeat-connection-restored', function() {
     680        autosave_enable_buttons();
     681        jQuery('#lost-connection-notice').hide();
     682});
  • 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() {