Sandbox: JavaScript

Polls a URL and updates a target's HTML based upon the response and can optionally run other delegators as well.


<a data-behavior="PollForUpdate"
     'url': '/sandbox/poll_for_update',
     'date': 1556236890,
     'pollInterval': 2000,
     'target': 'span.btn',
     'dataKey': 'count_text'
  <span class="btn btn-primary">Watch me change!</span>

Behavior Options

Name type default example description
url string ~ '' REQUIRED The url that is passed to Thanx.PollForUpdate.
date number ~ 1380580557 REQUIRED The time as presented in whatever format the server expects. In this case, it's in seconds.
target string ~ 'span.btn' The object to affect based on the server response.
dataKey string ~ 'count_text' The server returns a data hash. This is the key in that hash that contains the value we want to update target with. For example, the returned data hash needs to contain a count_text key, and it contains '4 new'. '4 new' is then inserted into target.
pollInterval number ~ 1000 How often (in milliseconds) the server will be polled.
delegators hash ~ { 'removeClass': { 'target': 'span.btn' } } Any delegators (and their options) to run upon a successful update response from the server. In this case, span.btn would be have a class removed.
updateDateOnClick boolean ~ true If enabled, this option will override the date passed to the server with updatedAt instead. This is useful if you want to trigger a reset of the counter due to user interaction.