jQuery Idle Timer Plugin
Demo
https://thorst.github.io/jquery-idletimer/index.html
Download
Purpose
Fires a custom event when the user is "idle". Idle is defined by not...
- moving the mouse
- scrolling the mouse wheel
- using the keyboard
Usage
There are two ways to instantiate. Either statically, or on an element. Element bound timers
will only watch for events inside of them. You may just want page-level activity, in which
case you may set up your timers on document
, document.documentElement
, and document.body
.
Instantiate returns jQuery for chaining.
$(function() {
$.idleTimer();
$( document ).idleTimer();
$( "#myTextArea" ).idleTimer();
});
Options
You can configure the settings several ways
$(function() {
$( document ).idleTimer( );
$( document ).idleTimer( 10000 );
$( document ).idleTimer( {
timeout:10000,
idle:true
});
idle [default:false]
timeout [default:30000]
events [default:'mousemove keydown wheel DOMMouseScroll mousewheel mousedown touchstart touchmove MSPointerDown MSPointerMove']
timerSyncId [default:null]
});
Events
When a users state changes a custom events get triggered. There are several parameters
passed to your handler for you to use.
$(function() {
$( document ).on( "idle.idleTimer", function(event, elem, obj){
});
$( document ).on( "active.idleTimer", function(event, elem, obj, triggerevent){
});
});
Methods
There are several methods to invoke
$(function() {
$( document ).idleTimer("destroy");
$( document ).idleTimer("pause");
$( document ).idleTimer("resume");
$( document ).idleTimer("reset");
$( document ).idleTimer("getRemainingTime");
$( document ).idleTimer("getElapsedTime");
$( document ).idleTimer("getLastActiveTime");
$( document ).idleTimer("isIdle");
});
Using multiple idle monitors
When using multiple idle monitors on the same element, a unique id needs be used for each one.
####Options
$(function() {
$( document ).idleTimer( 10000, "someUniqueId" );
$.idleTimer(10000, document, "someUniqueId");
});
####Methods
$(function() {
var uniqueId = "someUniqueString";
$( document ).idleTimer("pause", uniqueId);
});
####Events
$(function() {
var uniqueId = "someUniqueString";
$( document ).on( "idle.idleTimer" + uniqueId, function(event, elem, obj){
});
});
Pre-Req
jQuery 1.7 (tested with 1.11.0)
Intended Browser Support
####Desktop
-
=IE8
- Firefox n-1
- Chrome n-1
- Safari n
####Mobile
- iOS n-1
- Android (version?)
- Windows Phone IEMobile/10.0
Links
Playground
Version History
Author History
Bug?
Please create a fiddle and submit a ticket