GitXplorerGitXplorer
s

idle-timer

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Verified
cccbb0a134ddd43293c651548003f9d443e49771

Rework Utils.now

sspdawson committed 7 years ago
Verified
8abf770edfb3dec3ff16cc07a83ecfd580f42004

Fix import path

sspdawson committed 7 years ago
Verified
ce6aee2af3bcbd7a84499aafe2c098f03dbe0ad9

Split out utility functions

sspdawson committed 7 years ago
Verified
ce21c1653b48c14ccd53bf135dbb460bf58335c6

Further reworking, and fleshing out of README

sspdawson committed 7 years ago
Verified
9be81e484da5cc8d907d2edc3c41127f9e02c224

Update copyright and license information

sspdawson committed 7 years ago
Verified
70ed9894ffc595ec28b8d195da83ead2ed4e031f

First cut of README

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();