delay client capability test until initialization phase

edit
Hakim El Hattab 2013-08-10 13:10:48 -04:00
parent 7b5e537157
commit 8ad81aa1a5
2 changed files with 34 additions and 17 deletions

View File

@ -14,8 +14,6 @@ var Reveal = (function(){
VERTICAL_SLIDES_SELECTOR = '.reveal .slides>section.present>section', VERTICAL_SLIDES_SELECTOR = '.reveal .slides>section.present>section',
HOME_SLIDE_SELECTOR = '.reveal .slides>section:first-child', HOME_SLIDE_SELECTOR = '.reveal .slides>section:first-child',
IS_MOBILE = navigator.userAgent.match( /(iphone|ipod|android)/gi ),
// Configurations defaults, can be overridden at initialization time // Configurations defaults, can be overridden at initialization time
config = { config = {
@ -113,19 +111,14 @@ var Reveal = (function(){
// Cached references to DOM elements // Cached references to DOM elements
dom = {}, dom = {},
// Detect support for CSS 3D transforms // Client support for CSS 3D transforms, see #checkCapabilities()
supports3DTransforms = 'WebkitPerspective' in document.body.style || supports3DTransforms,
'MozPerspective' in document.body.style ||
'msPerspective' in document.body.style ||
'OPerspective' in document.body.style ||
'perspective' in document.body.style,
// Detect support for CSS 2D transforms // Client support for CSS 2D transforms, see #checkCapabilities()
supports2DTransforms = 'WebkitTransform' in document.body.style || supports2DTransforms,
'MozTransform' in document.body.style ||
'msTransform' in document.body.style || // Client is a mobile device, see #checkCapabilities()
'OTransform' in document.body.style || isMobileDevice,
'transform' in document.body.style,
// Throttles mouse wheel navigation // Throttles mouse wheel navigation
lastMouseWheelStep = 0, lastMouseWheelStep = 0,
@ -160,6 +153,8 @@ var Reveal = (function(){
*/ */
function initialize( options ) { function initialize( options ) {
checkCapabilities();
if( !supports2DTransforms && !supports3DTransforms ) { if( !supports2DTransforms && !supports3DTransforms ) {
document.body.setAttribute( 'class', 'no-transforms' ); document.body.setAttribute( 'class', 'no-transforms' );
@ -182,6 +177,28 @@ var Reveal = (function(){
} }
/**
* Inspect the client to see what it's capable of, this
* should only happens once per runtime.
*/
function checkCapabilities() {
supports3DTransforms = 'WebkitPerspective' in document.body.style ||
'MozPerspective' in document.body.style ||
'msPerspective' in document.body.style ||
'OPerspective' in document.body.style ||
'perspective' in document.body.style;
supports2DTransforms = 'WebkitTransform' in document.body.style ||
'MozTransform' in document.body.style ||
'msTransform' in document.body.style ||
'OTransform' in document.body.style ||
'transform' in document.body.style;
isMobileDevice = navigator.userAgent.match( /(iphone|ipod|android)/gi );
}
/** /**
* Finds and stores references to DOM elements which are * Finds and stores references to DOM elements which are
* required by the presentation. If a required element is * required by the presentation. If a required element is
@ -1569,7 +1586,7 @@ var Reveal = (function(){
var threshold = 3; var threshold = 3;
// Heavily limited on weaker devices // Heavily limited on weaker devices
if( IS_MOBILE ) { if( isMobileDevice ) {
threshold = 1; threshold = 1;
} }

4
js/reveal.min.js vendored

File diff suppressed because one or more lines are too long