Ticket #23216: 23216-small-heartbeat-changes.diff
File 23216-small-heartbeat-changes.diff, 3.5 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 shouldAutoStart = true, 45 hasActiveConnection = true; 44 46 45 this.autostart = true; 46 this.connectionLost = false; 47 /** 48 * If a value is specified, this function will set the internal value of the `shouldAutoStart` setting. Always 49 * returns the value of `shouldAutoStart` 50 * 51 * @param value 52 * @returns boolean 53 * @private 54 */ 55 self.shouldAutoStart = function( value ) { 56 if ( typeof value === 'boolean' ) { 57 return shouldAutoStart = value; 58 } 47 59 60 return shouldAutoStart; 61 }; 62 63 /** 64 * If a value is specified, this function will set the internal value of the `hasActiveConnection` setting. 65 * Always returns the value of `hasActiveConnection` 66 * 67 * @param value (optional) 68 * @returns boolean 69 * @private 70 */ 71 self.hasActiveConnection = function( value ) { 72 if ( typeof value === 'boolean' ) { 73 return hasActiveConnection = value; 74 } 75 76 return hasActiveConnection; 77 }; 78 48 79 if ( typeof( window.heartbeatSettings ) == 'object' ) { 49 80 settings = $.extend( {}, window.heartbeatSettings ); 50 81 … … 121 152 break; 122 153 } 123 154 124 if ( trigger && ! self.connectionLost) {125 self. connectionLost = true;155 if ( trigger && self.hasActiveConnection() === true ) { 156 self.hasActiveConnection( false ); 126 157 $(document).trigger( 'heartbeat-connection-lost', [error] ); 127 158 } 128 } else if ( self. connectionLost) {159 } else if ( self.hasActiveConnection() === false ) { 129 160 errorcount = 0; 130 self. connectionLost = false;161 self.hasActiveConnection( true ); 131 162 $(document).trigger( 'heartbeat-connection-restored' ); 132 163 } 133 164 } … … 152 183 153 184 // If nothing to send (nothing is expecting a response), 154 185 // schedule the next tick and bail 155 if ( empty && ! self.connectionLost) {186 if ( empty && self.hasActiveConnection() === true ) { 156 187 connecting = false; 157 188 next(); 158 189 return; … … 179 210 return errorstate( 'empty' ); 180 211 181 212 // Clear error state 182 if ( self. connectionLost)213 if ( self.hasActiveConnection() === false ) 183 214 errorstate(); 184 215 185 216 if ( response.nonces_expired ) { … … 205 236 errorstate( textStatus || 'unknown' ); 206 237 self.error( jqXHR, textStatus, error ); 207 238 }); 208 } ;239 } 209 240 210 241 function next() { 211 242 var delta = time() - tick, t = interval; … … 333 364 // Check for user activity every 30 seconds. 334 365 window.setInterval( function(){ checkUserActive(); }, 30000 ); 335 366 336 if ( this.autostart) {367 if ( self.shouldAutoStart() === true ) { 337 368 $(document).ready( function() { 338 369 // Start one tick (15 sec) after DOM ready 339 370 running = true; … … 344 375 345 376 this.hasFocus = function() { 346 377 return hasFocus; 347 } 378 }; 348 379 349 380 /** 350 381 * Get/Set the interval … … 420 451 errorstate(); 421 452 running = false; 422 453 return true; 423 } 454 }; 424 455 425 456 /** 426 457 * Enqueue data to send with the next XHR … … 447 478 return true; 448 479 } 449 480 return false; 450 } 481 }; 451 482 452 483 /** 453 484 * Check if data with a particular handle is queued … … 457 488 */ 458 489 this.isQueued = function( handle ) { 459 490 return queue[handle]; 460 } 461 } 491 }; 492 }; 462 493 463 494 $.extend( Heartbeat.prototype, { 464 495 tick: function( data, textStatus, jqXHR ) {