Permalink
Browse files

Use feature detection for visibility API

  • Loading branch information...
1 parent 2795010 commit 4e69157631d277c04a78deacabada2e312a3de4e @nzakas committed Aug 13, 2012
@@ -38,7 +38,7 @@ function handleUserEvent(event){
if (enabled){
if (/visibilitychange/.test(event.type)){
- toggleIdleState(doc.hidden || doc.msHidden || doc.webkitHidden);
+ toggleIdleState(doc.hidden || doc.msHidden || doc.webkitHidden || doc.mozHidden);
} else {
//if it's idle, that means the user is no longer idle
if (idle){
@@ -133,8 +133,11 @@ Y.IdleTimer = {
Y.on("keydown", handleUserEvent, doc);
//need to add the old-fashioned way
- doc.addEventListener("msvisibilitychange", handleUserEvent, false)
- doc.addEventListener("webkitvisibilitychange", handleUserEvent, false)
+ if (doc.addEventListener) {
+ doc.addEventListener("msvisibilitychange", handleUserEvent, false);
+ doc.addEventListener("webkitvisibilitychange", handleUserEvent, false);
+ doc.addEventListener("mozvisibilitychange", handleUserEvent, false);
+ }
//set a timeout to toggle state
tId = setTimeout(toggleIdleState, timeout);
@@ -159,8 +162,11 @@ Y.IdleTimer = {
Y.detach("mousemove", handleUserEvent, doc);
Y.detach("keydown", handleUserEvent, doc);
- doc.removeEventListener("msvisibilitychange", handleUserEvent, false)
- doc.removeEventListener("webkitvisibilitychange", handleUserEvent, false)
+ if (doc.removeEventListener) {
+ doc.removeEventListener("msvisibilitychange", handleUserEvent, false);
+ doc.removeEventListener("webkitvisibilitychange", handleUserEvent, false);
+ doc.removeEventListener("mozvisibilitychange", handleUserEvent, false);
+ }
}
Oops, something went wrong.
@@ -38,7 +38,7 @@ function handleUserEvent(event){
if (enabled){
if (/visibilitychange/.test(event.type)){
- toggleIdleState(doc.hidden || doc.msHidden || doc.webkitHidden);
+ toggleIdleState(doc.hidden || doc.msHidden || doc.webkitHidden || doc.mozHidden);
} else {
//if it's idle, that means the user is no longer idle
if (idle){
@@ -133,8 +133,11 @@ Y.IdleTimer = {
Y.on("keydown", handleUserEvent, doc);
//need to add the old-fashioned way
- doc.addEventListener("msvisibilitychange", handleUserEvent, false)
- doc.addEventListener("webkitvisibilitychange", handleUserEvent, false)
+ if (doc.addEventListener) {
+ doc.addEventListener("msvisibilitychange", handleUserEvent, false);
+ doc.addEventListener("webkitvisibilitychange", handleUserEvent, false);
+ doc.addEventListener("mozvisibilitychange", handleUserEvent, false);
+ }
//set a timeout to toggle state
tId = setTimeout(toggleIdleState, timeout);
@@ -159,8 +162,11 @@ Y.IdleTimer = {
Y.detach("mousemove", handleUserEvent, doc);
Y.detach("keydown", handleUserEvent, doc);
- doc.removeEventListener("msvisibilitychange", handleUserEvent, false)
- doc.removeEventListener("webkitvisibilitychange", handleUserEvent, false)
+ if (doc.removeEventListener) {
+ doc.removeEventListener("msvisibilitychange", handleUserEvent, false);
+ doc.removeEventListener("webkitvisibilitychange", handleUserEvent, false);
+ doc.removeEventListener("mozvisibilitychange", handleUserEvent, false);
+ }
}
@@ -131,9 +131,11 @@ Y.IdleTimer = {
Y.on("keydown", handleUserEvent, doc);
//need to add the old-fashioned way
- doc.addEventListener("msvisibilitychange", handleUserEvent, false)
- doc.addEventListener("webkitvisibilitychange", handleUserEvent, false)
- doc.addEventListener("mozvisibilitychange", handleUserEvent, false)
+ if (doc.addEventListener) {
+ doc.addEventListener("msvisibilitychange", handleUserEvent, false);
+ doc.addEventListener("webkitvisibilitychange", handleUserEvent, false);
+ doc.addEventListener("mozvisibilitychange", handleUserEvent, false);
+ }
//set a timeout to toggle state
tId = setTimeout(toggleIdleState, timeout);
@@ -158,9 +160,11 @@ Y.IdleTimer = {
Y.detach("mousemove", handleUserEvent, doc);
Y.detach("keydown", handleUserEvent, doc);
- doc.removeEventListener("msvisibilitychange", handleUserEvent, false)
- doc.removeEventListener("webkitvisibilitychange", handleUserEvent, false)
- doc.removeEventListener("mozvisibilitychange", handleUserEvent, false)
+ if (doc.removeEventListener) {
+ doc.removeEventListener("msvisibilitychange", handleUserEvent, false);
+ doc.removeEventListener("webkitvisibilitychange", handleUserEvent, false);
+ doc.removeEventListener("mozvisibilitychange", handleUserEvent, false);
+ }
}

0 comments on commit 4e69157

Please sign in to comment.