aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2012-11-10 09:41:26 -0500
committerHakim El Hattab <hakim.elhattab@gmail.com>2012-11-10 09:41:26 -0500
commit691099c6a25861405f067d3b1f7c669c4642a535 (patch)
tree4277c39f8054f66eda7fe9f3aeb8c016abc93873 /js
parentf51067b00e8099bb576858e70db6e2fc44ce3d61 (diff)
downloadperl-software-in-gnu-guix-691099c6a25861405f067d3b1f7c669c4642a535.tar
perl-software-in-gnu-guix-691099c6a25861405f067d3b1f7c669c4642a535.tar.gz
rough support for vertical centering #70
Diffstat (limited to 'js')
-rw-r--r--js/reveal.js50
1 files changed, 48 insertions, 2 deletions
diff --git a/js/reveal.js b/js/reveal.js
index d92ee76..a1683ec 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -29,6 +29,8 @@ var Reveal = (function(){
// Enable the slide overview mode
overview: true,
+ center: false,
+
// Loop the presentation
loop: false,
@@ -264,6 +266,10 @@ var Reveal = (function(){
// Updates the presentation to match the current configuration values
configure();
+ // Force an initial layout, will thereafter be invoked as the window
+ // is resized
+ layout();
+
// Read the initial hash
readURL();
@@ -301,6 +307,10 @@ var Reveal = (function(){
dom.wrapper.classList.add( config.transition );
}
+ if( config.center ) {
+ dom.wrapper.classList.add( 'center' );
+ }
+
if( config.mouseWheel ) {
document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
@@ -332,6 +342,7 @@ var Reveal = (function(){
document.addEventListener( 'touchmove', onDocumentTouchMove, false );
document.addEventListener( 'touchend', onDocumentTouchEnd, false );
window.addEventListener( 'hashchange', onWindowHashChange, false );
+ window.addEventListener( 'resize', onWindowResize, false );
if( config.keyboard ) {
document.addEventListener( 'keydown', onDocumentKeyDown, false );
@@ -358,6 +369,7 @@ var Reveal = (function(){
document.removeEventListener( 'touchmove', onDocumentTouchMove, false );
document.removeEventListener( 'touchend', onDocumentTouchEnd, false );
window.removeEventListener( 'hashchange', onWindowHashChange, false );
+ window.removeEventListener( 'resize', onWindowResize, false );
if ( config.progress && dom.progress ) {
dom.progress.removeEventListener( 'click', preventAndForward( onProgressClick ), false );
@@ -449,6 +461,33 @@ var Reveal = (function(){
}
/**
+ * Applies JavaScript-controlled layout rules to the
+ * presentation.
+ */
+ function layout() {
+ if( config.center ) {
+
+ // Select all slides, vertical and horizontal
+ var slides = Array.prototype.slice.call( document.querySelectorAll( '.reveal .slides section' ) );
+
+ // Determine the minimum top offset for slides
+ var minTop = -dom.wrapper.offsetHeight / 2;
+
+ for( var i = 0, len = slides.length; i < len; i++ ) {
+ var slide = slides[ i ];
+
+ if( slide.classList.contains( 'stack' ) ) {
+ slide.style.marginTop = 0;
+ }
+ else {
+ slide.style.marginTop = Math.max( - ( slide.offsetHeight / 2 ) - 20, minTop ) + 'px';
+ }
+ }
+
+ }
+ }
+
+ /**
* Displays the overview of slides (quick nav) by
* scaling down and arranging all slide elements.
*
@@ -643,6 +682,8 @@ var Reveal = (function(){
indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
+ layout();
+
// Apply the new state
stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
// Check if this state existed on the previous slide. If it
@@ -1284,14 +1325,19 @@ var Reveal = (function(){
/**
* Handler for the window level 'hashchange' event.
- *
- * @param {Object} event
*/
function onWindowHashChange( event ) {
readURL();
}
/**
+ * Handler for the window level 'resize' event.
+ */
+ function onWindowResize( event ) {
+ layout();
+ }
+
+ /**
* Invoked when a slide is and we're in the overview.
*/
function onOverviewSlideClicked( event ) {