GithubHelp home page GithubHelp logo

shawnmclean / idle.js Goto Github PK

View Code? Open in Web Editor NEW
401.0 21.0 59.0 94 KB

Javascript activity library for the browser. (away, idle, etc)

License: Other

CoffeeScript 3.04% JavaScript 92.53% CSS 2.59% HTML 1.85%

idle.js's Introduction

Build Status

Idle.Js

NuGet

Visual Studio users can install this directly into their web projects by executing the following command in the Package Manager Console

PM> Install-Package Idle.js

Web Component

Polymer wrapper is available here.

Description

Tiny javascript library to report activity of user in the browser (away, idle, not looking at webpage, etc). that is independent of any other javascript libraries such as jquery.

You can view the demo here.

Changelog

0.0.2 (19-11-14) - Bower Support

0.0.2 (7-03-12) - Added 2 events for the visibility API. Now detects when is a user changes tabs or returns.

0.0.1 - Initial activity monitoring.

idle.js's People

Contributors

glennvd avatar jarvizx avatar justintulloss avatar laurynasra avatar lihas avatar mkazlauskas avatar msanjdev avatar shawnmclean avatar snayagar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

idle.js's Issues

Document API

Library looks pretty solid, but it really needs documentation on the behavior and interface.

onfocus = active?

First, thanks for sharing this, very useful.

I was wondering... have you ever thought about raising the "back" or "active" event when the browser comes back in focus?

I'm asking because right now, if you switch window using ctrl-tab for example, when you come back to your browser, I'd like to see the active event firing back again.

Just a thought, great plugin!

Patrice

Document Supported Browsers

This script looks/works good, and I'm sure the documentation will come when you release a beta.

But when you get to that point (or sooner) please document the browsers you have tested in.

Tested http://shawnmclean.github.io/Idle.js/

PASS::
Windows 7:
Firefox 20.0.1
Chrome Version 27.0.1453.73 beta-m
IE 10

FAIL::
Windows XP:
IE 8

SCRIPT438: Object doesn't support property or method 'addEventListener'
idle.js, line 43 character 7

I've committed to compatibility down to ie8. Unfortunately this fails in ie8. To get rid of the above error i added:

        if (document.addEventListener) {
            document.addEventListener("visibilitychange", (function () {
                return activity.handleVisibilityChange();
            }), false);
            document.addEventListener("webkitvisibilitychange", (function () {
                return activity.handleVisibilityChange();
            }), false);
            document.addEventListener("msvisibilitychange", (function () {
                return activity.handleVisibilityChange();
            }), false);
        } else {
            document.attachEvent("onvisibilitychange", (function () {
                return activity.handleVisibilityChange();
            }));
        }

This will then run, but it doesn't work. I will see if i can figure out some more fixes.

ES6 and NPM packages

Hi @shawnmclean Thanks for providing IdleJS.

I am trying to integrate Idle in our applications, but I encountered some problems. We are using ES6/Webpack.

I download a copy of idle.js, when import it , none of the following are working.

import './idle';
import Idle from './idle';
import * as Idle from './idle';

Can you provide some suggestion?

BTW, I can not find this lib in NPM, it is not published to NPM?

startAwayTimeout does not exist

When building idle.js there is a call to startAwayTimeout() but this function doesn't exist.

Using the idle.js version from the live demo it works fine.

Idle.js interprets page navigation in Firefox as being "away"

If you go to http://shawnmclean.github.io/Idle.js/ in Firefox and refresh the page, you'll briefly see idle.js report that "User is not looking at page" before the page repaints. This is also happening in a dashboard app that I have whenever a user clicks on any link that takes them away from the dashboard - the "background polling paused" message I have setup is displayed for a second while Firefox is busy loading the new page.

Touch events support

It appears this lib doesn't take into account touch events (am I wrong?).

It would be nice.

vendor-prefixed `visibilitychange` event listener is called the second time in newer browsers

In the code for Idle.js, There are several vendor-prefixed events setup on the same listener for the visibilitychange event. This makes it fire twice in (newer) browsers that support both the older vendor-prefixed events and the newer unprefixed events. I have corrected this in my personal build of Idle.js and would have made a pull request but i don't know how to write coffeescript (which is the source language of choice for Idle.js ). However, here's my code snippet to remedy this in plain JavaScript

        if(typeof document.addEventListener === 'function'){
          
            if('hidden' in document &&
              !('webkitHidden' in document
                  || 'oHidden' in document
                    || 'mozHidden' in document
                        || 'msHidden' in document)){
                         document.addEventListener("visibilitychange", this.listener, false);
            }else{
                        document.addEventListener("webkitvisibilitychange", this.listener, false);
                        document.addEventListener("msvisibilitychange", this.listener, false);
            }
        }
        .
        .
        .
        if(typeof document.removeEventListener === 'function'){
            if('hidden' in document &&
                  !('webkitHidden' in document
                      || 'oHidden' in document
                        || 'mozHidden' in document
                            || 'msHidden' in document)){
                        document.removeEventListener("visibilitychange", this.listener);
            }else{
                       document.removeEventListener("webkitvisibilitychange", this.listener);
                       document.removeEventListener("msvisibilitychange", this.listener);
           }
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.