Featuretest pagevisibility #700

Merged
merged 1 commit into from Oct 5, 2012

Conversation

Projects
None yet
5 participants
Contributor

helgri commented Sep 23, 2012

Added simple test for PageVisibility API support

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

@paulirish paulirish and 1 other commented on an outdated diff Sep 23, 2012

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

paulirish Sep 23, 2012

Owner

add one of these before this:

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

it'll look a lot better

@paulirish paulirish commented on an outdated diff Sep 23, 2012

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

paulirish Sep 23, 2012

Owner

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

Owner

paulirish commented Sep 23, 2012

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

Owner

paulirish commented Sep 23, 2012

Could you quickly test in ie8 too?

@sindresorhus sindresorhus commented on an outdated diff Sep 23, 2012

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

sindresorhus commented Sep 23, 2012

and single-quotes

Contributor

helgri commented Sep 23, 2012

added your change requests. test on IE8 works fine.

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

Contributor

helgri commented Sep 26, 2012

is something still missing?

Owner

paulirish commented Sep 26, 2012

yeah that slice of pie you promised to get me to accept your PR instead of
joe's!

@sindresorhus sindresorhus commented on an outdated diff Sep 28, 2012

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

sindresorhus Sep 28, 2012

Member

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

@sindresorhus sindresorhus commented on an outdated diff Sep 28, 2012

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

sindresorhus Sep 28, 2012

Member

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

if (prefix + 'Hidden' in document) {

@sindresorhus

sindresorhus Sep 28, 2012

Member

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

Contributor

helgri commented Sep 28, 2012

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


                        #,
                        ###
                       ## ##
                      ##  ##
                       ####
                         :
                        #####
                       ######
                       ##  ##
                       ##  ##
                       ##  ##
                       ##  ##########
                       ##  #############
                  #######  ###############
              #############################
        .###################################
       #####################################;
       ##                                 ##.
       ##                                 ##
       #####################################
       ##                                 ##
       ##                                 ##
       ##                                 ###
    #####                                 #####
   ### ##################################### ###
  ###  ##                                 ##  ###
  ##   ## ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ##   ##
   ##  #####################################  ##
    ##                                       ##
     ####                                 ####
       ######                         ######
          ###############################
Contributor

helgri commented Sep 28, 2012

made ++i to i++

Contributor

helgri commented Sep 28, 2012

@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?

Owner

ryanseddon commented Oct 1, 2012

@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.

Contributor

helgri commented Oct 1, 2012

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

Owner

ryanseddon commented Oct 4, 2012

@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

Contributor

helgri commented Oct 4, 2012

squashed like hell :)

@ryanseddon ryanseddon added a commit that referenced this pull request Oct 5, 2012

@ryanseddon ryanseddon Merge pull request #700 from helgri/featuretest-pagevisibility
Feature detect for Page Visibility API
def11e6

@ryanseddon ryanseddon merged commit def11e6 into Modernizr:master Oct 5, 2012

1 check passed

default The Travis build passed
Details
Owner

ryanseddon commented Oct 5, 2012

Thanks @helgri 👍

@patrickkettner patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this pull request Feb 22, 2015

@ryanseddon ryanseddon Merge pull request #700 from helgri/featuretest-pagevisibility
Feature detect for Page Visibility API
245b6cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment