3 * http://lab.hakim.se/reveal-js
6 * Copyright (C) 2013 Hakim El Hattab, http://hakim.se
8 var Reveal = (function(){
12 var SLIDES_SELECTOR = '.reveal .slides section',
13 HORIZONTAL_SLIDES_SELECTOR = '.reveal .slides>section',
14 VERTICAL_SLIDES_SELECTOR = '.reveal .slides>section.present>section',
15 HOME_SLIDE_SELECTOR = '.reveal .slides>section:first-child',
17 // Configurations defaults, can be overridden at initialization time
20 // The "normal" size of the presentation, aspect ratio will be preserved
21 // when the presentation is scaled to fit different resolutions
25 // Factor of the display size that should remain empty around the content
28 // Bounds for smallest/largest possible scale to apply to content
32 // Display controls in the bottom right corner
35 // Display a presentation progress bar
38 // Push each slide change to the browser history
41 // Enable keyboard shortcuts for navigation
44 // Enable the slide overview mode
47 // Vertical centring of slides
50 // Enables touch navigation on devices with touch input
53 // Loop the presentation
56 // Change the presentation direction to be RTL
59 // Number of milliseconds between automatically proceeding to the
60 // next slide, disabled when set to 0, this value can be overwritten
61 // by using a data-autoslide attribute on your slides
64 // Enable slide navigation via mouse wheel
67 // Apply a 3D roll to links on hover
70 // Theme (see /css/theme)
74 transition: 'default', // default/cube/page/concave/zoom/linear/fade/none
76 // Script dependencies to load
80 // The current auto-slide duration
83 // The horizontal and vertical index of the currently active slide
87 // The previous and current slide HTML elements
91 // Slides may hold a data-state attribute which we pick up and apply
92 // as a class to the body. This list contains the combined state of
93 // all current slides.
96 // The current scale of the presentation (see width/height config)
99 // Cached references to DOM elements
102 // Detect support for CSS 3D transforms
103 supports3DTransforms = 'WebkitPerspective' in document.body.style ||
104 'MozPerspective' in document.body.style ||
105 'msPerspective' in document.body.style ||
106 'OPerspective' in document.body.style ||
107 'perspective' in document.body.style,
109 // Detect support for CSS 2D transforms
110 supports2DTransforms = 'WebkitTransform' in document.body.style ||
111 'MozTransform' in document.body.style ||
112 'msTransform' in document.body.style ||
113 'OTransform' in document.body.style ||
114 'transform' in document.body.style,
116 // Throttles mouse wheel navigation
117 mouseWheelTimeout = 0,
119 // An interval used to automatically move on to the next slide
120 autoSlideTimeout = 0,
122 // Delays updates to the URL due to a Chrome thumbnailer bug
125 // A delay used to activate the overview mode
126 activateOverviewTimeout = 0,
128 // A delay used to deactivate the overview mode
129 deactivateOverviewTimeout = 0,
131 // Flags if the interaction event listeners are bound
132 eventsAreBound = false,
134 // Holds information about the currently ongoing touch input
145 * Starts up the presentation if the client is capable.
147 function initialize( options ) {
149 if( !supports2DTransforms && !supports3DTransforms ) {
150 document.body.setAttribute( 'class', 'no-transforms' );
152 // If the browser doesn't support core features we won't be
153 // using JavaScript to control the presentation
157 // Force a layout when the whole page, incl fonts, has loaded
158 window.addEventListener( 'load', layout, false );
160 // Copy options over to our config object
161 extend( config, options );
163 // Hide the address bar in mobile browsers
166 // Loads the dependencies and continues to #start() once done
172 * Finds and stores references to DOM elements which are
173 * required by the presentation. If a required element is
174 * not found, it is created.
176 function setupDOM() {
178 // Cache references to key DOM elements
179 dom.theme = document.querySelector( '#theme' );
180 dom.wrapper = document.querySelector( '.reveal' );
181 dom.slides = document.querySelector( '.reveal .slides' );
184 if( !dom.wrapper.querySelector( '.progress' ) && config.progress ) {
185 var progressElement = document.createElement( 'div' );
186 progressElement.classList.add( 'progress' );
187 progressElement.innerHTML = '<span></span>';
188 dom.wrapper.appendChild( progressElement );
192 if( !dom.wrapper.querySelector( '.controls' ) && config.controls ) {
193 var controlsElement = document.createElement( 'aside' );
194 controlsElement.classList.add( 'controls' );
195 controlsElement.innerHTML = '<div class="navigate-left"></div>' +
196 '<div class="navigate-right"></div>' +
197 '<div class="navigate-up"></div>' +
198 '<div class="navigate-down"></div>';
199 dom.wrapper.appendChild( controlsElement );
202 // Presentation background element
203 if( !dom.wrapper.querySelector( '.state-background' ) ) {
204 var backgroundElement = document.createElement( 'div' );
205 backgroundElement.classList.add( 'state-background' );
206 dom.wrapper.appendChild( backgroundElement );
209 // Overlay graphic which is displayed during the paused mode
210 if( !dom.wrapper.querySelector( '.pause-overlay' ) ) {
211 var pausedElement = document.createElement( 'div' );
212 pausedElement.classList.add( 'pause-overlay' );
213 dom.wrapper.appendChild( pausedElement );
216 // Cache references to elements
217 dom.progress = document.querySelector( '.reveal .progress' );
218 dom.progressbar = document.querySelector( '.reveal .progress span' );
220 if ( config.controls ) {
221 dom.controls = document.querySelector( '.reveal .controls' );
223 // There can be multiple instances of controls throughout the page
224 dom.controlsLeft = toArray( document.querySelectorAll( '.navigate-left' ) );
225 dom.controlsRight = toArray( document.querySelectorAll( '.navigate-right' ) );
226 dom.controlsUp = toArray( document.querySelectorAll( '.navigate-up' ) );
227 dom.controlsDown = toArray( document.querySelectorAll( '.navigate-down' ) );
228 dom.controlsPrev = toArray( document.querySelectorAll( '.navigate-prev' ) );
229 dom.controlsNext = toArray( document.querySelectorAll( '.navigate-next' ) );
235 * Hides the address bar if we're on a mobile device.
237 function hideAddressBar() {
239 if( /iphone|ipod|android/gi.test( navigator.userAgent ) && !/crios/gi.test( navigator.userAgent ) ) {
240 // Events that should trigger the address bar to hide
241 window.addEventListener( 'load', removeAddressBar, false );
242 window.addEventListener( 'orientationchange', removeAddressBar, false );
248 * Loads the dependencies of reveal.js. Dependencies are
249 * defined via the configuration option 'dependencies'
250 * and will be loaded prior to starting/binding reveal.js.
251 * Some dependencies may have an 'async' flag, if so they
252 * will load after reveal.js has been started up.
259 for( var i = 0, len = config.dependencies.length; i < len; i++ ) {
260 var s = config.dependencies[i];
262 // Load if there's no condition or the condition is truthy
263 if( !s.condition || s.condition() ) {
265 scriptsAsync.push( s.src );
268 scripts.push( s.src );
271 // Extension may contain callback functions
272 if( typeof s.callback === 'function' ) {
273 head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], s.callback );
278 // Called once synchronous scripts finish loading
280 if( scriptsAsync.length ) {
281 // Load asynchronous scripts
282 head.js.apply( null, scriptsAsync );
288 if( scripts.length ) {
289 head.ready( proceed );
291 // Load synchronous scripts
292 head.js.apply( null, scripts );
301 * Starts up reveal.js by binding input events and navigating
302 * to the current URL deeplink if there is one.
306 // Make sure we've got all the DOM elements we need
309 // Updates the presentation to match the current configuration values
312 // Read the initial hash
315 // Notify listeners that the presentation is ready but use a 1ms
316 // timeout to ensure it's not fired synchronously after #initialize()
317 setTimeout( function() {
318 dispatchEvent( 'ready', {
321 'currentSlide': currentSlide
328 * Applies the configuration settings from the config object.
330 function configure( options ) {
332 dom.wrapper.classList.remove( config.transition );
334 // New config options may be passed when this method
335 // is invoked through the API after initialization
336 if( typeof options === 'object' ) extend( config, options );
338 // Force linear transition based on browser capabilities
339 if( supports3DTransforms === false ) config.transition = 'linear';
341 dom.wrapper.classList.add( config.transition );
344 dom.controls.style.display = ( config.controls && dom.controls ) ? 'block' : 'none';
348 dom.progress.style.display = ( config.progress && dom.progress ) ? 'block' : 'none';
352 dom.wrapper.classList.add( 'rtl' );
355 dom.wrapper.classList.remove( 'rtl' );
358 if( config.center ) {
359 dom.wrapper.classList.add( 'center' );
362 dom.wrapper.classList.remove( 'center' );
365 if( config.mouseWheel ) {
366 document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
367 document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
370 document.removeEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
371 document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
375 if( config.rollingLinks ) {
382 // Load the theme in the config, if it's not already loaded
383 if( config.theme && dom.theme ) {
384 var themeURL = dom.theme.getAttribute( 'href' );
385 var themeFinder = /[^\/]*?(?=\.css)/;
386 var themeName = themeURL.match(themeFinder)[0];
388 if( config.theme !== themeName ) {
389 themeURL = themeURL.replace(themeFinder, config.theme);
390 dom.theme.setAttribute( 'href', themeURL );
399 * Updates various parts of the presentatio after the
400 * configuration has changed.
402 function postConfigure() {
404 // Subscribe to input
405 removeEventListeners();
408 // Force a layout to make sure the current config is accounted for
411 // Reflect the current autoSlide value
412 autoSlide = config.autoSlide;
414 // Start auto-sliding if it's enabled
420 * Binds all event listeners.
422 function addEventListeners() {
424 eventsAreBound = true;
426 window.addEventListener( 'hashchange', onWindowHashChange, false );
427 window.addEventListener( 'resize', onWindowResize, false );
430 dom.wrapper.addEventListener( 'touchstart', onTouchStart, false );
431 dom.wrapper.addEventListener( 'touchmove', onTouchMove, false );
432 dom.wrapper.addEventListener( 'touchend', onTouchEnd, false );
434 // Support pointer-style touch interaction as well
435 if( window.navigator.msPointerEnabled ) {
436 dom.wrapper.addEventListener( 'MSPointerDown', onPointerDown, false );
437 dom.wrapper.addEventListener( 'MSPointerMove', onPointerMove, false );
438 dom.wrapper.addEventListener( 'MSPointerUp', onPointerUp, false );
442 if( config.keyboard ) {
443 document.addEventListener( 'keydown', onDocumentKeyDown, false );
446 if ( config.progress && dom.progress ) {
447 dom.progress.addEventListener( 'click', onProgressClicked, false );
450 if ( config.controls && dom.controls ) {
451 [ 'touchstart', 'click' ].forEach( function( eventName ) {
452 dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } );
453 dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } );
454 dom.controlsUp.forEach( function( el ) { el.addEventListener( eventName, onNavigateUpClicked, false ); } );
455 dom.controlsDown.forEach( function( el ) { el.addEventListener( eventName, onNavigateDownClicked, false ); } );
456 dom.controlsPrev.forEach( function( el ) { el.addEventListener( eventName, onNavigatePrevClicked, false ); } );
457 dom.controlsNext.forEach( function( el ) { el.addEventListener( eventName, onNavigateNextClicked, false ); } );
464 * Unbinds all event listeners.
466 function removeEventListeners() {
468 eventsAreBound = false;
470 document.removeEventListener( 'keydown', onDocumentKeyDown, false );
471 window.removeEventListener( 'hashchange', onWindowHashChange, false );
472 window.removeEventListener( 'resize', onWindowResize, false );
474 dom.wrapper.removeEventListener( 'touchstart', onTouchStart, false );
475 dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false );
476 dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false );
478 if( window.navigator.msPointerEnabled ) {
479 dom.wrapper.removeEventListener( 'MSPointerDown', onPointerDown, false );
480 dom.wrapper.removeEventListener( 'MSPointerMove', onPointerMove, false );
481 dom.wrapper.removeEventListener( 'MSPointerUp', onPointerUp, false );
484 if ( config.progress && dom.progress ) {
485 dom.progress.removeEventListener( 'click', onProgressClicked, false );
488 if ( config.controls && dom.controls ) {
489 [ 'touchstart', 'click' ].forEach( function( eventName ) {
490 dom.controlsLeft.forEach( function( el ) { el.removeEventListener( eventName, onNavigateLeftClicked, false ); } );
491 dom.controlsRight.forEach( function( el ) { el.removeEventListener( eventName, onNavigateRightClicked, false ); } );
492 dom.controlsUp.forEach( function( el ) { el.removeEventListener( eventName, onNavigateUpClicked, false ); } );
493 dom.controlsDown.forEach( function( el ) { el.removeEventListener( eventName, onNavigateDownClicked, false ); } );
494 dom.controlsPrev.forEach( function( el ) { el.removeEventListener( eventName, onNavigatePrevClicked, false ); } );
495 dom.controlsNext.forEach( function( el ) { el.removeEventListener( eventName, onNavigateNextClicked, false ); } );
502 * Extend object a with the properties of object b.
503 * If there's a conflict, object b takes precedence.
505 function extend( a, b ) {
514 * Converts the target object to an array.
516 function toArray( o ) {
518 return Array.prototype.slice.call( o );
523 * Measures the distance in pixels between point a
526 * @param {Object} a point with x/y properties
527 * @param {Object} b point with x/y properties
529 function distanceBetween( a, b ) {
534 return Math.sqrt( dx*dx + dy*dy );
539 * Causes the address bar to hide on mobile devices,
540 * more vertical space ftw.
542 function removeAddressBar() {
544 if( window.orientation === 0 ) {
545 document.documentElement.style.overflow = 'scroll';
546 document.body.style.height = '120%';
549 document.documentElement.style.overflow = '';
550 document.body.style.height = '100%';
553 setTimeout( function() {
554 window.scrollTo( 0, 1 );
560 * Dispatches an event of the specified type from the
561 * reveal DOM element.
563 function dispatchEvent( type, properties ) {
565 var event = document.createEvent( "HTMLEvents", 1, 2 );
566 event.initEvent( type, true, true );
567 extend( event, properties );
568 dom.wrapper.dispatchEvent( event );
573 * Wrap all links in 3D goodness.
575 function enable3DLinks() {
577 if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) {
578 var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
580 for( var i = 0, len = anchors.length; i < len; i++ ) {
581 var anchor = anchors[i];
583 if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
584 var span = document.createElement('span');
585 span.setAttribute('data-title', anchor.text);
586 span.innerHTML = anchor.innerHTML;
588 anchor.classList.add( 'roll' );
589 anchor.innerHTML = '';
590 anchor.appendChild(span);
598 * Unwrap all 3D links.
600 function disable3DLinks() {
602 var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
604 for( var i = 0, len = anchors.length; i < len; i++ ) {
605 var anchor = anchors[i];
606 var span = anchor.querySelector( 'span' );
609 anchor.classList.remove( 'roll' );
610 anchor.innerHTML = span.innerHTML;
617 * Return a sorted fragments list, ordered by an increasing
618 * "data-fragment-index" attribute.
620 * Fragments will be revealed in the order that they are returned by
621 * this function, so you can use the index attributes to control the
622 * order of fragment appearance.
624 * To maintain a sensible default fragment order, fragments are presumed
625 * to be passed in document order. This function adds a "fragment-index"
626 * attribute to each node if such an attribute is not already present,
627 * and sets that attribute to an integer value which is the position of
628 * the fragment within the fragments list.
630 function sortFragments( fragments ) {
632 var a = toArray( fragments );
634 a.forEach( function( el, idx ) {
635 if( !el.hasAttribute( 'data-fragment-index' ) ) {
636 el.setAttribute( 'data-fragment-index', idx );
640 a.sort( function( l, r ) {
641 return l.getAttribute( 'data-fragment-index' ) - r.getAttribute( 'data-fragment-index');
649 * Applies JavaScript-controlled layout rules to the
656 // Available space to scale within
657 var availableWidth = dom.wrapper.offsetWidth,
658 availableHeight = dom.wrapper.offsetHeight;
660 // Reduce available space by margin
661 availableWidth -= ( availableHeight * config.margin );
662 availableHeight -= ( availableHeight * config.margin );
664 // Dimensions of the content
665 var slideWidth = config.width,
666 slideHeight = config.height;
668 // Slide width may be a percentage of available width
669 if( typeof slideWidth === 'string' && /%$/.test( slideWidth ) ) {
670 slideWidth = parseInt( slideWidth, 10 ) / 100 * availableWidth;
673 // Slide height may be a percentage of available height
674 if( typeof slideHeight === 'string' && /%$/.test( slideHeight ) ) {
675 slideHeight = parseInt( slideHeight, 10 ) / 100 * availableHeight;
678 dom.slides.style.width = slideWidth + 'px';
679 dom.slides.style.height = slideHeight + 'px';
681 // Determine scale of content to fit within available space
682 scale = Math.min( availableWidth / slideWidth, availableHeight / slideHeight );
684 // Respect max/min scale settings
685 scale = Math.max( scale, config.minScale );
686 scale = Math.min( scale, config.maxScale );
688 // Prefer applying scale via zoom since Chrome blurs scaled content
689 // with nested transforms
690 if( typeof dom.slides.style.zoom !== 'undefined' && !navigator.userAgent.match( /(iphone|ipod|ipad|android)/gi ) ) {
691 dom.slides.style.zoom = scale;
693 // Apply scale transform as a fallback
695 var transform = 'translate(-50%, -50%) scale('+ scale +') translate(50%, 50%)';
697 dom.slides.style.WebkitTransform = transform;
698 dom.slides.style.MozTransform = transform;
699 dom.slides.style.msTransform = transform;
700 dom.slides.style.OTransform = transform;
701 dom.slides.style.transform = transform;
704 // Select all slides, vertical and horizontal
705 var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
707 for( var i = 0, len = slides.length; i < len; i++ ) {
708 var slide = slides[ i ];
710 // Don't bother updating invisible slides
711 if( slide.style.display === 'none' ) {
715 if( config.center ) {
716 // Vertical stacks are not centred since their section
718 if( slide.classList.contains( 'stack' ) ) {
722 slide.style.top = Math.max( - ( slide.offsetHeight / 2 ) - 20, -slideHeight / 2 ) + 'px';
726 slide.style.top = '';
736 * Stores the vertical index of a stack so that the same
737 * vertical slide can be selected when navigating to and
740 * @param {HTMLElement} stack The vertical stack element
741 * @param {int} v Index to memorize
743 function setPreviousVerticalIndex( stack, v ) {
745 if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
746 stack.setAttribute( 'data-previous-indexv', v || 0 );
752 * Retrieves the vertical index which was stored using
753 * #setPreviousVerticalIndex() or 0 if no previous index
756 * @param {HTMLElement} stack The vertical stack element
758 function getPreviousVerticalIndex( stack ) {
760 if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
761 return parseInt( stack.getAttribute( 'data-previous-indexv' ) || 0, 10 );
769 * Displays the overview of slides (quick nav) by
770 * scaling down and arranging all slide elements.
772 * Experimental feature, might be dropped if perf
775 function activateOverview() {
777 // Only proceed if enabled in config
778 if( config.overview ) {
780 // Don't auto-slide while in overview mode
783 var wasActive = dom.wrapper.classList.contains( 'overview' );
785 dom.wrapper.classList.add( 'overview' );
786 dom.wrapper.classList.remove( 'exit-overview' );
788 clearTimeout( activateOverviewTimeout );
789 clearTimeout( deactivateOverviewTimeout );
791 // Not the pretties solution, but need to let the overview
792 // class apply first so that slides are measured accurately
793 // before we can position them
794 activateOverviewTimeout = setTimeout( function(){
796 var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
798 for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
799 var hslide = horizontalSlides[i],
800 htransform = 'translateZ(-2500px) translate(' + ( ( i - indexh ) * 105 ) + '%, 0%)';
802 hslide.setAttribute( 'data-index-h', i );
803 hslide.style.display = 'block';
804 hslide.style.WebkitTransform = htransform;
805 hslide.style.MozTransform = htransform;
806 hslide.style.msTransform = htransform;
807 hslide.style.OTransform = htransform;
808 hslide.style.transform = htransform;
810 if( hslide.classList.contains( 'stack' ) ) {
812 var verticalSlides = hslide.querySelectorAll( 'section' );
814 for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
815 var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
817 var vslide = verticalSlides[j],
818 vtransform = 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)';
820 vslide.setAttribute( 'data-index-h', i );
821 vslide.setAttribute( 'data-index-v', j );
822 vslide.style.display = 'block';
823 vslide.style.WebkitTransform = vtransform;
824 vslide.style.MozTransform = vtransform;
825 vslide.style.msTransform = vtransform;
826 vslide.style.OTransform = vtransform;
827 vslide.style.transform = vtransform;
829 // Navigate to this slide on click
830 vslide.addEventListener( 'click', onOverviewSlideClicked, true );
836 // Navigate to this slide on click
837 hslide.addEventListener( 'click', onOverviewSlideClicked, true );
845 // Notify observers of the overview showing
846 dispatchEvent( 'overviewshown', {
849 'currentSlide': currentSlide
860 * Exits the slide overview and enters the currently
863 function deactivateOverview() {
865 // Only proceed if enabled in config
866 if( config.overview ) {
868 clearTimeout( activateOverviewTimeout );
869 clearTimeout( deactivateOverviewTimeout );
871 dom.wrapper.classList.remove( 'overview' );
873 // Temporarily add a class so that transitions can do different things
874 // depending on whether they are exiting/entering overview, or just
875 // moving from slide to slide
876 dom.wrapper.classList.add( 'exit-overview' );
878 deactivateOverviewTimeout = setTimeout( function () {
879 dom.wrapper.classList.remove( 'exit-overview' );
883 var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
885 for( var i = 0, len = slides.length; i < len; i++ ) {
886 var element = slides[i];
888 element.style.display = '';
890 // Resets all transforms to use the external styles
891 element.style.WebkitTransform = '';
892 element.style.MozTransform = '';
893 element.style.msTransform = '';
894 element.style.OTransform = '';
895 element.style.transform = '';
897 element.removeEventListener( 'click', onOverviewSlideClicked, true );
900 slide( indexh, indexv );
904 // Notify observers of the overview hiding
905 dispatchEvent( 'overviewhidden', {
908 'currentSlide': currentSlide
915 * Toggles the slide overview mode on and off.
917 * @param {Boolean} override Optional flag which overrides the
918 * toggle logic and forcibly sets the desired state. True means
919 * overview is open, false means it's closed.
921 function toggleOverview( override ) {
923 if( typeof override === 'boolean' ) {
924 override ? activateOverview() : deactivateOverview();
927 isOverview() ? deactivateOverview() : activateOverview();
933 * Checks if the overview is currently active.
935 * @return {Boolean} true if the overview is active,
938 function isOverview() {
940 return dom.wrapper.classList.contains( 'overview' );
945 * Handling the fullscreen functionality via the fullscreen API
947 * @see http://fullscreen.spec.whatwg.org/
948 * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
950 function enterFullscreen() {
952 var element = document.body;
954 // Check which implementation is available
955 var requestMethod = element.requestFullScreen ||
956 element.webkitRequestFullScreen ||
957 element.mozRequestFullScreen ||
958 element.msRequestFullScreen;
960 if( requestMethod ) {
961 requestMethod.apply( element );
967 * Enters the paused mode which fades everything on screen to
972 var wasPaused = dom.wrapper.classList.contains( 'paused' );
975 dom.wrapper.classList.add( 'paused' );
977 if( wasPaused === false ) {
978 dispatchEvent( 'paused' );
984 * Exits from the paused mode.
988 var wasPaused = dom.wrapper.classList.contains( 'paused' );
989 dom.wrapper.classList.remove( 'paused' );
994 dispatchEvent( 'resumed' );
1000 * Toggles the paused mode on and off.
1002 function togglePause() {
1014 * Checks if we are currently in the paused mode.
1016 function isPaused() {
1018 return dom.wrapper.classList.contains( 'paused' );
1023 * Steps from the current point in the presentation to the
1024 * slide which matches the specified horizontal and vertical
1027 * @param {int} h Horizontal index of the target slide
1028 * @param {int} v Vertical index of the target slide
1029 * @param {int} f Optional index of a fragment within the
1030 * target slide to activate
1031 * @param {int} o Optional origin for use in multimaster environments
1033 function slide( h, v, f, o ) {
1035 // Remember where we were at before
1036 previousSlide = currentSlide;
1038 // Query all horizontal slides in the deck
1039 var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
1041 // If no vertical index is specified and the upcoming slide is a
1042 // stack, resume at its previous vertical index
1043 if( v === undefined ) {
1044 v = getPreviousVerticalIndex( horizontalSlides[ h ] );
1047 // If we were on a vertical stack, remember what vertical index
1048 // it was on so we can resume at the same position when returning
1049 if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
1050 setPreviousVerticalIndex( previousSlide.parentNode, indexv );
1053 // Remember the state before this slide
1054 var stateBefore = state.concat();
1056 // Reset the state array
1059 var indexhBefore = indexh,
1060 indexvBefore = indexv;
1062 // Activate and transition to the new slide
1063 indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
1064 indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
1068 // Apply the new state
1069 stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
1070 // Check if this state existed on the previous slide. If it
1071 // did, we will avoid adding it repeatedly
1072 for( var j = 0; j < stateBefore.length; j++ ) {
1073 if( stateBefore[j] === state[i] ) {
1074 stateBefore.splice( j, 1 );
1079 document.documentElement.classList.add( state[i] );
1081 // Dispatch custom event matching the state's name
1082 dispatchEvent( state[i] );
1085 // Clean up the remains of the previous state
1086 while( stateBefore.length ) {
1087 document.documentElement.classList.remove( stateBefore.pop() );
1090 // If the overview is active, re-activate it to update positions
1091 if( isOverview() ) {
1095 // Update the URL hash after a delay since updating it mid-transition
1096 // is likely to cause visual lag
1099 // Find the current horizontal slide and any possible vertical slides
1101 var currentHorizontalSlide = horizontalSlides[ indexh ],
1102 currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
1104 // Store references to the previous and current slides
1105 currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
1108 // Show fragment, if specified
1109 if( typeof f !== 'undefined' ) {
1110 var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
1112 toArray( fragments ).forEach( function( fragment, indexf ) {
1114 fragment.classList.add( 'visible' );
1117 fragment.classList.remove( 'visible' );
1122 // Dispatch an event if the slide changed
1123 if( indexh !== indexhBefore || indexv !== indexvBefore ) {
1124 dispatchEvent( 'slidechanged', {
1127 'previousSlide': previousSlide,
1128 'currentSlide': currentSlide,
1133 // Ensure that the previous slide is never the same as the current
1134 previousSlide = null;
1137 // Solves an edge case where the previous slide maintains the
1138 // 'present' class when navigating between adjacent vertical
1140 if( previousSlide ) {
1141 previousSlide.classList.remove( 'present' );
1143 // Reset all slides upon navigate to home
1145 if ( document.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
1146 // Launch async task
1147 setTimeout( function () {
1148 var slides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
1149 for( i in slides ) {
1152 setPreviousVerticalIndex( slides[i], 0 );
1165 * Updates one dimension of slides by showing the slide
1166 * with the specified index.
1168 * @param {String} selector A CSS selector that will fetch
1169 * the group of slides we are working with
1170 * @param {Number} index The index of the slide that should be
1173 * @return {Number} The index of the slide that is now shown,
1174 * might differ from the passed in index if it was out of
1177 function updateSlides( selector, index ) {
1179 // Select all slides and convert the NodeList result to
1181 var slides = toArray( document.querySelectorAll( selector ) ),
1182 slidesLength = slides.length;
1184 if( slidesLength ) {
1186 // Should the index loop?
1188 index %= slidesLength;
1191 index = slidesLength + index;
1195 // Enforce max and minimum index bounds
1196 index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
1198 for( var i = 0; i < slidesLength; i++ ) {
1199 var element = slides[i];
1201 // Optimization; hide all slides that are three or more steps
1202 // away from the present slide
1203 if( isOverview() === false ) {
1204 // The distance loops so that it measures 1 between the first
1206 var distance = Math.abs( ( index - i ) % ( slidesLength - 3 ) ) || 0;
1208 element.style.display = distance > 3 ? 'none' : 'block';
1211 slides[i].classList.remove( 'past' );
1212 slides[i].classList.remove( 'present' );
1213 slides[i].classList.remove( 'future' );
1216 // Any element previous to index is given the 'past' class
1217 slides[i].classList.add( 'past' );
1219 else if( i > index ) {
1220 // Any element subsequent to index is given the 'future' class
1221 slides[i].classList.add( 'future' );
1224 // If this element contains vertical slides
1225 if( element.querySelector( 'section' ) ) {
1226 slides[i].classList.add( 'stack' );
1230 // Mark the current slide as present
1231 slides[index].classList.add( 'present' );
1233 // If this slide has a state associated with it, add it
1234 // onto the current state of the deck
1235 var slideState = slides[index].getAttribute( 'data-state' );
1237 state = state.concat( slideState.split( ' ' ) );
1240 // If this slide has a data-autoslide attribtue associated use this as
1241 // autoSlide value otherwise use the global configured time
1242 var slideAutoSlide = slides[index].getAttribute( 'data-autoslide' );
1243 if( slideAutoSlide ) {
1244 autoSlide = parseInt( slideAutoSlide, 10 );
1247 autoSlide = config.autoSlide;
1252 // Since there are no slides we can't be anywhere beyond the
1262 * Updates the progress bar to reflect the current slide.
1264 function updateProgress() {
1266 // Update progress if enabled
1267 if( config.progress && dom.progress ) {
1269 var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
1271 // The number of past and total slides
1272 var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
1275 // Step through all slides and count the past ones
1276 mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
1278 var horizontalSlide = horizontalSlides[i];
1279 var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
1281 for( var j = 0; j < verticalSlides.length; j++ ) {
1283 // Stop as soon as we arrive at the present
1284 if( verticalSlides[j].classList.contains( 'present' ) ) {
1292 // Stop as soon as we arrive at the present
1293 if( horizontalSlide.classList.contains( 'present' ) ) {
1297 // Don't count the wrapping section for vertical slides
1298 if( horizontalSlide.classList.contains( 'stack' ) === false ) {
1304 dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px';
1311 * Updates the state of all control/navigation arrows.
1313 function updateControls() {
1315 if ( config.controls && dom.controls ) {
1317 var routes = availableRoutes();
1319 // Remove the 'enabled' class from all directions
1320 dom.controlsLeft.concat( dom.controlsRight )
1321 .concat( dom.controlsUp )
1322 .concat( dom.controlsDown )
1323 .concat( dom.controlsPrev )
1324 .concat( dom.controlsNext ).forEach( function( node ) {
1325 node.classList.remove( 'enabled' );
1328 // Add the 'enabled' class to the available routes
1329 if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1330 if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1331 if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1332 if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1334 // Prev/next buttons
1335 if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1336 if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1343 * Determine what available routes there are for navigation.
1345 * @return {Object} containing four booleans: left/right/up/down
1347 function availableRoutes() {
1349 var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
1350 verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
1353 left: indexh > 0 || config.loop,
1354 right: indexh < horizontalSlides.length - 1 || config.loop,
1356 down: indexv < verticalSlides.length - 1
1362 * Reads the current URL (hash) and navigates accordingly.
1364 function readURL() {
1366 var hash = window.location.hash;
1368 // Attempt to parse the hash as either an index or name
1369 var bits = hash.slice( 2 ).split( '/' ),
1370 name = hash.replace( /#|\//gi, '' );
1372 // If the first bit is invalid and there is a name we can
1373 // assume that this is a named link
1374 if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
1375 // Find the slide with the specified name
1376 var element = document.querySelector( '#' + name );
1379 // Find the position of the named slide and navigate to it
1380 var indices = Reveal.getIndices( element );
1381 slide( indices.h, indices.v );
1383 // If the slide doesn't exist, navigate to the current slide
1385 slide( indexh, indexv );
1389 // Read the index components of the hash
1390 var h = parseInt( bits[0], 10 ) || 0,
1391 v = parseInt( bits[1], 10 ) || 0;
1399 * Updates the page URL (hash) to reflect the current
1402 * @param {Number} delay The time in ms to wait before
1405 function writeURL( delay ) {
1407 if( config.history ) {
1409 // Make sure there's never more than one timeout running
1410 clearTimeout( writeURLTimeout );
1412 // If a delay is specified, timeout this call
1413 if( typeof delay === 'number' ) {
1414 writeURLTimeout = setTimeout( writeURL, delay );
1419 // If the current slide has an ID, use that as a named link
1420 if( currentSlide && typeof currentSlide.getAttribute( 'id' ) === 'string' ) {
1421 url = '/' + currentSlide.getAttribute( 'id' );
1423 // Otherwise use the /h/v index
1425 if( indexh > 0 || indexv > 0 ) url += indexh;
1426 if( indexv > 0 ) url += '/' + indexv;
1429 window.location.hash = url;
1436 * Retrieves the h/v location of the current, or specified,
1439 * @param {HTMLElement} slide If specified, the returned
1440 * index will be for this slide rather than the currently
1443 * @return {Object} { h: <int>, v: <int> }
1445 function getIndices( slide ) {
1447 // By default, return the current indices
1451 // If a slide is specified, return the indices of that slide
1453 var isVertical = !!slide.parentNode.nodeName.match( /section/gi );
1454 var slideh = isVertical ? slide.parentNode : slide;
1456 // Select all horizontal slides
1457 var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
1459 // Now that we know which the horizontal slide is, get its index
1460 h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
1462 // If this is a vertical slide, grab the vertical index
1464 v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
1468 return { h: h, v: v };
1473 * Navigate to the next slide fragment.
1475 * @return {Boolean} true if there was a next fragment,
1478 function nextFragment() {
1481 if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
1482 var verticalFragments = sortFragments( document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' ) );
1484 if( verticalFragments.length ) {
1485 verticalFragments[0].classList.add( 'visible' );
1487 // Notify subscribers of the change
1488 dispatchEvent( 'fragmentshown', { fragment: verticalFragments[0] } );
1492 // Horizontal slides:
1494 var horizontalFragments = sortFragments( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' ) );
1496 if( horizontalFragments.length ) {
1497 horizontalFragments[0].classList.add( 'visible' );
1499 // Notify subscribers of the change
1500 dispatchEvent( 'fragmentshown', { fragment: horizontalFragments[0] } );
1510 * Navigate to the previous slide fragment.
1512 * @return {Boolean} true if there was a previous fragment,
1515 function previousFragment() {
1518 if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
1519 var verticalFragments = sortFragments( document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment.visible' ) );
1521 if( verticalFragments.length ) {
1522 verticalFragments[ verticalFragments.length - 1 ].classList.remove( 'visible' );
1524 // Notify subscribers of the change
1525 dispatchEvent( 'fragmenthidden', { fragment: verticalFragments[ verticalFragments.length - 1 ] } );
1529 // Horizontal slides:
1531 var horizontalFragments = sortFragments( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment.visible' ) );
1533 if( horizontalFragments.length ) {
1534 horizontalFragments[ horizontalFragments.length - 1 ].classList.remove( 'visible' );
1536 // Notify subscribers of the change
1537 dispatchEvent( 'fragmenthidden', { fragment: horizontalFragments[ horizontalFragments.length - 1 ] } );
1547 * Cues a new automated slide if enabled in the config.
1549 function cueAutoSlide() {
1551 clearTimeout( autoSlideTimeout );
1553 // Cue the next auto-slide if enabled
1554 if( autoSlide && !isPaused() && !isOverview() ) {
1555 autoSlideTimeout = setTimeout( navigateNext, autoSlide );
1561 * Cancels any ongoing request to auto-slide.
1563 function cancelAutoSlide() {
1565 clearTimeout( autoSlideTimeout );
1569 function navigateLeft() {
1571 // Prioritize hiding fragments
1572 if( availableRoutes().left && ( isOverview() || previousFragment() === false ) ) {
1573 slide( indexh - 1 );
1578 function navigateRight() {
1580 // Prioritize revealing fragments
1581 if( availableRoutes().right && ( isOverview() || nextFragment() === false ) ) {
1582 slide( indexh + 1 );
1587 function navigateUp() {
1589 // Prioritize hiding fragments
1590 if( availableRoutes().up && isOverview() || previousFragment() === false ) {
1591 slide( indexh, indexv - 1 );
1596 function navigateDown() {
1598 // Prioritize revealing fragments
1599 if( availableRoutes().down && isOverview() || nextFragment() === false ) {
1600 slide( indexh, indexv + 1 );
1606 * Navigates backwards, prioritized in the following order:
1607 * 1) Previous fragment
1608 * 2) Previous vertical slide
1609 * 3) Previous horizontal slide
1611 function navigatePrev() {
1613 // Prioritize revealing fragments
1614 if( previousFragment() === false ) {
1615 if( availableRoutes().up ) {
1619 // Fetch the previous horizontal slide, if there is one
1620 var previousSlide = document.querySelector( HORIZONTAL_SLIDES_SELECTOR + '.past:nth-child(' + indexh + ')' );
1622 if( previousSlide ) {
1623 indexv = ( previousSlide.querySelectorAll( 'section' ).length + 1 ) || undefined;
1633 * Same as #navigatePrev() but navigates forwards.
1635 function navigateNext() {
1637 // Prioritize revealing fragments
1638 if( nextFragment() === false ) {
1639 availableRoutes().down ? navigateDown() : navigateRight();
1642 // If auto-sliding is enabled we need to cue up
1649 // --------------------------------------------------------------------//
1650 // ----------------------------- EVENTS -------------------------------//
1651 // --------------------------------------------------------------------//
1655 * Handler for the document level 'keydown' event.
1657 * @param {Object} event
1659 function onDocumentKeyDown( event ) {
1661 // Check if there's a focused element that could be using
1663 var activeElement = document.activeElement;
1664 var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) );
1666 // Disregard the event if there's a focused element or a
1667 // keyboard modifier key is present
1668 if( hasFocus || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
1670 var triggered = true;
1672 // while paused only allow "unpausing" keyboard events (b and .)
1673 if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) {
1677 switch( event.keyCode ) {
1679 case 80: case 33: navigatePrev(); break;
1681 case 78: case 34: navigateNext(); break;
1683 case 72: case 37: navigateLeft(); break;
1685 case 76: case 39: navigateRight(); break;
1687 case 75: case 38: navigateUp(); break;
1689 case 74: case 40: navigateDown(); break;
1691 case 36: slide( 0 ); break;
1693 case 35: slide( Number.MAX_VALUE ); break;
1695 case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
1697 case 13: isOverview() ? deactivateOverview() : triggered = false; break;
1698 // b, period, Logitech presenter tools "black screen" button
1699 case 66: case 190: case 191: togglePause(); break;
1701 case 70: enterFullscreen(); break;
1706 // If the input resulted in a triggered action we should prevent
1707 // the browsers default behavior
1709 event.preventDefault();
1711 else if ( event.keyCode === 27 && supports3DTransforms ) {
1714 event.preventDefault();
1717 // If auto-sliding is enabled we need to cue up
1724 * Handler for the 'touchstart' event, enables support for
1725 * swipe and pinch gestures.
1727 function onTouchStart( event ) {
1729 touch.startX = event.touches[0].clientX;
1730 touch.startY = event.touches[0].clientY;
1731 touch.startCount = event.touches.length;
1733 // If there's two touches we need to memorize the distance
1734 // between those two points to detect pinching
1735 if( event.touches.length === 2 && config.overview ) {
1736 touch.startSpan = distanceBetween( {
1737 x: event.touches[1].clientX,
1738 y: event.touches[1].clientY
1748 * Handler for the 'touchmove' event.
1750 function onTouchMove( event ) {
1752 // Each touch should only trigger one action
1753 if( !touch.handled ) {
1754 var currentX = event.touches[0].clientX;
1755 var currentY = event.touches[0].clientY;
1757 // If the touch started off with two points and still has
1758 // two active touches; test for the pinch gesture
1759 if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
1761 // The current distance in pixels between the two touch points
1762 var currentSpan = distanceBetween( {
1763 x: event.touches[1].clientX,
1764 y: event.touches[1].clientY
1770 // If the span is larger than the desire amount we've got
1771 // ourselves a pinch
1772 if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
1773 touch.handled = true;
1775 if( currentSpan < touch.startSpan ) {
1779 deactivateOverview();
1783 event.preventDefault();
1786 // There was only one touch point, look for a swipe
1787 else if( event.touches.length === 1 && touch.startCount !== 2 ) {
1789 var deltaX = currentX - touch.startX,
1790 deltaY = currentY - touch.startY;
1792 if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
1793 touch.handled = true;
1796 else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
1797 touch.handled = true;
1800 else if( deltaY > touch.threshold ) {
1801 touch.handled = true;
1804 else if( deltaY < -touch.threshold ) {
1805 touch.handled = true;
1809 event.preventDefault();
1813 // There's a bug with swiping on some Android devices unless
1814 // the default action is always prevented
1815 else if( navigator.userAgent.match( /android/gi ) ) {
1816 event.preventDefault();
1822 * Handler for the 'touchend' event.
1824 function onTouchEnd( event ) {
1826 touch.handled = false;
1831 * Convert pointer down to touch start.
1833 function onPointerDown( event ) {
1835 if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
1836 event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
1837 onTouchStart( event );
1843 * Convert pointer move to touch move.
1845 function onPointerMove( event ) {
1847 if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
1848 event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
1849 onTouchMove( event );
1855 * Convert pointer up to touch end.
1857 function onPointerUp( event ) {
1859 if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
1860 event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
1861 onTouchEnd( event );
1867 * Handles mouse wheel scrolling, throttled to avoid skipping
1870 function onDocumentMouseScroll( event ) {
1872 clearTimeout( mouseWheelTimeout );
1874 mouseWheelTimeout = setTimeout( function() {
1875 var delta = event.detail || -event.wheelDelta;
1887 * Clicking on the progress bar results in a navigation to the
1888 * closest approximate horizontal slide using this equation:
1890 * ( clickX / presentationWidth ) * numberOfSlides
1892 function onProgressClicked( event ) {
1894 event.preventDefault();
1896 var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
1897 var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
1899 slide( slideIndex );
1904 * Event handler for navigation control buttons.
1906 function onNavigateLeftClicked( event ) { event.preventDefault(); navigateLeft(); }
1907 function onNavigateRightClicked( event ) { event.preventDefault(); navigateRight(); }
1908 function onNavigateUpClicked( event ) { event.preventDefault(); navigateUp(); }
1909 function onNavigateDownClicked( event ) { event.preventDefault(); navigateDown(); }
1910 function onNavigatePrevClicked( event ) { event.preventDefault(); navigatePrev(); }
1911 function onNavigateNextClicked( event ) { event.preventDefault(); navigateNext(); }
1914 * Handler for the window level 'hashchange' event.
1916 function onWindowHashChange( event ) {
1923 * Handler for the window level 'resize' event.
1925 function onWindowResize( event ) {
1932 * Invoked when a slide is and we're in the overview.
1934 function onOverviewSlideClicked( event ) {
1936 // TODO There's a bug here where the event listeners are not
1937 // removed after deactivating the overview.
1938 if( eventsAreBound && isOverview() ) {
1939 event.preventDefault();
1941 var element = event.target;
1943 while( element && !element.nodeName.match( /section/gi ) ) {
1944 element = element.parentNode;
1947 if( element && !element.classList.contains( 'disabled' ) ) {
1949 deactivateOverview();
1951 if( element.nodeName.match( /section/gi ) ) {
1952 var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
1953 v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
1964 // --------------------------------------------------------------------//
1965 // ------------------------------- API --------------------------------//
1966 // --------------------------------------------------------------------//
1970 initialize: initialize,
1971 configure: configure,
1973 // Navigation methods
1976 right: navigateRight,
1981 prevFragment: previousFragment,
1982 nextFragment: nextFragment,
1984 // Deprecated aliases
1986 navigateLeft: navigateLeft,
1987 navigateRight: navigateRight,
1988 navigateUp: navigateUp,
1989 navigateDown: navigateDown,
1990 navigatePrev: navigatePrev,
1991 navigateNext: navigateNext,
1993 // Forces an update in slide layout
1996 // Returns an object with the available routes as booleans (left/right/top/bottom)
1997 availableRoutes: availableRoutes,
1999 // Toggles the overview mode on/off
2000 toggleOverview: toggleOverview,
2002 // Toggles the "black screen" mode on/off
2003 togglePause: togglePause,
2006 isOverview: isOverview,
2009 // Adds or removes all internal event listeners (such as keyboard)
2010 addEventListeners: addEventListeners,
2011 removeEventListeners: removeEventListeners,
2013 // Returns the indices of the current, or specified, slide
2014 getIndices: getIndices,
2016 // Returns the slide at the specified index, y is optional
2017 getSlide: function( x, y ) {
2018 var horizontalSlide = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
2019 var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
2021 if( typeof y !== 'undefined' ) {
2022 return verticalSlides ? verticalSlides[ y ] : undefined;
2025 return horizontalSlide;
2028 // Returns the previous slide element, may be null
2029 getPreviousSlide: function() {
2030 return previousSlide;
2033 // Returns the current slide element
2034 getCurrentSlide: function() {
2035 return currentSlide;
2038 // Returns the current scale of the presentation content
2039 getScale: function() {
2043 // Returns the current configuration object
2044 getConfig: function() {
2048 // Helper method, retrieves query string as a key/value hash
2049 getQueryHash: function() {
2052 location.search.replace( /[A-Z0-9]+?=(\w*)/gi, function(a) {
2053 query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
2059 // Returns true if we're currently on the first slide
2060 isFirstSlide: function() {
2061 return document.querySelector( SLIDES_SELECTOR + '.past' ) == null ? true : false;
2064 // Returns true if we're currently on the last slide
2065 isLastSlide: function() {
2066 if( currentSlide && currentSlide.classList.contains( '.stack' ) ) {
2067 return currentSlide.querySelector( SLIDES_SELECTOR + '.future' ) == null ? true : false;
2070 return document.querySelector( SLIDES_SELECTOR + '.future' ) == null ? true : false;
2074 // Forward event binding to the reveal DOM element
2075 addEventListener: function( type, listener, useCapture ) {
2076 if( 'addEventListener' in window ) {
2077 ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
2080 removeEventListener: function( type, listener, useCapture ) {
2081 if( 'addEventListener' in window ) {
2082 ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );