Ticket #23216: 23216-small-heartbeat-changes.4.diff
File 23216-small-heartbeat-changes.4.diff, 3.9 KB (added by , 11 years ago) |
---|
-
wp-includes/js/heartbeat.js
40 40 isUserActive, 41 41 userActiveEvents, 42 42 winBlurTimeout, 43 frameBlurTimeout = -1; 43 frameBlurTimeout = -1, 44 hasConnectionError = false; 44 45 45 this.autostart = true; 46 this.connectionLost = false; 46 /** 47 * Returns a boolean that's indicative of whether or not there is a connection error 48 * 49 * @returns boolean 50 * @private 51 */ 52 this.hasConnectionError = function() { 53 return hasConnectionError; 54 }; 47 55 48 56 if ( typeof( window.heartbeatSettings ) == 'object' ) { 49 57 settings = $.extend( {}, window.heartbeatSettings ); … … 121 129 break; 122 130 } 123 131 124 if ( trigger && ! self. connectionLost) {125 self.connectionLost= true;132 if ( trigger && ! self.hasConnectionError() ) { 133 hasConnectionError = true; 126 134 $(document).trigger( 'heartbeat-connection-lost', [error] ); 127 135 } 128 } else if ( self. connectionLost) {136 } else if ( self.hasConnectionError() ) { 129 137 errorcount = 0; 130 self.connectionLost= false;138 hasConnectionError = false; 131 139 $(document).trigger( 'heartbeat-connection-restored' ); 132 140 } 133 141 } … … 152 160 153 161 // If nothing to send (nothing is expecting a response), 154 162 // schedule the next tick and bail 155 if ( empty && ! self. connectionLost) {163 if ( empty && ! self.hasConnectionError() ) { 156 164 connecting = false; 157 165 next(); 158 166 return; … … 179 187 return errorstate( 'empty' ); 180 188 181 189 // Clear error state 182 if ( self. connectionLost)190 if ( self.hasConnectionError() ) 183 191 errorstate(); 184 192 185 193 if ( response.nonces_expired ) { … … 205 213 errorstate( textStatus || 'unknown' ); 206 214 self.error( jqXHR, textStatus, error ); 207 215 }); 208 } ;216 } 209 217 210 218 function next() { 211 219 var delta = time() - tick, t = interval; … … 332 340 333 341 // Check for user activity every 30 seconds. 334 342 window.setInterval( function(){ checkUserActive(); }, 30000 ); 343 $(document).ready( function() { 344 // Start one tick (15 sec) after DOM ready 345 running = true; 346 tick = time(); 347 next(); 348 }); 335 349 336 if ( this.autostart ) {337 $(document).ready( function() {338 // Start one tick (15 sec) after DOM ready339 running = true;340 tick = time();341 next();342 });343 }344 345 350 this.hasFocus = function() { 346 351 return hasFocus; 347 } 352 }; 348 353 349 354 /** 350 355 * Get/Set the interval … … 401 406 return tempInterval ? tempInterval / 1000 : interval / 1000; 402 407 }; 403 408 404 // Start. Has no effect if heartbeat is already running405 this.start = function() {406 if ( running )407 return false;408 409 running = true;410 connect();411 return true;412 };413 414 // Stop. If a XHR is in progress, abort it415 this.stop = function() {416 if ( self.xhr && self.xhr.readyState != 4 )417 self.xhr.abort();418 419 // Reset the error state420 errorstate();421 running = false;422 return true;423 }424 425 409 /** 426 410 * Enqueue data to send with the next XHR 427 411 * … … 447 431 return true; 448 432 } 449 433 return false; 450 } 434 }; 451 435 452 436 /** 453 437 * Check if data with a particular handle is queued … … 457 441 */ 458 442 this.isQueued = function( handle ) { 459 443 return queue[handle]; 460 } 461 } 444 }; 445 }; 462 446 463 447 $.extend( Heartbeat.prototype, { 464 448 tick: function( data, textStatus, jqXHR ) { -
wp-includes/js/autosave.js
242 242 243 243 function autosave_enable_buttons() { 244 244 jQuery(document).trigger('autosave-enable-buttons'); 245 if ( ! wp.heartbeat. connectionLost) {245 if ( ! wp.heartbeat.hasConnectionError() ) { 246 246 // delay that a bit to avoid some rare collisions while the DOM is being updated. 247 247 setTimeout(function(){ 248 248 var parent = jQuery('#submitpost');