From 8b355eaba0aa1fc51c8284b02f3f9a6f7ab64410 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Mon, 20 May 2013 00:29:34 -0400 Subject: support vertical align of slides with absolute children --- js/reveal.js | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'js/reveal.js') diff --git a/js/reveal.js b/js/reveal.js index d4532ac..776cac9 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -535,6 +535,41 @@ var Reveal = (function(){ } + /** + * Retrieves the height of the given element by looking + * at the position and height of its immediate children. + */ + function getAbsoluteHeight( element ) { + + var height = 0; + + if( element ) { + var absoluteChildren = 0; + + toArray( element.childNodes ).forEach( function( child ) { + + if( typeof child.offsetTop === 'number' && child.style ) { + // Count # of abs children + if( child.style.position === 'absolute' ) { + absoluteChildren += 1; + } + + height = Math.max( height, child.offsetTop + child.offsetHeight ); + } + + } ); + + // If there are no absolute children, use offsetHeight + if( absoluteChildren === 0 ) { + height = element.offsetHeight; + } + + } + + return height; + + } + /** * Causes the address bar to hide on mobile devices, * more vertical space ftw. @@ -613,26 +648,6 @@ var Reveal = (function(){ } - /** - * Retrieves the height of the given element by looking - * at the position and height of its immediate children. - */ - function getAbsoluteHeight( element ) { - - var height = 0; - - if( element ) { - - toArray( element.childNodes ).forEach( function( child ) { - height = Math.max( height, child.offsetTop + child.offsetHeight ); - } ); - - } - - return height; - - } - /** * Bind preview frame links. */ -- cgit v1.2.3