public
Created

Modernizr Test 'fullscreen'

  • Download Gist
modernizr_fullscreen.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
Modernizr.addTest('fullscreen',function(){
var ancelFullScreen = 'ancelFullScreen'; //make string minifiable
var limit = Modernizr._domPrefixes.length;
for(var i = 0; i < limit; ++i) {
if( document[Modernizr._domPrefixes[i].toLowerCase() + 'C' + ancelFullScreen])
return true;
}
return !!document['c' + ancelFullScreen] || false;
});
 
 
// solution 2 with FF9 handling and minify and speed improvements
 
Modernizr.addTest('fullscreen',function(){
var ancelFullScreen = 'ancelFullScreen'; //make string minifiable
//FF9 pre-check
if(document.mozCancelFullScreen && !document.mozFullScreenEnabled) return false;
var limit = Modernizr._domPrefixes.length;
for(var i = 0; i < limit; ++i) {
if( document[[Modernizr._domPrefixes[i].toLowerCase(),'C',ancelFullScreen].join('')])
return true;
}
return !!document[['c',ancelFullScreen].join('')] || false;
});
 
 
 
//http://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/ControllingMediaWithJavaScript/ControllingMediaWithJavaScript.html#//apple_ref/doc/uid/TP40009523-CH3-SW20
//https://developer.mozilla.org/en/API/Fullscreen

needs to test unprefixed too.

pull request plzz

ok. will add it tomorrow and then i'll make a pull request

added unprefixed test and made pull-request

Although it's not being implemented yet, I'm wondering if you should be testing for "exitFullscreen" as well (per the W3C Spec http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html).

@paulirish pull request is still open ;)

@darcyclarke webkit and mozilla are using "cancelFullScreen". i think it's sufficient to test for this... If necessary we could add it later to the test. I think less code is better than über-testing.

i'm happy to test less as long as there are no inconsistencies.
PR was pulled.

@helgri I think the term "über-testing" isn't quite right. Testing for properly implemented, to spec, fullscreen support seems like a reasonable expectation. Doesn't look like the method names are changing, in the spec, so I'd expect to see proper implementations, by teams like Opera, sooner then later. Either way, thanks for making a pull request for this (as I was about to before I found this gist).

In Firefox 9 the fullscreen API is disabled by default, while document.mozCancelFullScreen is defined, so this test will return true even when the API isn't enabled.

According to https://bugzilla.mozilla.org/show_bug.cgi?id=694690 an API will be introduced in FF10 so document.mozFullScreenEnabled will indicate whether the fullscreen API is enabled or not. If it's not defined (which is the case for FF9) it can be enabled by the user.

I don't see any possibility to check whether the user has activated the fullscreen mode in Firefox or not. Do you?

rainboxx can you ask on the bug ticket what the engineer's recommendation is for feature detection?

Paul, they already say:

We added an API which enables websites like YouTube to determine whether the full-screen API is enabled (document.mozFullScreenEnabled) but that's in Firefox 10, it is not available in Firefox 9. However websites can test to see if document.mozFullScreenEnabled is defined and if not can just assume that the full-screen API is not enabled by default in that build.

See Comment 20 for details: https://bugzilla.mozilla.org/show_bug.cgi?id=694690#c20

Hi guys,

I added a second way.

It's pre-testing FF9 now. It's also more optimized for minifying and speed.

Please have a look. If's ok for all, I will make a Pull-Request.

Still prefer to not support FF9, because FF10 is coming soon...
Again not adding "ExitFullScreen" because no browser is using it

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.