Detecting if user is idle, away or back by using Idle.js

Idle.js is a javascript API that can detect if a user is idle, away or back in a webpage. This library is independent of other libraries such as jQuery. It supports callbacks for when the user is idle and back and methods for setting the timeout. The main purpose of creating this library is to use it in a chat application to relay the user status back to the server.

API

There are 2 callbacks supported, onAway and onAwayBack, both of which takes no parameters. onAway is trigger whenever the there is no activity inside the webpage by the user for the length of the timeout specified. onAwayBack is triggered whenever there is an activity inside the webpage by the user.

One method exposed to set the timeout setAwayTimeout(int), which takes an integer of when to trigger the onAway event.

The constructor also accepts a configuration object with all of these methods.

Here is an example of usage:

Demo

There is a demo of this on on github here.

The project is hosted here.