diff --git src/wp-includes/js/heartbeat.js src/wp-includes/js/heartbeat.js
index 9db2162ab..0f93ff36d 100644
|
|
|
|
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | 29 | ( function( $, window, undefined ) { |
| 30 | | |
| 31 | | /** |
| 32 | | * Constructs the Heartbeat API. |
| 33 | | * |
| 34 | | * @since 3.6.0 |
| 35 | | * |
| 36 | | * @returns {Object} An instance of the Heartbeat class. |
| 37 | | * @constructor |
| 38 | | */ |
| 39 | 30 | var Heartbeat = function() { |
| 40 | 31 | var $document = $(document), |
| 41 | 32 | settings = { |
| 42 | | // Suspend/resume. |
| | 33 | // Suspend/resume |
| 43 | 34 | suspend: false, |
| 44 | 35 | |
| 45 | | // Whether suspending is enabled. |
| | 36 | // Whether suspending is enabled |
| 46 | 37 | suspendEnabled: true, |
| 47 | 38 | |
| 48 | | // Current screen id, defaults to the JS global 'pagenow' when present (in the admin) or 'front'. |
| | 39 | // Current screen id, defaults to the JS global 'pagenow' when present (in the admin) or 'front' |
| 49 | 40 | screenId: '', |
| 50 | 41 | |
| 51 | | // XHR request URL, defaults to the JS global 'ajaxurl' when present. |
| | 42 | // XHR request URL, defaults to the JS global 'ajaxurl' when present |
| 52 | 43 | url: '', |
| 53 | 44 | |
| 54 | | // Timestamp, start of the last connection request. |
| | 45 | // Timestamp, start of the last connection request |
| 55 | 46 | lastTick: 0, |
| 56 | 47 | |
| 57 | | // Container for the enqueued items. |
| | 48 | // Container for the enqueued items |
| 58 | 49 | queue: {}, |
| 59 | 50 | |
| 60 | | // Connect interval (in seconds). |
| | 51 | // Connect interval (in seconds) |
| 61 | 52 | mainInterval: 60, |
| 62 | 53 | |
| 63 | | // Used when the interval is set to 5 sec. temporarily. |
| | 54 | // Used when the interval is set to 5 sec. temporarily |
| 64 | 55 | tempInterval: 0, |
| 65 | 56 | |
| 66 | | // Used when the interval is reset. |
| | 57 | // Used when the interval is reset |
| 67 | 58 | originalInterval: 0, |
| 68 | 59 | |
| 69 | 60 | // Used to limit the number of AJAX requests. |
| 70 | 61 | minimalInterval: 0, |
| 71 | 62 | |
| 72 | | // Used together with tempInterval. |
| | 63 | // Used together with tempInterval |
| 73 | 64 | countdown: 0, |
| 74 | 65 | |
| 75 | | // Whether a connection is currently in progress. |
| | 66 | // Whether a connection is currently in progress |
| 76 | 67 | connecting: false, |
| 77 | 68 | |
| 78 | | // Whether a connection error occurred. |
| | 69 | // Whether a connection error occurred |
| 79 | 70 | connectionError: false, |
| 80 | 71 | |
| 81 | | // Used to track non-critical errors. |
| | 72 | // Used to track non-critical errors |
| 82 | 73 | errorcount: 0, |
| 83 | 74 | |
| 84 | | // Whether at least one connection has been completed successfully. |
| | 75 | // Whether at least one connection has completed successfully |
| 85 | 76 | hasConnected: false, |
| 86 | 77 | |
| 87 | | // Whether the current browser window is in focus and the user is active. |
| | 78 | // Whether the current browser window is in focus and the user is active |
| 88 | 79 | hasFocus: true, |
| 89 | 80 | |
| 90 | 81 | // Timestamp, last time the user was active. Checked every 30 sec. |
| 91 | 82 | userActivity: 0, |
| 92 | 83 | |
| 93 | | // Flag whether events tracking user activity were set. |
| | 84 | // Flags whether events tracking user activity were set |
| 94 | 85 | userActivityEvents: false, |
| 95 | 86 | |
| 96 | | // Timer that keeps track of how long a user has focus. |
| 97 | 87 | checkFocusTimer: 0, |
| 98 | | |
| 99 | | // Timer that keeps track of how long needs to be waited before connecting to the server again. |
| 100 | 88 | beatTimer: 0 |
| 101 | 89 | }; |
| 102 | 90 | |
| 103 | 91 | /** |
| 104 | | * Sets the necessary variables and events before starting the actual heartbeat. |
| 105 | | * |
| 106 | | * @summary Sets local variables and events, then starts the heartbeat. |
| | 92 | * Set local vars and events, then start |
| 107 | 93 | * |
| 108 | 94 | * @access private |
| 109 | 95 | * |
| 110 | | * @since 3.8.0 |
| 111 | | * |
| 112 | | * @returns { void } |
| | 96 | * @return void |
| 113 | 97 | */ |
| 114 | 98 | function initialize() { |
| 115 | 99 | var options, hidden, visibilityState, visibilitychange; |
| … |
… |
|
| 122 | 106 | settings.url = window.ajaxurl; |
| 123 | 107 | } |
| 124 | 108 | |
| 125 | | // Pull in options passed from PHP. |
| | 109 | // Pull in options passed from PHP |
| 126 | 110 | if ( typeof window.heartbeatSettings === 'object' ) { |
| 127 | 111 | options = window.heartbeatSettings; |
| 128 | 112 | |
| 129 | | // The XHR URL can be passed as option when window.ajaxurl is not set. |
| | 113 | // The XHR URL can be passed as option when window.ajaxurl is not set |
| 130 | 114 | if ( ! settings.url && options.ajaxurl ) { |
| 131 | 115 | settings.url = options.ajaxurl; |
| 132 | 116 | } |
| 133 | 117 | |
| 134 | | /** |
| 135 | | * The interval can be from 15 to 120 sec. and can be set temporarily to 5 sec. |
| 136 | | * It can be set in the initial options or changed later through JS and/or through PHP. |
| 137 | | */ |
| | 118 | // The interval can be from 15 to 120 sec. and can be set temporarily to 5 sec. |
| | 119 | // It can be set in the initial options or changed later from JS and/or from PHP. |
| 138 | 120 | if ( options.interval ) { |
| 139 | 121 | settings.mainInterval = options.interval; |
| 140 | 122 | |
| … |
… |
|
| 145 | 127 | } |
| 146 | 128 | } |
| 147 | 129 | |
| 148 | | /** |
| 149 | | * Used to limit the number of AJAX requests. Overrides all other intervals if they are shorter. |
| 150 | | * Needed for some hosts that cannot handle frequent requests and the user may exceed the allocated server CPU time, etc. |
| 151 | | * The minimal interval can be up to 600 sec. however setting it to longer than 120 sec. will limit or disable |
| 152 | | * some of the functionality (like post locks). |
| 153 | | * Once set at initialization, minimalInterval cannot be changed/overridden. |
| 154 | | */ |
| | 130 | // Used to limit the number of AJAX requests. Overrides all other intervals if they are shorter. |
| | 131 | // Needed for some hosts that cannot handle frequent requests and the user may exceed the allocated server CPU time, etc. |
| | 132 | // The minimal interval can be up to 600 sec. however setting it to longer than 120 sec. will limit or disable |
| | 133 | // some of the functionality (like post locks). |
| | 134 | // Once set at initialization, minimalInterval cannot be changed/overridden. |
| 155 | 135 | if ( options.minimalInterval ) { |
| 156 | 136 | options.minimalInterval = parseInt( options.minimalInterval, 10 ); |
| 157 | 137 | settings.minimalInterval = options.minimalInterval > 0 && options.minimalInterval <= 600 ? options.minimalInterval * 1000 : 0; |
| … |
… |
|
| 161 | 141 | settings.mainInterval = settings.minimalInterval; |
| 162 | 142 | } |
| 163 | 143 | |
| 164 | | // 'screenId' can be added from settings on the front end where the JS global 'pagenow' is not set. |
| | 144 | // 'screenId' can be added from settings on the front end where the JS global 'pagenow' is not set |
| 165 | 145 | if ( ! settings.screenId ) { |
| 166 | 146 | settings.screenId = options.screenId || 'front'; |
| 167 | 147 | } |
| … |
… |
|
| 171 | 151 | } |
| 172 | 152 | } |
| 173 | 153 | |
| 174 | | // Convert to milliseconds. |
| | 154 | // Convert to milliseconds |
| 175 | 155 | settings.mainInterval = settings.mainInterval * 1000; |
| 176 | 156 | settings.originalInterval = settings.mainInterval; |
| 177 | 157 | |
| 178 | | /** |
| 179 | | * Switch the interval to 120 seconds by using the Page Visibility API. |
| 180 | | * If the browser doesn't support it (Safari < 7, Android < 4.4, IE < 10), the interval |
| 181 | | * will be increased to 120 seconds after 5 minutes of mouse and keyboard inactivity. |
| 182 | | */ |
| | 158 | // Switch the interval to 120 sec. by using the Page Visibility API. |
| | 159 | // If the browser doesn't support it (Safari < 7, Android < 4.4, IE < 10), the interval |
| | 160 | // will be increased to 120 sec. after 5 min. of mouse and keyboard inactivity. |
| 183 | 161 | if ( typeof document.hidden !== 'undefined' ) { |
| 184 | 162 | hidden = 'hidden'; |
| 185 | 163 | visibilitychange = 'visibilitychange'; |
| … |
… |
|
| 218 | 196 | } |
| 219 | 197 | |
| 220 | 198 | $(window).on( 'unload.wp-heartbeat', function() { |
| 221 | | // Don't connect anymore. |
| | 199 | // Don't connect any more |
| 222 | 200 | settings.suspend = true; |
| 223 | 201 | |
| 224 | | // Abort the last request if not completed. |
| | 202 | // Abort the last request if not completed |
| 225 | 203 | if ( settings.xhr && settings.xhr.readyState !== 4 ) { |
| 226 | 204 | settings.xhr.abort(); |
| 227 | 205 | } |
| … |
… |
|
| 230 | 208 | // Check for user activity every 30 seconds. |
| 231 | 209 | window.setInterval( checkUserActivity, 30000 ); |
| 232 | 210 | |
| 233 | | // Start one tick after DOM ready. |
| | 211 | // Start one tick after DOM ready |
| 234 | 212 | $document.ready( function() { |
| 235 | 213 | settings.lastTick = time(); |
| 236 | 214 | scheduleNextTick(); |
| … |
… |
|
| 238 | 216 | } |
| 239 | 217 | |
| 240 | 218 | /** |
| 241 | | * Returns the current time according to the browser. |
| | 219 | * Return the current time according to the browser |
| 242 | 220 | * |
| 243 | 221 | * @access private |
| 244 | 222 | * |
| 245 | | * @since 3.6.0 |
| 246 | | * |
| 247 | | * @returns int Returns the current time. |
| | 223 | * @return int |
| 248 | 224 | */ |
| 249 | 225 | function time() { |
| 250 | 226 | return (new Date()).getTime(); |
| 251 | 227 | } |
| 252 | 228 | |
| 253 | 229 | /** |
| 254 | | * Checks if the iframe is from the same origin. |
| | 230 | * Check if the iframe is from the same origin |
| 255 | 231 | * |
| 256 | 232 | * @access private |
| 257 | 233 | * |
| 258 | | * @since 3.6.0 |
| 259 | | * |
| 260 | | * @returns boolean Returns whether or not the iframe is from the same origin. |
| | 234 | * @return bool |
| 261 | 235 | */ |
| 262 | 236 | function isLocalFrame( frame ) { |
| 263 | 237 | var origin, src = frame.src; |
| 264 | 238 | |
| 265 | | /** |
| 266 | | * Need to compare strings as WebKit doesn't throw JS errors when iframes have different origin. |
| 267 | | * It throws uncatchable exceptions. |
| 268 | | */ |
| | 239 | // Need to compare strings as WebKit doesn't throw JS errors when iframes have different origin. |
| | 240 | // It throws uncatchable exceptions. |
| 269 | 241 | if ( src && /^https?:\/\//.test( src ) ) { |
| 270 | 242 | origin = window.location.origin ? window.location.origin : window.location.protocol + '//' + window.location.host; |
| 271 | 243 | |
| … |
… |
|
| 284 | 256 | } |
| 285 | 257 | |
| 286 | 258 | /** |
| 287 | | * Checks if the document's focus has changed. |
| | 259 | * Check if the document's focus has changed |
| 288 | 260 | * |
| 289 | 261 | * @access private |
| 290 | 262 | * |
| 291 | | * @since 4.1.0 |
| 292 | | * |
| 293 | | * @returns { void } |
| | 263 | * @return void |
| 294 | 264 | */ |
| 295 | 265 | function checkFocus() { |
| 296 | 266 | if ( settings.hasFocus && ! document.hasFocus() ) { |
| … |
… |
|
| 301 | 271 | } |
| 302 | 272 | |
| 303 | 273 | /** |
| 304 | | * Sets error state and fires an event on XHR errors or timeout. |
| | 274 | * Set error state and fire an event on XHR errors or timeout |
| 305 | 275 | * |
| 306 | 276 | * @access private |
| 307 | 277 | * |
| 308 | | * @since 3.8.0 |
| 309 | | * |
| 310 | | * @param string error The error type passed from the XHR. |
| 311 | | * @param int status The HTTP status code passed from jqXHR (200, 404, 500, etc.). |
| 312 | | * |
| 313 | | * @returns { void } |
| | 278 | * @param string error The error type passed from the XHR |
| | 279 | * @param int status The HTTP status code passed from jqXHR (200, 404, 500, etc.) |
| | 280 | * @return void |
| 314 | 281 | */ |
| 315 | 282 | function setErrorState( error, status ) { |
| 316 | 283 | var trigger; |
| … |
… |
|
| 318 | 285 | if ( error ) { |
| 319 | 286 | switch ( error ) { |
| 320 | 287 | case 'abort': |
| 321 | | // Do nothing. |
| | 288 | // do nothing |
| 322 | 289 | break; |
| 323 | 290 | case 'timeout': |
| 324 | | // No response for 30 sec. |
| | 291 | // no response for 30 sec. |
| 325 | 292 | trigger = true; |
| 326 | 293 | break; |
| 327 | 294 | case 'error': |
| … |
… |
|
| 329 | 296 | trigger = true; |
| 330 | 297 | break; |
| 331 | 298 | } |
| 332 | | // Falls through. |
| | 299 | /* falls through */ |
| 333 | 300 | case 'parsererror': |
| 334 | 301 | case 'empty': |
| 335 | 302 | case 'unknown': |
| … |
… |
|
| 350 | 317 | } |
| 351 | 318 | |
| 352 | 319 | /** |
| 353 | | * Clears the error state and fires an event if there is a connection error. |
| | 320 | * Clear the error state and fire an event |
| 354 | 321 | * |
| 355 | 322 | * @access private |
| 356 | 323 | * |
| 357 | | * @since 3.8.0 |
| 358 | | * |
| 359 | | * @returns { void } |
| | 324 | * @return void |
| 360 | 325 | */ |
| 361 | 326 | function clearErrorState() { |
| 362 | | // Has connected successfully. |
| | 327 | // Has connected successfully |
| 363 | 328 | settings.hasConnected = true; |
| 364 | 329 | |
| 365 | 330 | if ( hasConnectionError() ) { |
| … |
… |
|
| 370 | 335 | } |
| 371 | 336 | |
| 372 | 337 | /** |
| 373 | | * Gathers the data and connects to the server. |
| | 338 | * Gather the data and connect to the server |
| 374 | 339 | * |
| 375 | 340 | * @access private |
| 376 | 341 | * |
| 377 | | * @since 3.6.0 |
| 378 | | * |
| 379 | | * @returns { void } |
| | 342 | * @return void |
| 380 | 343 | */ |
| 381 | 344 | function connect() { |
| 382 | 345 | var ajaxData, heartbeatData; |
| … |
… |
|
| 390 | 353 | settings.lastTick = time(); |
| 391 | 354 | |
| 392 | 355 | heartbeatData = $.extend( {}, settings.queue ); |
| 393 | | // Clear the data queue. Anything added after this point will be sent on the next tick. |
| | 356 | // Clear the data queue, anything added after this point will be send on the next tick |
| 394 | 357 | settings.queue = {}; |
| 395 | 358 | |
| 396 | 359 | $document.trigger( 'heartbeat-send', [ heartbeatData ] ); |
| … |
… |
|
| 440 | 403 | |
| 441 | 404 | $document.trigger( 'heartbeat-tick', [response, textStatus, jqXHR] ); |
| 442 | 405 | |
| 443 | | // Do this last. Can trigger the next XHR if connection time > 5 sec. and newInterval == 'fast'. |
| | 406 | // Do this last, can trigger the next XHR if connection time > 5 sec. and newInterval == 'fast' |
| 444 | 407 | if ( newInterval ) { |
| 445 | 408 | interval( newInterval ); |
| 446 | 409 | } |
| … |
… |
|
| 451 | 414 | } |
| 452 | 415 | |
| 453 | 416 | /** |
| 454 | | * Schedules the next connection. |
| | 417 | * Schedule the next connection |
| 455 | 418 | * |
| 456 | 419 | * Fires immediately if the connection time is longer than the interval. |
| 457 | 420 | * |
| 458 | 421 | * @access private |
| 459 | 422 | * |
| 460 | | * @since 3.8.0 |
| 461 | | * |
| 462 | | * @returns { void } |
| | 423 | * @return void |
| 463 | 424 | */ |
| 464 | 425 | function scheduleNextTick() { |
| 465 | 426 | var delta = time() - settings.lastTick, |
| … |
… |
|
| 499 | 460 | } |
| 500 | 461 | |
| 501 | 462 | /** |
| 502 | | * Sets the internal state when the browser window becomes hidden or loses focus. |
| | 463 | * Set the internal state when the browser window becomes hidden or loses focus |
| 503 | 464 | * |
| 504 | 465 | * @access private |
| 505 | 466 | * |
| 506 | | * @since 3.6.0 |
| 507 | | * |
| 508 | | * @returns { void } |
| | 467 | * @return void |
| 509 | 468 | */ |
| 510 | 469 | function blurred() { |
| 511 | 470 | settings.hasFocus = false; |
| 512 | 471 | } |
| 513 | 472 | |
| 514 | 473 | /** |
| 515 | | * Sets the internal state when the browser window becomes visible or is in focus. |
| | 474 | * Set the internal state when the browser window becomes visible or is in focus |
| 516 | 475 | * |
| 517 | 476 | * @access private |
| 518 | 477 | * |
| 519 | | * @since 3.6.0 |
| 520 | | * |
| 521 | | * @returns { void } |
| | 478 | * @return void |
| 522 | 479 | */ |
| 523 | 480 | function focused() { |
| 524 | 481 | settings.userActivity = time(); |
| … |
… |
|
| 533 | 490 | } |
| 534 | 491 | |
| 535 | 492 | /** |
| 536 | | * Runs when the user becomes active after a period of inactivity. |
| | 493 | * Runs when the user becomes active after a period of inactivity |
| 537 | 494 | * |
| 538 | 495 | * @access private |
| 539 | 496 | * |
| 540 | | * @since 3.6.0 |
| 541 | | * |
| 542 | | * @returns { void } |
| | 497 | * @return void |
| 543 | 498 | */ |
| 544 | 499 | function userIsActive() { |
| 545 | 500 | settings.userActivityEvents = false; |
| … |
… |
|
| 555 | 510 | } |
| 556 | 511 | |
| 557 | 512 | /** |
| 558 | | * Checks for user activity. |
| | 513 | * Check for user activity |
| 559 | 514 | * |
| 560 | 515 | * Runs every 30 sec. |
| 561 | 516 | * Sets 'hasFocus = true' if user is active and the window is in the background. |
| 562 | | * Sets 'hasFocus = false' if the user has been inactive (no mouse or keyboard activity) |
| | 517 | * Set 'hasFocus = false' if the user has been inactive (no mouse or keyboard activity) |
| 563 | 518 | * for 5 min. even when the window has focus. |
| 564 | 519 | * |
| 565 | 520 | * @access private |
| 566 | 521 | * |
| 567 | | * @since 3.8.0 |
| 568 | | * |
| 569 | | * @returns { void } |
| | 522 | * @return void |
| 570 | 523 | */ |
| 571 | 524 | function checkUserActivity() { |
| 572 | 525 | var lastActive = settings.userActivity ? time() - settings.userActivity : 0; |
| … |
… |
|
| 599 | 552 | } |
| 600 | 553 | } |
| 601 | 554 | |
| 602 | | // Public methods. |
| | 555 | // Public methods |
| 603 | 556 | |
| 604 | 557 | /** |
| 605 | | * Checks whether the window (or any local iframe in it) has focus, or the user is active. |
| | 558 | * Whether the window (or any local iframe in it) has focus, or the user is active |
| 606 | 559 | * |
| 607 | | * @since 3.6.0 |
| 608 | | * |
| 609 | | * @returns boolean True if the window or the user is active. |
| | 560 | * @return bool |
| 610 | 561 | */ |
| 611 | 562 | function hasFocus() { |
| 612 | 563 | return settings.hasFocus; |
| 613 | 564 | } |
| 614 | 565 | |
| 615 | 566 | /** |
| 616 | | * Checks whether there is a connection error. |
| 617 | | * |
| 618 | | * @since 3.6.0 |
| | 567 | * Whether there is a connection error |
| 619 | 568 | * |
| 620 | | * @returns boolean True if a connection error was found. |
| | 569 | * @return bool |
| 621 | 570 | */ |
| 622 | 571 | function hasConnectionError() { |
| 623 | 572 | return settings.connectionError; |
| 624 | 573 | } |
| 625 | 574 | |
| 626 | 575 | /** |
| 627 | | * Connects as soon as possible regardless of 'hasFocus' state. |
| | 576 | * Connect asap regardless of 'hasFocus' |
| 628 | 577 | * |
| 629 | 578 | * Will not open two concurrent connections. If a connection is in progress, |
| 630 | 579 | * will connect again immediately after the current connection completes. |
| 631 | 580 | * |
| 632 | | * @since 3.8.0 |
| 633 | | * |
| 634 | | * @returns { void } |
| | 581 | * @return void |
| 635 | 582 | */ |
| 636 | 583 | function connectNow() { |
| 637 | 584 | settings.lastTick = 0; |
| … |
… |
|
| 639 | 586 | } |
| 640 | 587 | |
| 641 | 588 | /** |
| 642 | | * Disables suspending. |
| | 589 | * Disable suspending |
| 643 | 590 | * |
| 644 | 591 | * Should be used only when Heartbeat is performing critical tasks like autosave, post-locking, etc. |
| 645 | 592 | * Using this on many screens may overload the user's hosting account if several |
| 646 | 593 | * browser windows/tabs are left open for a long time. |
| 647 | 594 | * |
| 648 | | * @since 3.8.0 |
| 649 | | * |
| 650 | | * @returns { void } |
| | 595 | * @return void |
| 651 | 596 | */ |
| 652 | 597 | function disableSuspend() { |
| 653 | 598 | settings.suspendEnabled = false; |
| 654 | 599 | } |
| 655 | 600 | |
| 656 | 601 | /** |
| 657 | | * Gets/Sets the interval. |
| | 602 | * Get/Set the interval |
| 658 | 603 | * |
| 659 | | * When setting to 'fast' or 5, the interval is 5 seconds for the next 30 ticks (for 2 minutes and 30 seconds) by default. |
| | 604 | * When setting to 'fast' or 5, by default interval is 5 sec. for the next 30 ticks (for 2 min and 30 sec). |
| 660 | 605 | * In this case the number of 'ticks' can be passed as second argument. |
| 661 | 606 | * If the window doesn't have focus, the interval slows down to 2 min. |
| 662 | 607 | * |
| 663 | | * @since 3.6.0 |
| 664 | | * |
| 665 | | * @param mixed speed Interval: 'fast' or 5, 15, 30, 60, 120. |
| 666 | | * @param string ticks Used with speed = 'fast' or 5. Tells how many ticks before the interval reverts back. |
| 667 | | * |
| 668 | | * @returns int Current interval in seconds. |
| | 608 | * @param mixed speed Interval: 'fast' or 5, 15, 30, 60, 120 |
| | 609 | * @param string ticks Used with speed = 'fast' or 5, how many ticks before the interval reverts back |
| | 610 | * @return int Current interval in seconds |
| 669 | 611 | */ |
| 670 | 612 | function interval( speed, ticks ) { |
| 671 | 613 | var newInterval, |
| … |
… |
|
| 725 | 667 | } |
| 726 | 668 | |
| 727 | 669 | /** |
| 728 | | * Enqueues data to send with the next XHR. |
| | 670 | * Enqueue data to send with the next XHR |
| 729 | 671 | * |
| 730 | 672 | * As the data is send asynchronously, this function doesn't return the XHR response. |
| 731 | 673 | * To see the response, use the custom jQuery event 'heartbeat-tick' on the document, example: |
| … |
… |
|
| 735 | 677 | * If the same 'handle' is used more than once, the data is not overwritten when the third argument is 'true'. |
| 736 | 678 | * Use wp.heartbeat.isQueued('handle') to see if any data is already queued for that handle. |
| 737 | 679 | * |
| 738 | | * @since 3.6.0 |
| 739 | | * |
| 740 | | * @param string handle Unique handle for the data, used in PHP to receive the data. |
| 741 | | * @param mixed data The data to send. |
| 742 | | * @param boolean noOverwrite Whether to overwrite existing data in the queue. |
| 743 | | * |
| 744 | | * @returns boolean True if the data was queued. |
| | 680 | * $param string handle Unique handle for the data. The handle is used in PHP to receive the data. |
| | 681 | * $param mixed data The data to send. |
| | 682 | * $param bool noOverwrite Whether to overwrite existing data in the queue. |
| | 683 | * $return bool Whether the data was queued or not. |
| 745 | 684 | */ |
| 746 | 685 | function enqueue( handle, data, noOverwrite ) { |
| 747 | 686 | if ( handle ) { |
| … |
… |
|
| 756 | 695 | } |
| 757 | 696 | |
| 758 | 697 | /** |
| 759 | | * Checks if data with a particular handle is queued. |
| 760 | | * |
| 761 | | * @since 3.6.0 |
| 762 | | * |
| 763 | | * @param string handle The handle for the data. |
| | 698 | * Check if data with a particular handle is queued |
| 764 | 699 | * |
| 765 | | * @returns boolean True if the data is queued with this handle. |
| | 700 | * $param string handle The handle for the data |
| | 701 | * $return bool Whether some data is queued with this handle |
| 766 | 702 | */ |
| 767 | 703 | function isQueued( handle ) { |
| 768 | 704 | if ( handle ) { |
| … |
… |
|
| 771 | 707 | } |
| 772 | 708 | |
| 773 | 709 | /** |
| 774 | | * Removes data with a particular handle from the queue. |
| | 710 | * Remove data with a particular handle from the queue |
| 775 | 711 | * |
| 776 | | * @since 3.7.0 |
| 777 | | * |
| 778 | | * @param string handle The handle for the data. |
| 779 | | * |
| 780 | | * @returns void |
| | 712 | * $param string handle The handle for the data |
| | 713 | * $return void |
| 781 | 714 | */ |
| 782 | 715 | function dequeue( handle ) { |
| 783 | 716 | if ( handle ) { |
| … |
… |
|
| 786 | 719 | } |
| 787 | 720 | |
| 788 | 721 | /** |
| 789 | | * Gets data that was enqueued with a particular handle. |
| 790 | | * |
| 791 | | * @since 3.7.0 |
| 792 | | * |
| 793 | | * @param string handle The handle for the data. |
| | 722 | * Get data that was enqueued with a particular handle |
| 794 | 723 | * |
| 795 | | * @returns mixed The data or undefined. |
| | 724 | * $param string handle The handle for the data |
| | 725 | * $return mixed The data or undefined |
| 796 | 726 | */ |
| 797 | 727 | function getQueuedItem( handle ) { |
| 798 | 728 | if ( handle ) { |
| … |
… |
|
| 802 | 732 | |
| 803 | 733 | initialize(); |
| 804 | 734 | |
| 805 | | // Expose public methods. |
| | 735 | // Expose public methods |
| 806 | 736 | return { |
| 807 | 737 | hasFocus: hasFocus, |
| 808 | 738 | connectNow: connectNow, |