diff options
Diffstat (limited to 'js/reveal.js')
-rw-r--r-- | js/reveal.js | 101 |
1 files changed, 55 insertions, 46 deletions
diff --git a/js/reveal.js b/js/reveal.js index d425a87..a4187e7 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -44,7 +44,7 @@ var Reveal = (function(){ // Enable the slide overview mode overview: true, - // Vertical centering of slides + // Vertical centring of slides center: true, // Enables touch navigation on devices with touch input @@ -77,11 +77,10 @@ var Reveal = (function(){ dependencies: [] }, - // Stores if the next slide should be shown automatically - // after n milliseconds - autoSlide = config.autoSlide, + // The current auto-slide duration + autoSlide = 0, - // The horizontal and verical index of the currently active slide + // The horizontal and vertical index of the currently active slide indexh = 0, indexv = 0, @@ -276,7 +275,7 @@ var Reveal = (function(){ } } - // Called once synchronous scritps finish loading + // Called once synchronous scripts finish loading function proceed() { if( scriptsAsync.length ) { // Load asynchronous scripts @@ -316,9 +315,6 @@ var Reveal = (function(){ // Read the initial hash readURL(); - // Start auto-sliding if it's enabled - cueAutoSlide(); - // Notify listeners that the presentation is ready but use a 1ms // timeout to ensure it's not fired synchronously after #initialize() setTimeout( function() { @@ -347,8 +343,13 @@ var Reveal = (function(){ dom.wrapper.classList.add( config.transition ); - dom.controls.style.display = ( config.controls && dom.controls ) ? 'block' : 'none'; - dom.progress.style.display = ( config.progress && dom.progress ) ? 'block' : 'none'; + if( dom.controls ) { + dom.controls.style.display = ( config.controls && dom.controls ) ? 'block' : 'none'; + } + + if( dom.progress ) { + dom.progress.style.display = ( config.progress && dom.progress ) ? 'block' : 'none'; + } if( config.rtl ) { dom.wrapper.classList.add( 'rtl' ); @@ -396,6 +397,12 @@ var Reveal = (function(){ // Force a layout to make sure the current config is accounted for layout(); + // Reflect the current autoSlide value + autoSlide = config.autoSlide; + + // Start auto-sliding if it's enabled + cueAutoSlide(); + } /** @@ -409,9 +416,9 @@ var Reveal = (function(){ window.addEventListener( 'resize', onWindowResize, false ); if( config.touch ) { - document.addEventListener( 'touchstart', onDocumentTouchStart, false ); - document.addEventListener( 'touchmove', onDocumentTouchMove, false ); - document.addEventListener( 'touchend', onDocumentTouchEnd, false ); + dom.wrapper.addEventListener( 'touchstart', onTouchStart, false ); + dom.wrapper.addEventListener( 'touchmove', onTouchMove, false ); + dom.wrapper.addEventListener( 'touchend', onTouchEnd, false ); } if( config.keyboard ) { @@ -423,13 +430,14 @@ var Reveal = (function(){ } if ( config.controls && dom.controls ) { - var actionEvent = 'ontouchstart' in window && window.ontouchstart != null ? 'touchstart' : 'click'; - dom.controlsLeft.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateLeftClicked, false ); } ); - dom.controlsRight.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateRightClicked, false ); } ); - dom.controlsUp.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateUpClicked, false ); } ); - dom.controlsDown.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateDownClicked, false ); } ); - dom.controlsPrev.forEach( function( el ) { el.addEventListener( actionEvent, onNavigatePrevClicked, false ); } ); - dom.controlsNext.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateNextClicked, false ); } ); + [ 'touchstart', 'click' ].forEach( function( eventName ) { + dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } ); + dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } ); + dom.controlsUp.forEach( function( el ) { el.addEventListener( eventName, onNavigateUpClicked, false ); } ); + dom.controlsDown.forEach( function( el ) { el.addEventListener( eventName, onNavigateDownClicked, false ); } ); + dom.controlsPrev.forEach( function( el ) { el.addEventListener( eventName, onNavigatePrevClicked, false ); } ); + dom.controlsNext.forEach( function( el ) { el.addEventListener( eventName, onNavigateNextClicked, false ); } ); + } ); } } @@ -446,9 +454,9 @@ var Reveal = (function(){ window.removeEventListener( 'resize', onWindowResize, false ); if( config.touch ) { - document.removeEventListener( 'touchstart', onDocumentTouchStart, false ); - document.removeEventListener( 'touchmove', onDocumentTouchMove, false ); - document.removeEventListener( 'touchend', onDocumentTouchEnd, false ); + dom.wrapper.removeEventListener( 'touchstart', onTouchStart, false ); + dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false ); + dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false ); } if ( config.progress && dom.progress ) { @@ -456,13 +464,14 @@ var Reveal = (function(){ } if ( config.controls && dom.controls ) { - var actionEvent = 'ontouchstart' in window && window.ontouchstart != null ? 'touchstart' : 'click'; - dom.controlsLeft.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateLeftClicked, false ); } ); - dom.controlsRight.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateRightClicked, false ); } ); - dom.controlsUp.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateUpClicked, false ); } ); - dom.controlsDown.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateDownClicked, false ); } ); - dom.controlsPrev.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigatePrevClicked, false ); } ); - dom.controlsNext.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateNextClicked, false ); } ); + [ 'touchstart', 'click' ].forEach( function( eventName ) { + dom.controlsLeft.forEach( function( el ) { el.removeEventListener( eventName, onNavigateLeftClicked, false ); } ); + dom.controlsRight.forEach( function( el ) { el.removeEventListener( eventName, onNavigateRightClicked, false ); } ); + dom.controlsUp.forEach( function( el ) { el.removeEventListener( eventName, onNavigateUpClicked, false ); } ); + dom.controlsDown.forEach( function( el ) { el.removeEventListener( eventName, onNavigateDownClicked, false ); } ); + dom.controlsPrev.forEach( function( el ) { el.removeEventListener( eventName, onNavigatePrevClicked, false ); } ); + dom.controlsNext.forEach( function( el ) { el.removeEventListener( eventName, onNavigateNextClicked, false ); } ); + } ); } } @@ -626,7 +635,7 @@ var Reveal = (function(){ var availableWidth = dom.wrapper.offsetWidth, availableHeight = dom.wrapper.offsetHeight; - // Reduce availabe space by margin + // Reduce available space by margin availableWidth -= ( availableHeight * config.margin ); availableHeight -= ( availableHeight * config.margin ); @@ -682,7 +691,7 @@ var Reveal = (function(){ } if( config.center ) { - // Vertical stacks are not centered since their section + // Vertical stacks are not centred since their section // children will be if( slide.classList.contains( 'stack' ) ) { slide.style.top = 0; @@ -711,7 +720,7 @@ var Reveal = (function(){ */ function setPreviousVerticalIndex( stack, v ) { - if( stack ) { + if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) { stack.setAttribute( 'data-previous-indexv', v || 0 ); } @@ -726,7 +735,7 @@ var Reveal = (function(){ */ function getPreviousVerticalIndex( stack ) { - if( stack && stack.classList.contains( 'stack' ) ) { + if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) { return parseInt( stack.getAttribute( 'data-previous-indexv' ) || 0, 10 ); } @@ -1317,8 +1326,8 @@ var Reveal = (function(){ verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR ); return { - left: indexh > 0, - right: indexh < horizontalSlides.length - 1, + left: indexh > 0 || config.loop, + right: indexh < horizontalSlides.length - 1 || config.loop, up: indexv > 0, down: indexv < verticalSlides.length - 1 }; @@ -1536,7 +1545,7 @@ var Reveal = (function(){ function navigateLeft() { // Prioritize hiding fragments - if( availableRoutes().left && isOverview() || previousFragment() === false ) { + if( availableRoutes().left && ( isOverview() || previousFragment() === false ) ) { slide( indexh - 1 ); } @@ -1545,7 +1554,7 @@ var Reveal = (function(){ function navigateRight() { // Prioritize revealing fragments - if( availableRoutes().right && isOverview() || nextFragment() === false ) { + if( availableRoutes().right && ( isOverview() || nextFragment() === false ) ) { slide( indexh + 1 ); } @@ -1688,10 +1697,10 @@ var Reveal = (function(){ } /** - * Handler for the document level 'touchstart' event, - * enables support for swipe and pinch gestures. + * Handler for the 'touchstart' event, enables support for + * swipe and pinch gestures. */ - function onDocumentTouchStart( event ) { + function onTouchStart( event ) { touch.startX = event.touches[0].clientX; touch.startY = event.touches[0].clientY; @@ -1712,9 +1721,9 @@ var Reveal = (function(){ } /** - * Handler for the document level 'touchmove' event. + * Handler for the 'touchmove' event. */ - function onDocumentTouchMove( event ) { + function onTouchMove( event ) { // Each touch should only trigger one action if( !touch.handled ) { @@ -1786,9 +1795,9 @@ var Reveal = (function(){ } /** - * Handler for the document level 'touchend' event. + * Handler for the 'touchend' event. */ - function onDocumentTouchEnd( event ) { + function onTouchEnd( event ) { touch.handled = false; |