Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Featuretest pagevisibility #700

Merged
merged 1 commit into from

5 participants

@helgri

Added simple test for PageVisibility API support

Tested w/ Chrome Canary, FIrefox 15, Safari 6, IE9/10

feature-detects/pagevisibility-api.js
@@ -0,0 +1,12 @@
+Modernizr.addTest('pagevisibility', function(){
+ for(var i = 0, len = Modernizr._domPrefixes.length; i < len; ++i) {
+ if(typeof document[Modernizr._domPrefixes[i].toLowerCase() + "Hidden"] !== "undefined") {
@paulirish Owner

add one of these before this:

var prefix = Modernizr._domPrefixes[i].toLowerCase();

it'll look a lot better

@sindresorhus Collaborator

if (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
feature-detects/pagevisibility-api.js
@@ -0,0 +1,12 @@
+Modernizr.addTest('pagevisibility', function(){
+ for(var i = 0, len = Modernizr._domPrefixes.length; i < len; ++i) {
+ if(typeof document[Modernizr._domPrefixes[i].toLowerCase() + "Hidden"] !== "undefined") {
+ return true;
+ }
+ }
+ return typeof document["hidden"] !== "undefined";
+});
+
+
+//https://developer.mozilla.org/en-US/docs/DOM/Using_the_Page_Visibility_API
@paulirish Owner

can you move these to the top of the file and add a space after the // ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@paulirish
Owner

thanks. was just talking to @ebidel about how we didnt have this, surprisingly.

@paulirish
Owner

Could you quickly test in ie8 too?

feature-detects/pagevisibility-api.js
@@ -0,0 +1,12 @@
+Modernizr.addTest('pagevisibility', function(){
+ for(var i = 0, len = Modernizr._domPrefixes.length; i < len; ++i) {
@sindresorhus Collaborator

for (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@sindresorhus
Collaborator

and single-quotes

@helgri

added your change requests. test on IE8 works fine.

@joemarini

Doh! Just wrote one myself, didn't realize I was duplicating effort.

@helgri

is something still missing?

@paulirish
Owner
feature-detects/pagevisibility-api.js
@@ -0,0 +1,12 @@
+// https://developer.mozilla.org/en-US/docs/DOM/Using_the_Page_Visibility_API
+// http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html
+
+Modernizr.addTest('pagevisibility', function(){
+ for (var i = 0, len = Modernizr._domPrefixes.length; i < len; ++i) {
@sindresorhus Collaborator

Not that it makes a difference, but i++ is clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
feature-detects/pagevisibility-api.js
@@ -0,0 +1,12 @@
+// https://developer.mozilla.org/en-US/docs/DOM/Using_the_Page_Visibility_API
+// http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html
+
+Modernizr.addTest('pagevisibility', function(){
+ for (var i = 0, len = Modernizr._domPrefixes.length; i < len; ++i) {
+ var prefix = Modernizr._domPrefixes[i].toLowerCase();
+ if (typeof document[prefix + 'Hidden'] !== 'undefined') {
@sindresorhus Collaborator

I think this would be better and more in line with what's used elsewhere in Modernizr:

if (prefix + 'Hidden' in document) {

@sindresorhus Collaborator

Or even better, use the built in Modernizr.prefixed method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@helgri

Paul, the cake is a lie, but here you go :)


                        #,
                        ###
                       ## ##
                      ##  ##
                       ####
                         :
                        #####
                       ######
                       ##  ##
                       ##  ##
                       ##  ##
                       ##  ##########
                       ##  #############
                  #######  ###############
              #############################
        .###################################
       #####################################;
       ##                                 ##.
       ##                                 ##
       #####################################
       ##                                 ##
       ##                                 ##
       ##                                 ###
    #####                                 #####
   ### ##################################### ###
  ###  ##                                 ##  ###
  ##   ## ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ##   ##
   ##  #####################################  ##
    ##                                       ##
     ####                                 ####
       ######                         ######
          ###############################
@helgri

made ++i to i++

@helgri

@sindresorhus test is now using hidden in document

I think Modernizr.prefixed() doesn't work, because the value of document.hidden can be false by itself, does it?

@ryanseddon
Owner

@helgri if you do Modernizr.prefixed("hidden", document, false) that will either return [prefix]Hidden or false. The last argument will force a string rather than try and bind.

@helgri

@ryanseddon Oh, that's really convenient...

@ryanseddon
Owner

@helgri looks good can you squash your commits into one please. If you're not sure how to do that check out this post on commit squashing

@helgri

squashed like hell :)

@ryanseddon ryanseddon merged commit def11e6 into from
@ryanseddon
Owner

Thanks @helgri :thumbsup:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 4, 2012
  1. @helgri
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 0 deletions.
  1. +4 −0 feature-detects/pagevisibility-api.js
View
4 feature-detects/pagevisibility-api.js
@@ -0,0 +1,4 @@
+// https://developer.mozilla.org/en-US/docs/DOM/Using_the_Page_Visibility_API
+// http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html
+
+Modernizr.addTest('pagevisibility', !!Modernizr.prefixed("hidden", document, false));
Something went wrong with that request. Please try again.