|
|
3 tahun lalu | |
|---|---|---|
| .. | ||
| demos | 3 tahun lalu | |
| dist | 3 tahun lalu | |
| libs | 3 tahun lalu | |
| src | 3 tahun lalu | |
| test | 3 tahun lalu | |
| CHANGELOG.md | 3 tahun lalu | |
| CONTRIBUTING.md | 3 tahun lalu | |
| Gruntfile.js | 3 tahun lalu | |
| LICENSE-MIT | 3 tahun lalu | |
| README.md | 3 tahun lalu | |
| idle-timer.jquery.json | 3 tahun lalu | |
| jquery-idletimer.sln | 3 tahun lalu | |
| package.json | 3 tahun lalu | |
http://thorst.github.io/jquery-idletimer/index.html
Fires a custom event when the user is "idle". Idle is defined by not...
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.
// binds to document - shorthand
$.idleTimer();
// binds to document - explicit
$( document ).idleTimer();
// bind to different element
$( "#myTextArea" ).idleTimer();
You can configure the settings several ways
// idleTimer() with all defaults
$( document ).idleTimer( );
// idleTimer() takes an optional numeric argument that defines just the idle timeout
// timeout is in milliseconds
$( document ).idleTimer( 10000 );
// idleTimer() takes an optional object argument that defines any/all setting
$( document ).idleTimer( {
timeout:10000,
idle:true
});
/*
* Here are the possible settings
* you can omit any or all of them
*/
// indicates if the user is idle
idle [default:false]
// the timeout period
timeout [default:30000]
// activity is any one of these events
events [default:'mousemove keydown wheel DOMMouseScroll mousewheel mousedown touchstart touchmove MSPointerDown MSPointerMove']
When a users state changes a custom events get triggered. There are several parameters passed to your handler for you to use
$( document ).on( "idle.idleTimer", function(event, elem, obj){
// function you want to fire when the user goes idle
});
$( document ).on( "active.idleTimer", function(event, elem, obj, triggerevent){
// function you want to fire when the user becomes active again
});
/*
* Here are the arguments
*/
// event
// will be either idle.idleTimer or active.idleTimer
// use event.stopPropagation(); to stop element from bubbling up to document
// elem
// is the element that the event was triggered on
// obj
// is a copy of the internal data used by idleTimer
// triggerevent
// is the initial event that triggered the element to become active
// obviously for idle state this will be undefined
There are several methods to invoke
// stop the timer, removes data, removes event bindings
// to come back from this you will need to instantiate again
// returns: jQuery
$( document ).idleTimer("destroy");
// save remaining time, and stops the timer
// returns: jQuery
$( document ).idleTimer("pause");
// starts timer with remaining time
// returns: jQuery
$( document ).idleTimer("resume");
// restore initial idle state, and restart the timer
// returns: jQuery
$( document ).idleTimer("reset");
// get time left until idle, if idle return 0
// returns: number
$( document ).idleTimer("getRemainingTime");
// get time elapsed (in ms) since the user went idle/active
// if idle, how have you been idle, if active, how long have you been active
// returns: number
$( document ).idleTimer("getElapsedTime");
// get time last active event fired
// returns: number
$( document ).idleTimer("getLastActiveTime");
// you can also query if it's "idle" or "active"
// returns: bool
$( document ).idleTimer("isIdle");
jQuery 1.7 (tested with 1.11.0)
####Desktop
####Mobile
| Version | Author | Released | Links |
|---|---|---|---|
| 1.0.0 | Todd Horst | 03/10/2014 | Change Log - Breaking Changes |
| 0.9.3 | Mike Sherov | 08/04/2013 |
Please create a fiddle and submit a ticket