Have heartbeat's connection lost notice handle 503 errors send by the upgrader's maintenance mode.

fixes #25660 for 3.7.


git-svn-id: https://develop.svn.wordpress.org/trunk@25874 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2013-10-22 21:26:04 +00:00
parent ff69fb4b8f
commit 46302236ae
2 changed files with 13 additions and 7 deletions

View File

@ -141,8 +141,8 @@ jQuery(document).ready( function($) {
}
// When connection is lost, keep user from submitting changes.
$(document).on('heartbeat-connection-lost.autosave', function( e, error ) {
if ( 'timeout' === error ) {
$(document).on('heartbeat-connection-lost.autosave', function( e, error, status ) {
if ( 'timeout' === error || 503 == status ) {
var notice = $('#lost-connection-notice');
if ( ! wp.autosave.local.hasStorage ) {
notice.find('.hide-if-no-sessionstorage').hide();

View File

@ -45,7 +45,7 @@ window.wp = window.wp || {};
userActiveEvents,
winBlurTimeout,
frameBlurTimeout = -1,
hasConnectionError = false;
hasConnectionError = null;
/**
* Returns a boolean that's indicative of whether or not there is a connection error
@ -53,7 +53,7 @@ window.wp = window.wp || {};
* @returns boolean
*/
this.hasConnectionError = function() {
return hasConnectionError;
return !! hasConnectionError;
};
if ( typeof( window.heartbeatSettings ) == 'object' ) {
@ -108,7 +108,7 @@ window.wp = window.wp || {};
}
// Set error state and fire an event on XHR errors or timeout
function errorstate( error ) {
function errorstate( error, status ) {
var trigger;
if ( error ) {
@ -132,14 +132,20 @@ window.wp = window.wp || {};
break;
}
if ( 503 == status && false === hasConnectionError ) {
trigger = true;
}
if ( trigger && ! self.hasConnectionError() ) {
hasConnectionError = true;
$(document).trigger( 'heartbeat-connection-lost', [error] );
$(document).trigger( 'heartbeat-connection-lost', [error, status] );
}
} else if ( self.hasConnectionError() ) {
errorcount = 0;
hasConnectionError = false;
$(document).trigger( 'heartbeat-connection-restored' );
} else if ( null === hasConnectionError ) {
hasConnectionError = false;
}
}
@ -213,7 +219,7 @@ window.wp = window.wp || {};
connecting = false;
next();
}).fail( function( jqXHR, textStatus, error ) {
errorstate( textStatus || 'unknown' );
errorstate( textStatus || 'unknown', jqXHR.status );
self.error( jqXHR, textStatus, error );
});
}