• Stars
    star
    282
  • Rank 146,549 (Top 3 %)
  • Language
    JavaScript
  • Created over 15 years ago
  • Updated about 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A port of Prototype's PeriodicalUpdater to JQuery

A port of Prototype's Ajax.PeriodicalUpdater function to jQuery.

Basically, this function polls some remote service at fairly regular internvals, and (optionally) processes the result via a callback. The period of calls will decay as long as the same response keeps coming back from the server (either in the form of repeated data or in the form of a 304 Not Modified status), which reduces the load on the server naturally. The first Ajax call happens as a page 'onReady' handler (ie: the jQuery(function) call), so it is safe to put the PeriodicalUpdater call anywhere on the page.

Usage:

    $.PeriodicalUpdater('/path/to/service', {
        url: url,         // URL of ajax request
        cache: false,     // By default, don't allow caching
        method: 'GET',    // method; get or post
        data: '',         // array of values to be passed to the page - e.g. {name: "John", greeting: "hello"}
        minTimeout: 1000, // starting value for the timeout in milliseconds
        maxTimeout:64000, // maximum length of time between requests
        multiplier: 2,    // if set to 2, timerInterval will double each time the response hasn't changed (up to maxTimeout)
        maxCalls: 0,      // maximum number of calls. 0 = no limit.
        maxCallsCallback: null, // The callback to execute when we reach our max number of calls
        autoStop: 0,      // automatically stop requests after this many returns of the same data. 0 = disabled
        autoStopCallback: null, // The callback to execute when we autoStop
        cookie: false,    // whether (and how) to store a cookie
        runatonce: false, // Whether to fire initially or wait
        verbose: 0        // The level to be logging at: 0 = none; 1 = some; 2 = all
    }, function(remoteData, success, xhr, handle) {
        // Process the new data (only called when there was a change)
				// For a description of "success", see $.ajax documentation
    });

		// You can also do a bound version: identical to above except that the callback function
		// has 'this' assigned to the JQuery object that you call it on.
		$('.myClass').PeriodicalUpdater('/path/to/service', { /* ... */ }, function(/*...*/) {
			// this is $('.myClass')
		});

Data:

The data value can be one of three things:

  • A scalar, in which case it will be used constantly.
  • A JavaScript map/object, in which case it will be turned into key/value pairs by jQuery
  • An anonymous function, in which case it will be executed before each AJAX call. See jQuery.ajax for more information.

Cookie:

The cookie value will store the timeout of the previous PeriodicalUpdater between page loads. It uses the JQuery-Cookie plugin (imported automatically by the script) to store these values. The value for the cookie configuration value can be one of three things:

  • A scalar, in which case it is treated as the cookie name
  • A JavaScript map/object, in which case you can specify the cookie name as the name property, and you can additionally specify any configuration value for the JQuery-Cookie plugin in order to configure the cookie.
  • A boolean, which signals to use a cookie if true, and not to use a cookie if false.

If you don't specify a cookie name, the cookie name defaults to the PeriodicalUpdater's url. WARNING: If you use two PeriodicalUpdaters with the same cookie name, they will each overwrite the other's value, resulting in wonky timeout behavior.

Other Configuration Data:

Any of the other standard $.ajax configuration options can be passed to the setting map, including the AJAX callbacks. The only exception is the flag that treats modifications as errors. That is always going to be true.

Function Return Value (Handle):

The function call returns a handle. You can call .stop() on this handle in order to stop the updating and ignore any subsequent responses. If the maximum number of calls, .stop(), or the autoStop has been triggered, you can restart the updater using .restart() on the handle. You can also call .send() on the handle to force a send of the AJAX request. This handle is also passed into the callback functions as the fourth argument.

More Information:

For more info about the motivation for this plugin, including its advantages over the deprecated 360innovate version, see the blog post on EnfranchisedMind.

See the source file for license terms.

More Repositories

1

gradle-plugins

Plugins for Gradle
Groovy
74
star
2

Gradle-License-Report

A plugin for generating reports about the licenses of third party software using Gradle
HTML
41
star
3

tomcat8-redis-sessions

Library for using Redis sessions in Tomcat 8.
Java
15
star
4

json-parser

JavaCC-built JSON Parser
Groovy
7
star
5

rfc

Robert Fischer's Common library for Haskell
Haskell
4
star
6

couchdb-psql-replication

Replicate your documents from CouchDB to PostgreSQL jsonb
Haskell
4
star
7

CleanSweep

Finalization substitute based on a Phantom Reference queue.
Java
4
star
8

miso-bulma

Bindings for the Bulma CSS Framework for Miso
Haskell
3
star
9

fetch-dns

An implementation of Node's "dns" API based on using "fetch"
JavaScript
3
star
10

Classy-Miso

A typeclass (type family) layer on top of Miso. Miso is a tasty client-side framework for Haskell.
Shell
3
star
11

hs-aws-lambda

A modern and easy-to-use wrapper for Docker-based Lambda implementations
Haskell
3
star
12

gradle-javacc-plugin

JavaCC Plugin of Gradle
Java
3
star
13

GuiceJumper

The Smokejumper supplemental classes for Guice. These are utility classes and useful modules which do not depend on anything more than the most recent version of Guice and its dependencies.
Java
3
star
14

hs-snowflake-checked

A Haskell derivation from Twitter's Snowflake unique id generation algorithm which adds a checksum to the resulting id.
Haskell
2
star
15

bittorrent2

A Haskell library supporting both GHC and GHCJS that provides the BitTorrent protocol (v1 and v2) over TCP, UDP, ZeroConf (aka: Bonjour), and WebRTC, depending on what is available.
Haskell
2
star
16

tois

A more user-friendly interface to the @toi/toi npm package.
TypeScript
1
star
17

vfs-conduit

A Haskell conduit that represents a Virtual File System.
Haskell
1
star
18

bulkify-experiments

Various demonstrations/experiments of using browserify's bulkify and npm's bulk-require
JavaScript
1
star
19

fun-promises

A library for making Promises more friendly and fun(ctional).
TypeScript
1
star
20

cabalish

An interface for retrieving .cabal file data for shell scripts.
Haskell
1
star
21

rich-asana-cli

A rich Asana CLI for task management
Haskell
1
star
22

pong-server

A useful Haskell library for running a pingable server within another application, which is useful for health checks and the like. This library runs a background server that listens on a port, and when a connection comes in, it writes "pong" and closes the connection.
Haskell
1
star
23

fusebox

Various FUSE (filesystem-in-userspace) implementations built on Haskell and HFUSE.
Haskell
1
star
24

sbl-latex

LaTeX files for a Society of Biblical Literature essay class and useful Biblical essay features.
1
star
25

github-cleaner

A little tool for cleaning up your GitHub repos
Haskell
1
star
26

Restling

Restlet + Guice + other awesomeness
Groovy
1
star
27

Haskell-GroundHog-DDL-Tolerance

Does GroundHog tolerate triggers that it does not know about? What about OID columns?
Haskell
1
star