GitXplorerGitXplorer
s

idle-timer

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Verified
d87482786492fa1a844f0f5e6313f69ad8c93510

Update repository URL: Bitbucket -> GitHub

sspdawson committed 6 years ago
Verified
5a4cb73e49cc2a9f64ef80cea955f5f8e939b156

Fix import for idle-timer, in README

sspdawson committed 7 years ago
Verified
f64a601e8ccafa5c4d6763c6977acf62af6630a9

ES6 syntax

sspdawson committed 7 years ago
Verified
f856aeb2229200a1538d88fa4c8595750fc431c9

Change file extensions back to .js

sspdawson committed 7 years ago
Verified
e85c38116b0ce164b4ca593d0fb30787853dd21a

Webpacker doesn't seem to like the .js file extension for ES2015 files...

sspdawson committed 7 years ago
Verified
99f94399e3f29969ae0d7aaffcc0e71ce80a54c2

Partial revert of cccbb0a134ddd43293c651548003f9d443e49771

sspdawson committed 7 years ago

README

The README file for this repository.

idle-timer

A timer to detect lapses in browser activity

The initial implementation is based on jquery-idletimer, but rewritten to break the dependency on jQuery, and to take advantage of modern JavaScript.

Synopsis

The browser is considered "idle", if within a specified period of time:

  • The mouse has not moved
  • The mouse wheel has not scrolled
  • No key has been pressed

When such an "idle" state is detected, an event is dispatched on the element on which the idle timer has been registered.

Usage

import IdleTimer from 'idle-timer';

let handle_idle_timer_event = function(event) {
    const detail = event.detail;
    const timer = detail.timer;
    const original_event = detail.event; /* N.B. May be null */
    console.log('timer: %s (%s)',
                event.type,
                (original_event ? original_event.type : null));
};

console.log('timer: setup');
let timer = new IdleTimer({timeout: 2000, element: window.document});
window.document.addEventListener('idle-timer:idle', handle_idle_timer_event);
window.document.addEventListener('idle-timer:active', handle_idle_timer_event);

API: Constructor options

element

Defaulting to document, this indicates the element which is to be monitored for activity.

initially_idle

Defaulting to false, this indicates whether the instance should be considered "idle" initially.

timeout

Defaulting to 30000, this indicates the duration in milliseconds after which the "idle" state is triggered.

events

This indicates the array of events to be monitored, and defaults to the following value.

[
    'mousemove',
    'keydown',
    'wheel',
    'DOMMouseScroll',
    'mousewheel',
    'mousedown'
]

storage_key

Defaulting to null, this indicates a localStorage key to be used for synchronising the timer between multiple browser tabs/windows.

API: Timer management methods

Clean up a timer that is no longer required:

timer.destroy();

Reset a timer to its initial conditions:

timer.reset();

Pause a timer:

timer.pause();

Resume a previously-paused timer:

timer.resume();

API: Query methods

Get the number of milliseconds remaining until "idle" state detected by timer:

timer.get_remaining_time();

Get the number of milliseconds elapsed on timer since the last "idle" or "active" state transition occurred:

timer.get_elapsed_time();

Get the timestamp in milliseconds of the last detected activity:

timer.get_last_active_time();

Is timer currently indicating an "idle" state?

timer.is_idle();