shawnmclean / idle.js Goto Github PK
View Code? Open in Web Editor NEWJavascript activity library for the browser. (away, idle, etc)
License: Other
Javascript activity library for the browser. (away, idle, etc)
License: Other
Add a stop feature that pauses all timers.
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
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);
}
}
hey,
your project was featured on echo.js this weekend, but any and all links to it are broken since you renamed it to idle.js
just to let you know...
Sander
tested in IE11 with PDF and it does not work.
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.
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.
Library looks pretty solid, but it really needs documentation on the behavior and interface.
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?
test
I was curious what your thoughts are on triggering away events based on page visibility [1]
[1] http://www.nczonline.net/blog/2011/08/09/introduction-to-the-page-visibility-api/
Could you add bower support?
Thanks.
I think, it will be better to check if the window
object already have a value in onclick
, onmousemove
etc. to not override them:
https://github.com/shawnmclean/Idle.js/blob/master/src/idle.coffee#L52
Hi there, this library is nice. I tried to use it and i detected a problem. On Idle.prototype.onActive is still calling the function startAwayTimeout.
Thanks
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.
It appears this lib doesn't take into account touch events (am I wrong?).
It would be nice.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.