idlejs
Execute a function only when certain events on certain target element have or have not occured within given timeout.
It's simple, configurable, typescript friendly and has an easy chainable API.
Install
yarn add idlejs npm install --save idlejs
v2 to v3
idlejs/dist
to idlejs
Change imports from
Idle
Excutes the callback function (do
) when none of the specified events have occurred within given time, in other words when user is idle.
Usage
; // with predefined events on `document` .whenNotInteractive .within5 .dologoutUser .start; // another example with custom events which are useful if events aren't bubbling up to the document .whenNot .whenNotInteractive .within10 .dologoutUser .start;
For more features or examples please check the tests and source code.
NotIdle
Executes the callback function (do
), if at least one of the specified events have occured within given time, in other words when user is not idle or interactive.
Usage
; // with predefined events on `document` .whenInteractive .within10 .dolog'user was active in the last 10 minutes' .start; // another example with custom events which are useful if events aren't bubbling up to the `document` .when .whenInteractive .within10 .dolog'user was active in the last 10 minutes' .start;
For more features or examples please check the tests and source code.
Setting time
Second parameter of within
is time unit in miliseconds, by default 60000 (a minute).
// will trigger if nothing happens for 5 minutesnew Idle .within5 // will trigger if nothing happens for 5 secondsnew Idle .within5, 1000