diff options
author | Hakim El Hattab <hakim.elhattab@gmail.com> | 2012-10-20 12:51:12 -0400 |
---|---|---|
committer | Hakim El Hattab <hakim.elhattab@gmail.com> | 2012-10-20 12:51:12 -0400 |
commit | 3241cb78d8f3d9fba19e8438df50bd29d0d0bc02 (patch) | |
tree | 034d9f58077e5c824a353344b17bff8a758c85ec /js/reveal.js | |
parent | ecb4347ec1d9db8cceec1cb28385fc2326087b17 (diff) | |
download | fosdem-2018-presentation-3241cb78d8f3d9fba19e8438df50bd29d0d0bc02.tar fosdem-2018-presentation-3241cb78d8f3d9fba19e8438df50bd29d0d0bc02.tar.gz |
progress bar can now be clicked to navigate (closes #181)
Diffstat (limited to 'js/reveal.js')
-rw-r--r-- | js/reveal.js | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/js/reveal.js b/js/reveal.js index b08580b..14e4fd7 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -1,5 +1,5 @@ /*! - * reveal.js 2.1 r34 + * reveal.js 2.1 r35 * http://lab.hakim.se/reveal-js * MIT licensed * @@ -332,6 +332,10 @@ var Reveal = (function(){ document.addEventListener( 'keydown', onDocumentKeyDown, false ); } + if ( config.progress && dom.progress ) { + dom.progress.addEventListener( 'click', preventAndForward( onProgressClick ), false ); + } + if ( config.controls && dom.controls ) { dom.controlsLeft.addEventListener( 'click', preventAndForward( navigateLeft ), false ); dom.controlsRight.addEventListener( 'click', preventAndForward( navigateRight ), false ); @@ -349,6 +353,10 @@ var Reveal = (function(){ document.removeEventListener( 'touchmove', onDocumentTouchMove, false ); document.removeEventListener( 'touchend', onDocumentTouchEnd, false ); window.removeEventListener( 'hashchange', onWindowHashChange, false ); + + if ( config.progress && dom.progress ) { + dom.progress.removeEventListener( 'click', preventAndForward( onProgressClick ), false ); + } if ( config.controls && dom.controls ) { dom.controlsLeft.removeEventListener( 'click', preventAndForward( navigateLeft ), false ); @@ -392,7 +400,7 @@ var Reveal = (function(){ function preventAndForward( delegate ) { return function( event ) { event.preventDefault(); - delegate.call(); + delegate.call( null, event ); }; } @@ -1234,8 +1242,8 @@ var Reveal = (function(){ } /** - * Handles mouse wheel scrolling, throttled to avoid - * skipping multiple slides. + * Handles mouse wheel scrolling, throttled to avoid skipping + * multiple slides. */ function onDocumentMouseScroll( event ){ clearTimeout( mouseWheelTimeout ); @@ -1250,6 +1258,19 @@ var Reveal = (function(){ } }, 100 ); } + + /** + * Clicking on the progress bar results in a navigation to the + * closest approximate horizontal slide using this equation: + * + * ( clickX / presentationWidth ) * numberOfSlides + */ + function onProgressClick( event ) { + var slidesTotal = Array.prototype.slice.call( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length; + var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal ); + + slide( slideIndex ); + } /** * Handler for the window level 'hashchange' event. |