diff options
Diffstat (limited to 'js/reveal.js')
-rw-r--r-- | js/reveal.js | 135 |
1 files changed, 94 insertions, 41 deletions
diff --git a/js/reveal.js b/js/reveal.js index 72f68cb..b767594 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -77,9 +77,8 @@ 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 vertical index of the currently active slide indexh = 0, @@ -160,9 +159,9 @@ var Reveal = (function(){ // Copy options over to our config object extend( config, options ); - + // Push up globals - window.globals = config.globals + window.globals = config.globals; // Hide the address bar in mobile browsers hideAddressBar(); @@ -319,9 +318,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() { @@ -404,6 +400,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(); + } /** @@ -417,9 +419,16 @@ 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 ); + + // Support pointer-style touch interaction as well + if( window.navigator.msPointerEnabled ) { + dom.wrapper.addEventListener( 'MSPointerDown', onPointerDown, false ); + dom.wrapper.addEventListener( 'MSPointerMove', onPointerMove, false ); + dom.wrapper.addEventListener( 'MSPointerUp', onPointerUp, false ); + } } if( config.keyboard ) { @@ -431,13 +440,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 ); } ); + } ); } } @@ -454,9 +464,15 @@ 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( window.navigator.msPointerEnabled ) { + dom.wrapper.removeEventListener( 'MSPointerDown', onPointerDown, false ); + dom.wrapper.removeEventListener( 'MSPointerMove', onPointerMove, false ); + dom.wrapper.removeEventListener( 'MSPointerUp', onPointerUp, false ); + } } if ( config.progress && dom.progress ) { @@ -464,13 +480,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 ); } ); + } ); } } @@ -719,7 +736,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 ); } @@ -734,7 +751,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 ); } @@ -1327,8 +1344,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 }; @@ -1546,7 +1563,7 @@ var Reveal = (function(){ function navigateLeft() { // Prioritize hiding fragments - if( availableRoutes().left && isOverview() || previousFragment() === false ) { + if( availableRoutes().left && ( isOverview() || previousFragment() === false ) ) { slide( indexh - 1 ); } @@ -1555,7 +1572,7 @@ var Reveal = (function(){ function navigateRight() { // Prioritize revealing fragments - if( availableRoutes().right && isOverview() || nextFragment() === false ) { + if( availableRoutes().right && ( isOverview() || nextFragment() === false ) ) { slide( indexh + 1 ); } @@ -1698,10 +1715,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; @@ -1722,9 +1739,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 ) { @@ -1796,15 +1813,51 @@ var Reveal = (function(){ } /** - * Handler for the document level 'touchend' event. + * Handler for the 'touchend' event. */ - function onDocumentTouchEnd( event ) { + function onTouchEnd( event ) { touch.handled = false; } /** + * Convert pointer down to touch start. + */ + function onPointerDown( event ) { + + if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) { + event.touches = [{ clientX: event.clientX, clientY: event.clientY }]; + onTouchStart( event ); + } + + } + + /** + * Convert pointer move to touch move. + */ + function onPointerMove( event ) { + + if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) { + event.touches = [{ clientX: event.clientX, clientY: event.clientY }]; + onTouchMove( event ); + } + + } + + /** + * Convert pointer up to touch end. + */ + function onPointerUp( event ) { + + if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) { + event.touches = [{ clientX: event.clientX, clientY: event.clientY }]; + onTouchEnd( event ); + } + + } + + /** * Handles mouse wheel scrolling, throttled to avoid skipping * multiple slides. */ |