[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/ -> heartbeat.js (summary)

Heartbeat API Heartbeat is a simple server polling API that sends XHR requests to the server every 15 - 60 seconds and triggers events (or callbacks) upon receiving data. Currently these 'ticks' handle transports for post locking, login-expiration warnings, autosave, and related tasks while a user is logged in.

File Size: 906 lines (24 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 23 functions

  initialize()
  time()
  isLocalFrame()
  checkFocus()
  setErrorState()
  clearErrorState()
  connect()
  scheduleNextTick()
  blurred()
  focused()
  suspend()
  resume()
  userIsActive()
  checkUserActivity()
  hasFocus()
  hasConnectionError()
  connectNow()
  disableSuspend()
  interval()
  enqueue()
  isQueued()
  dequeue()
  getQueuedItem()

Functions
Functions that are not part of a class:

initialize()   X-Ref
Sets local variables and events, then starts the heartbeat.

return: {void}

time()   X-Ref
No description

isLocalFrame( frame )   X-Ref
Checks if the iframe is from the same origin.

return: {boolean} Returns whether or not the iframe is from the same origin.

checkFocus()   X-Ref
Checks if the document's focus has changed.

return: {void}

setErrorState( error, status )   X-Ref
Sets error state and fires an event on XHR errors or timeout.

param: {string} error  The error type passed from the XHR.
param: {number} status The HTTP status code passed from jqXHR
return: {void}

clearErrorState()   X-Ref
Clears the error state and fires an event if there is a connection error.

return: {void}

connect()   X-Ref
Gathers the data and connects to the server.

return: {void}

scheduleNextTick()   X-Ref
Schedules the next connection.

Fires immediately if the connection time is longer than the interval.

return: {void}

blurred()   X-Ref
No description

focused()   X-Ref
Sets the internal state when the browser window becomes visible or is in focus.

return: {void}

suspend()   X-Ref
Suspends connecting.


resume()   X-Ref
Resumes connecting.


userIsActive()   X-Ref
Runs when the user becomes active after a period of inactivity.

return: {void}

checkUserActivity()   X-Ref
Checks for user activity.

Runs every 30 seconds. Sets 'hasFocus = true' if user is active and the window
is in the background. Sets 'hasFocus = false' if the user has been inactive
(no mouse or keyboard activity) for 5 minutes even when the window has focus.

return: {void}

hasFocus()   X-Ref
Checks whether the window (or any local iframe in it) has focus, or the user
is active.

return: {boolean} True if the window or the user is active.

hasConnectionError()   X-Ref
Checks whether there is a connection error.

return: {boolean} True if a connection error was found.

connectNow()   X-Ref
Connects as soon as possible regardless of 'hasFocus' state.

Will not open two concurrent connections. If a connection is in progress,
will connect again immediately after the current connection completes.

return: {void}

disableSuspend()   X-Ref
Disables suspending.

Should be used only when Heartbeat is performing critical tasks like
autosave, post-locking, etc. Using this on many screens may overload
the user's hosting account if several browser windows/tabs are left open
for a long time.

return: {void}

interval( speed, ticks )   X-Ref
Gets/Sets the interval.

When setting to 'fast' or 5, the interval is 5 seconds for the next 30 ticks
(for 2 minutes and 30 seconds) by default. In this case the number of 'ticks'
can be passed as second argument. If the window doesn't have focus,
the interval slows down to 2 minutes.

param: {string|number} speed Interval: 'fast' or 5, 15, 30, 60, 120.
param: {string}        ticks Tells how many ticks before the interval reverts
return: {number} Current interval in seconds.

enqueue( handle, data, noOverwrite )   X-Ref
Enqueues data to send with the next XHR.

As the data is send asynchronously, this function doesn't return the XHR
response. To see the response, use the custom jQuery event 'heartbeat-tick'
on the document, example:
$(document).on( 'heartbeat-tick.myname', function( event, data, textStatus, jqXHR ) {
// code
});
If the same 'handle' is used more than once, the data is not overwritten when
the third argument is 'true'. Use `wp.heartbeat.isQueued('handle')` to see if
any data is already queued for that handle.

param: {string}  handle      Unique handle for the data, used in PHP to
param: {*}       data        The data to send.
param: {boolean} noOverwrite Whether to overwrite existing data in the queue.
return: {boolean} True if the data was queued.

isQueued( handle )   X-Ref
Checks if data with a particular handle is queued.

param: {string} handle The handle for the data.
return: {boolean} True if the data is queued with this handle.

dequeue( handle )   X-Ref
Removes data with a particular handle from the queue.

param: {string} handle The handle for the data.
return: {void}

getQueuedItem( handle )   X-Ref
Gets data that was enqueued with a particular handle.

param: {string} handle The handle for the data.
return: {*} The data or undefined.



Generated : Tue Mar 19 08:20:01 2024 Cross-referenced by PHPXref