fix error in how touch support was detected

This commit is contained in:
Hakim El Hattab 2013-03-04 17:30:28 -05:00
parent 0926be9781
commit ee7d36a044
2 changed files with 31 additions and 29 deletions

View File

@ -416,9 +416,9 @@ var Reveal = (function(){
window.addEventListener( 'resize', onWindowResize, false ); window.addEventListener( 'resize', onWindowResize, false );
if( config.touch ) { if( config.touch ) {
document.addEventListener( 'touchstart', onDocumentTouchStart, false ); dom.wrapper.addEventListener( 'touchstart', onTouchStart, false );
document.addEventListener( 'touchmove', onDocumentTouchMove, false ); dom.wrapper.addEventListener( 'touchmove', onTouchMove, false );
document.addEventListener( 'touchend', onDocumentTouchEnd, false ); dom.wrapper.addEventListener( 'touchend', onTouchEnd, false );
} }
if( config.keyboard ) { if( config.keyboard ) {
@ -430,13 +430,14 @@ var Reveal = (function(){
} }
if ( config.controls && dom.controls ) { if ( config.controls && dom.controls ) {
var actionEvent = 'ontouchstart' in window && window.ontouchstart != null ? 'touchstart' : 'click'; [ 'touchstart', 'click' ].forEach( function( eventName ) {
dom.controlsLeft.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateLeftClicked, false ); } ); dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } );
dom.controlsRight.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateRightClicked, false ); } ); dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } );
dom.controlsUp.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateUpClicked, false ); } ); dom.controlsUp.forEach( function( el ) { el.addEventListener( eventName, onNavigateUpClicked, false ); } );
dom.controlsDown.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateDownClicked, false ); } ); dom.controlsDown.forEach( function( el ) { el.addEventListener( eventName, onNavigateDownClicked, false ); } );
dom.controlsPrev.forEach( function( el ) { el.addEventListener( actionEvent, onNavigatePrevClicked, false ); } ); dom.controlsPrev.forEach( function( el ) { el.addEventListener( eventName, onNavigatePrevClicked, false ); } );
dom.controlsNext.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateNextClicked, false ); } ); dom.controlsNext.forEach( function( el ) { el.addEventListener( eventName, onNavigateNextClicked, false ); } );
} );
} }
} }
@ -453,9 +454,9 @@ var Reveal = (function(){
window.removeEventListener( 'resize', onWindowResize, false ); window.removeEventListener( 'resize', onWindowResize, false );
if( config.touch ) { if( config.touch ) {
document.removeEventListener( 'touchstart', onDocumentTouchStart, false ); dom.wrapper.removeEventListener( 'touchstart', onTouchStart, false );
document.removeEventListener( 'touchmove', onDocumentTouchMove, false ); dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false );
document.removeEventListener( 'touchend', onDocumentTouchEnd, false ); dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false );
} }
if ( config.progress && dom.progress ) { if ( config.progress && dom.progress ) {
@ -463,13 +464,14 @@ var Reveal = (function(){
} }
if ( config.controls && dom.controls ) { if ( config.controls && dom.controls ) {
var actionEvent = 'ontouchstart' in window && window.ontouchstart != null ? 'touchstart' : 'click'; [ 'touchstart', 'click' ].forEach( function( eventName ) {
dom.controlsLeft.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateLeftClicked, false ); } ); dom.controlsLeft.forEach( function( el ) { el.removeEventListener( eventName, onNavigateLeftClicked, false ); } );
dom.controlsRight.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateRightClicked, false ); } ); dom.controlsRight.forEach( function( el ) { el.removeEventListener( eventName, onNavigateRightClicked, false ); } );
dom.controlsUp.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateUpClicked, false ); } ); dom.controlsUp.forEach( function( el ) { el.removeEventListener( eventName, onNavigateUpClicked, false ); } );
dom.controlsDown.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateDownClicked, false ); } ); dom.controlsDown.forEach( function( el ) { el.removeEventListener( eventName, onNavigateDownClicked, false ); } );
dom.controlsPrev.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigatePrevClicked, false ); } ); dom.controlsPrev.forEach( function( el ) { el.removeEventListener( eventName, onNavigatePrevClicked, false ); } );
dom.controlsNext.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateNextClicked, false ); } ); dom.controlsNext.forEach( function( el ) { el.removeEventListener( eventName, onNavigateNextClicked, false ); } );
} );
} }
} }
@ -1695,10 +1697,10 @@ var Reveal = (function(){
} }
/** /**
* Handler for the document level 'touchstart' event, * Handler for the 'touchstart' event, enables support for
* enables support for swipe and pinch gestures. * swipe and pinch gestures.
*/ */
function onDocumentTouchStart( event ) { function onTouchStart( event ) {
touch.startX = event.touches[0].clientX; touch.startX = event.touches[0].clientX;
touch.startY = event.touches[0].clientY; touch.startY = event.touches[0].clientY;
@ -1719,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 // Each touch should only trigger one action
if( !touch.handled ) { if( !touch.handled ) {
@ -1793,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; touch.handled = false;

4
js/reveal.min.js vendored

File diff suppressed because one or more lines are too long