[ Index ]

PHP Cross Reference of WordPress

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: 881 lines (23 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 21 functions

  initialize()
  time()
  isLocalFrame()
  checkFocus()
  setErrorState()
  clearErrorState()
  connect()
  scheduleNextTick()
  blurred()
  focused()
  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.

returns: {void}
since: 3.8.0

time()   X-Ref
Returns the current time according to the browser.

returns: {number} Returns the current time.
since: 3.6.0

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

returns: {boolean} Returns whether or not the iframe is from the same origin.
since: 3.6.0

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

returns: {void}
since: 4.1.0

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
returns: {void}
since: 3.8.0

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

returns: {void}
since: 3.8.0

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

returns: {void}
since: 3.6.0

scheduleNextTick()   X-Ref
Schedules the next connection.

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

returns: {void}
since: 3.8.0

blurred()   X-Ref
No description

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

returns: {void}
since: 3.6.0

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

returns: {void}
since: 3.6.0

checkUserActivity()   X-Ref
Checks for user activity.

Runs every 30 sec. 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 min. even when the window has focus.

returns: {void}
since: 3.8.0

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

returns: {boolean} True if the window or the user is active.
since: 3.6.0

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

returns: {boolean} True if a connection error was found.
since: 3.6.0

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.

returns: {void}
since: 3.8.0

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.

returns: {void}
since: 3.8.0

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 min.

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

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.
returns: {boolean} True if the data was queued.
since: 3.6.0

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

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

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

param: {string} handle The handle for the data.
returns: {void}
since: 3.7.0

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

param: {string} handle The handle for the data.
returns: {*} The data or undefined.
since: 3.7.0



Generated: Tue Sep 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1