Ticket #25073: 25073.2.patch
File 25073.2.patch, 4.8 KB (added by , 11 years ago) |
---|
-
wp-includes/js/heartbeat.js
29 29 var Heartbeat = function() { 30 30 var self = this, 31 31 running, 32 beat ,32 beatTimeout, 33 33 screenId = typeof pagenow != 'undefined' ? pagenow : '', 34 34 url = typeof ajaxurl != 'undefined' ? ajaxurl : '', 35 35 settings, … … 146 146 function connect() { 147 147 var send = {}, data, i, empty = true, 148 148 nonce = typeof window.heartbeatSettings == 'object' ? window.heartbeatSettings.nonce : ''; 149 150 // If the connection to the server is slower than the interval, 151 // heartbeat connects as soon as the previous connection's response is received. 152 if ( connecting ) { 153 return; 154 } 155 149 156 tick = time(); 150 157 151 158 data = $.extend( {}, queue ); … … 164 171 // If nothing to send (nothing is expecting a response), 165 172 // schedule the next tick and bail 166 173 if ( empty && ! self.hasConnectionError() ) { 167 connecting = false;168 174 next(); 169 175 return; 170 176 } … … 183 189 timeout: 30000, // throw an error if not completed after 30 sec. 184 190 data: send, 185 191 dataType: 'json' 192 }).always( function() { 193 connecting = false; 194 next(); 186 195 }).done( function( response, textStatus, jqXHR ) { 187 196 var new_interval; 188 197 … … 209 218 // do this last, can trigger the next XHR if connection time > 5 sec. and new_interval == 'fast' 210 219 if ( new_interval ) 211 220 self.interval.call( self, new_interval ); 212 }).always( function() {213 connecting = false;214 next();215 221 }).fail( function( jqXHR, textStatus, error ) { 216 222 errorstate( textStatus || 'unknown' ); 217 223 self.error( jqXHR, textStatus, error ); … … 231 237 countdown--; 232 238 } 233 239 234 window.clearTimeout( beat);240 window.clearTimeout( beatTimeout ); 235 241 236 242 if ( delta < t ) { 237 beat = window.setTimeout(243 beatTimeout = window.setTimeout( 238 244 function(){ 239 245 if ( running ) 240 246 connect(); … … 265 271 return; 266 272 267 273 hasFocus = true; 268 window.clearTimeout(beat); 269 270 if ( ! connecting ) 271 next(); 274 next(); 272 275 } 273 276 274 277 function setFrameEvents() { … … 290 293 }); 291 294 } 292 295 293 $(window).on( 'blur.wp-heartbeat-focus', function(e) {294 setFrameEvents();295 winBlurTimeout = window.setTimeout( function(){ blurred(); }, 500 );296 }).on( 'focus.wp-heartbeat-focus', function() {297 $('iframe').each( function( i, frame ) {298 if ( !isLocalFrame( frame ) )299 return;300 301 $.removeData( frame, 'wp-heartbeat-focus' );302 $( frame.contentWindow ).off( '.wp-heartbeat-focus' );303 });304 305 focused();306 });307 308 296 function userIsActive() { 309 297 userActiveEvents = false; 310 298 $(document).off( '.wp-heartbeat-active' ); … … 341 329 } 342 330 } 343 331 332 $(window).on( 'blur.wp-heartbeat-focus', function(e) { 333 setFrameEvents(); 334 winBlurTimeout = window.setTimeout( function(){ blurred(); }, 500 ); 335 }).on( 'focus.wp-heartbeat-focus', function() { 336 $('iframe').each( function( i, frame ) { 337 if ( !isLocalFrame( frame ) ) 338 return; 339 340 $.removeData( frame, 'wp-heartbeat-focus' ); 341 $( frame.contentWindow ).off( '.wp-heartbeat-focus' ); 342 }); 343 344 focused(); 345 }).on( 'unload.wp-heartbeat', function() { 346 // Don't connect any more 347 running = false; 348 }); 349 344 350 // Check for user activity every 30 seconds. 345 351 window.setInterval( function(){ checkUserActive(); }, 30000 ); 346 352 $(document).ready( function() { … … 355 361 }; 356 362 357 363 /** 364 * Connect asap regardless of 'hasFocus'. Will not open two concurrent connections. 365 * If a connection is in progress, will connect again immediately after the current connection completes. 366 * 367 */ 368 this.connectNow = function() { 369 tick = 0; 370 next(); 371 }; 372 373 /** 358 374 * Get/Set the interval 359 375 * 360 376 * When setting to 'fast', the interval is 5 sec. for the next 30 ticks (for 2 min and 30 sec). … … 365 381 * @return int Current interval in seconds 366 382 */ 367 383 this.interval = function( speed, ticks ) { 368 var reset, seconds; 384 var seconds, oldInerval = interval; 385 369 386 ticks = parseInt( ticks, 10 ) || 30; 370 387 ticks = ticks < 1 || ticks > 30 ? 30 : ticks; 371 388 … … 389 406 countdown = 0; 390 407 } 391 408 392 // Reset when the new interval value is lower than the current one393 reset = seconds * 1000 < interval;394 395 409 if ( countdown > 0 ) { 396 410 tempInterval = seconds * 1000; 397 411 } else { … … 399 413 tempInterval = 0; 400 414 } 401 415 402 if ( reset ) 416 // Change the next connection time if the new interval is different 417 if ( seconds * 1000 != oldInerval ) { 418 tick = tick - ( oldInerval - seconds * 1000 ); 403 419 next(); 420 } 404 421 } 405 422 406 423 if ( ! hasFocus ) 407 return 1 20;424 return 100; 408 425 409 426 return tempInterval ? tempInterval / 1000 : interval / 1000; 410 427 };