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 // Subscribe to input
312 // Updates the presentation to match the current configuration values
315 // Read the initial hash
318 // Notify listeners that the presentation is ready but use a 1ms
319 // timeout to ensure it's not fired synchronously after #initialize()
320 setTimeout( function() {
321 dispatchEvent( 'ready', {
324 'currentSlide': currentSlide
331 * Applies the configuration settings from the config object.
333 function configure( options ) {
335 dom.wrapper.classList.remove( config.transition );
337 // New config options may be passed when this method
338 // is invoked through the API after initialization
339 if( typeof options === 'object' ) extend( config, options );
341 // Force linear transition based on browser capabilities
342 if( supports3DTransforms === false ) config.transition = 'linear';
344 dom.wrapper.classList.add( config.transition );
347 dom.controls.style.display = ( config.controls && dom.controls ) ? 'block' : 'none';
351 dom.progress.style.display = ( config.progress && dom.progress ) ? 'block' : 'none';
355 dom.wrapper.classList.add( 'rtl' );
358 dom.wrapper.classList.remove( 'rtl' );
361 if( config.center ) {
362 dom.wrapper.classList.add( 'center' );
365 dom.wrapper.classList.remove( 'center' );
368 if( config.mouseWheel ) {
369 document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
370 document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
373 document.removeEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
374 document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
378 if( config.rollingLinks ) {
385 // Load the theme in the config, if it's not already loaded
386 if( config.theme && dom.theme ) {
387 var themeURL = dom.theme.getAttribute( 'href' );
388 var themeFinder = /[^\/]*?(?=\.css)/;
389 var themeName = themeURL.match(themeFinder)[0];
391 if( config.theme !== themeName ) {
392 themeURL = themeURL.replace(themeFinder, config.theme);
393 dom.theme.setAttribute( 'href', themeURL );
397 // Force a layout to make sure the current config is accounted for
400 // Reflect the current autoSlide value
401 autoSlide = config.autoSlide;
403 // Start auto-sliding if it's enabled
409 * Binds all event listeners.
411 function addEventListeners() {
413 eventsAreBound = true;
415 window.addEventListener( 'hashchange', onWindowHashChange, false );
416 window.addEventListener( 'resize', onWindowResize, false );
419 document.addEventListener( 'touchstart', onDocumentTouchStart, false );
420 document.addEventListener( 'touchmove', onDocumentTouchMove, false );
421 document.addEventListener( 'touchend', onDocumentTouchEnd, false );
424 if( config.keyboard ) {
425 document.addEventListener( 'keydown', onDocumentKeyDown, false );
428 if ( config.progress && dom.progress ) {
429 dom.progress.addEventListener( 'click', onProgressClicked, false );
432 if ( config.controls && dom.controls ) {
433 var actionEvent = 'ontouchstart' in window && window.ontouchstart != null ? 'touchstart' : 'click';
434 dom.controlsLeft.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateLeftClicked, false ); } );
435 dom.controlsRight.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateRightClicked, false ); } );
436 dom.controlsUp.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateUpClicked, false ); } );
437 dom.controlsDown.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateDownClicked, false ); } );
438 dom.controlsPrev.forEach( function( el ) { el.addEventListener( actionEvent, onNavigatePrevClicked, false ); } );
439 dom.controlsNext.forEach( function( el ) { el.addEventListener( actionEvent, onNavigateNextClicked, false ); } );
445 * Unbinds all event listeners.
447 function removeEventListeners() {
449 eventsAreBound = false;
451 document.removeEventListener( 'keydown', onDocumentKeyDown, false );
452 window.removeEventListener( 'hashchange', onWindowHashChange, false );
453 window.removeEventListener( 'resize', onWindowResize, false );
456 document.removeEventListener( 'touchstart', onDocumentTouchStart, false );
457 document.removeEventListener( 'touchmove', onDocumentTouchMove, false );
458 document.removeEventListener( 'touchend', onDocumentTouchEnd, false );
461 if ( config.progress && dom.progress ) {
462 dom.progress.removeEventListener( 'click', onProgressClicked, false );
465 if ( config.controls && dom.controls ) {
466 var actionEvent = 'ontouchstart' in window && window.ontouchstart != null ? 'touchstart' : 'click';
467 dom.controlsLeft.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateLeftClicked, false ); } );
468 dom.controlsRight.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateRightClicked, false ); } );
469 dom.controlsUp.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateUpClicked, false ); } );
470 dom.controlsDown.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateDownClicked, false ); } );
471 dom.controlsPrev.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigatePrevClicked, false ); } );
472 dom.controlsNext.forEach( function( el ) { el.removeEventListener( actionEvent, onNavigateNextClicked, false ); } );
478 * Extend object a with the properties of object b.
479 * If there's a conflict, object b takes precedence.
481 function extend( a, b ) {
490 * Converts the target object to an array.
492 function toArray( o ) {
494 return Array.prototype.slice.call( o );
499 * Measures the distance in pixels between point a
502 * @param {Object} a point with x/y properties
503 * @param {Object} b point with x/y properties
505 function distanceBetween( a, b ) {
510 return Math.sqrt( dx*dx + dy*dy );
515 * Causes the address bar to hide on mobile devices,
516 * more vertical space ftw.
518 function removeAddressBar() {
520 if( window.orientation === 0 ) {
521 document.documentElement.style.overflow = 'scroll';
522 document.body.style.height = '120%';
525 document.documentElement.style.overflow = '';
526 document.body.style.height = '100%';
529 setTimeout( function() {
530 window.scrollTo( 0, 1 );
536 * Dispatches an event of the specified type from the
537 * reveal DOM element.
539 function dispatchEvent( type, properties ) {
541 var event = document.createEvent( "HTMLEvents", 1, 2 );
542 event.initEvent( type, true, true );
543 extend( event, properties );
544 dom.wrapper.dispatchEvent( event );
549 * Wrap all links in 3D goodness.
551 function enable3DLinks() {
553 if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) {
554 var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
556 for( var i = 0, len = anchors.length; i < len; i++ ) {
557 var anchor = anchors[i];
559 if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
560 var span = document.createElement('span');
561 span.setAttribute('data-title', anchor.text);
562 span.innerHTML = anchor.innerHTML;
564 anchor.classList.add( 'roll' );
565 anchor.innerHTML = '';
566 anchor.appendChild(span);
574 * Unwrap all 3D links.
576 function disable3DLinks() {
578 var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
580 for( var i = 0, len = anchors.length; i < len; i++ ) {
581 var anchor = anchors[i];
582 var span = anchor.querySelector( 'span' );
585 anchor.classList.remove( 'roll' );
586 anchor.innerHTML = span.innerHTML;
593 * Return a sorted fragments list, ordered by an increasing
594 * "data-fragment-index" attribute.
596 * Fragments will be revealed in the order that they are returned by
597 * this function, so you can use the index attributes to control the
598 * order of fragment appearance.
600 * To maintain a sensible default fragment order, fragments are presumed
601 * to be passed in document order. This function adds a "fragment-index"
602 * attribute to each node if such an attribute is not already present,
603 * and sets that attribute to an integer value which is the position of
604 * the fragment within the fragments list.
606 function sortFragments( fragments ) {
608 var a = toArray( fragments );
610 a.forEach( function( el, idx ) {
611 if( !el.hasAttribute( 'data-fragment-index' ) ) {
612 el.setAttribute( 'data-fragment-index', idx );
616 a.sort( function( l, r ) {
617 return l.getAttribute( 'data-fragment-index' ) - r.getAttribute( 'data-fragment-index');
625 * Applies JavaScript-controlled layout rules to the
632 // Available space to scale within
633 var availableWidth = dom.wrapper.offsetWidth,
634 availableHeight = dom.wrapper.offsetHeight;
636 // Reduce available space by margin
637 availableWidth -= ( availableHeight * config.margin );
638 availableHeight -= ( availableHeight * config.margin );
640 // Dimensions of the content
641 var slideWidth = config.width,
642 slideHeight = config.height;
644 // Slide width may be a percentage of available width
645 if( typeof slideWidth === 'string' && /%$/.test( slideWidth ) ) {
646 slideWidth = parseInt( slideWidth, 10 ) / 100 * availableWidth;
649 // Slide height may be a percentage of available height
650 if( typeof slideHeight === 'string' && /%$/.test( slideHeight ) ) {
651 slideHeight = parseInt( slideHeight, 10 ) / 100 * availableHeight;
654 dom.slides.style.width = slideWidth + 'px';
655 dom.slides.style.height = slideHeight + 'px';
657 // Determine scale of content to fit within available space
658 scale = Math.min( availableWidth / slideWidth, availableHeight / slideHeight );
660 // Respect max/min scale settings
661 scale = Math.max( scale, config.minScale );
662 scale = Math.min( scale, config.maxScale );
664 // Prefer applying scale via zoom since Chrome blurs scaled content
665 // with nested transforms
666 if( typeof dom.slides.style.zoom !== 'undefined' && !navigator.userAgent.match( /(iphone|ipod|ipad|android)/gi ) ) {
667 dom.slides.style.zoom = scale;
669 // Apply scale transform as a fallback
671 var transform = 'translate(-50%, -50%) scale('+ scale +') translate(50%, 50%)';
673 dom.slides.style.WebkitTransform = transform;
674 dom.slides.style.MozTransform = transform;
675 dom.slides.style.msTransform = transform;
676 dom.slides.style.OTransform = transform;
677 dom.slides.style.transform = transform;
680 // Select all slides, vertical and horizontal
681 var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
683 for( var i = 0, len = slides.length; i < len; i++ ) {
684 var slide = slides[ i ];
686 // Don't bother updating invisible slides
687 if( slide.style.display === 'none' ) {
691 if( config.center ) {
692 // Vertical stacks are not centred since their section
694 if( slide.classList.contains( 'stack' ) ) {
698 slide.style.top = Math.max( - ( slide.offsetHeight / 2 ) - 20, -slideHeight / 2 ) + 'px';
702 slide.style.top = '';
712 * Stores the vertical index of a stack so that the same
713 * vertical slide can be selected when navigating to and
716 * @param {HTMLElement} stack The vertical stack element
717 * @param {int} v Index to memorize
719 function setPreviousVerticalIndex( stack, v ) {
722 stack.setAttribute( 'data-previous-indexv', v || 0 );
728 * Retrieves the vertical index which was stored using
729 * #setPreviousVerticalIndex() or 0 if no previous index
732 * @param {HTMLElement} stack The vertical stack element
734 function getPreviousVerticalIndex( stack ) {
736 if( stack && stack.classList.contains( 'stack' ) ) {
737 return parseInt( stack.getAttribute( 'data-previous-indexv' ) || 0, 10 );
745 * Displays the overview of slides (quick nav) by
746 * scaling down and arranging all slide elements.
748 * Experimental feature, might be dropped if perf
751 function activateOverview() {
753 // Only proceed if enabled in config
754 if( config.overview ) {
756 // Don't auto-slide while in overview mode
759 var wasActive = dom.wrapper.classList.contains( 'overview' );
761 dom.wrapper.classList.add( 'overview' );
762 dom.wrapper.classList.remove( 'exit-overview' );
764 clearTimeout( activateOverviewTimeout );
765 clearTimeout( deactivateOverviewTimeout );
767 // Not the pretties solution, but need to let the overview
768 // class apply first so that slides are measured accurately
769 // before we can position them
770 activateOverviewTimeout = setTimeout( function(){
772 var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
774 for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
775 var hslide = horizontalSlides[i],
776 htransform = 'translateZ(-2500px) translate(' + ( ( i - indexh ) * 105 ) + '%, 0%)';
778 hslide.setAttribute( 'data-index-h', i );
779 hslide.style.display = 'block';
780 hslide.style.WebkitTransform = htransform;
781 hslide.style.MozTransform = htransform;
782 hslide.style.msTransform = htransform;
783 hslide.style.OTransform = htransform;
784 hslide.style.transform = htransform;
786 if( hslide.classList.contains( 'stack' ) ) {
788 var verticalSlides = hslide.querySelectorAll( 'section' );
790 for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
791 var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
793 var vslide = verticalSlides[j],
794 vtransform = 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)';
796 vslide.setAttribute( 'data-index-h', i );
797 vslide.setAttribute( 'data-index-v', j );
798 vslide.style.display = 'block';
799 vslide.style.WebkitTransform = vtransform;
800 vslide.style.MozTransform = vtransform;
801 vslide.style.msTransform = vtransform;
802 vslide.style.OTransform = vtransform;
803 vslide.style.transform = vtransform;
805 // Navigate to this slide on click
806 vslide.addEventListener( 'click', onOverviewSlideClicked, true );
812 // Navigate to this slide on click
813 hslide.addEventListener( 'click', onOverviewSlideClicked, true );
821 // Notify observers of the overview showing
822 dispatchEvent( 'overviewshown', {
825 'currentSlide': currentSlide
836 * Exits the slide overview and enters the currently
839 function deactivateOverview() {
841 // Only proceed if enabled in config
842 if( config.overview ) {
844 clearTimeout( activateOverviewTimeout );
845 clearTimeout( deactivateOverviewTimeout );
847 dom.wrapper.classList.remove( 'overview' );
849 // Temporarily add a class so that transitions can do different things
850 // depending on whether they are exiting/entering overview, or just
851 // moving from slide to slide
852 dom.wrapper.classList.add( 'exit-overview' );
854 deactivateOverviewTimeout = setTimeout( function () {
855 dom.wrapper.classList.remove( 'exit-overview' );
859 var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
861 for( var i = 0, len = slides.length; i < len; i++ ) {
862 var element = slides[i];
864 element.style.display = '';
866 // Resets all transforms to use the external styles
867 element.style.WebkitTransform = '';
868 element.style.MozTransform = '';
869 element.style.msTransform = '';
870 element.style.OTransform = '';
871 element.style.transform = '';
873 element.removeEventListener( 'click', onOverviewSlideClicked, true );
876 slide( indexh, indexv );
880 // Notify observers of the overview hiding
881 dispatchEvent( 'overviewhidden', {
884 'currentSlide': currentSlide
891 * Toggles the slide overview mode on and off.
893 * @param {Boolean} override Optional flag which overrides the
894 * toggle logic and forcibly sets the desired state. True means
895 * overview is open, false means it's closed.
897 function toggleOverview( override ) {
899 if( typeof override === 'boolean' ) {
900 override ? activateOverview() : deactivateOverview();
903 isOverview() ? deactivateOverview() : activateOverview();
909 * Checks if the overview is currently active.
911 * @return {Boolean} true if the overview is active,
914 function isOverview() {
916 return dom.wrapper.classList.contains( 'overview' );
921 * Handling the fullscreen functionality via the fullscreen API
923 * @see http://fullscreen.spec.whatwg.org/
924 * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
926 function enterFullscreen() {
928 var element = document.body;
930 // Check which implementation is available
931 var requestMethod = element.requestFullScreen ||
932 element.webkitRequestFullScreen ||
933 element.mozRequestFullScreen ||
934 element.msRequestFullScreen;
936 if( requestMethod ) {
937 requestMethod.apply( element );
943 * Enters the paused mode which fades everything on screen to
948 var wasPaused = dom.wrapper.classList.contains( 'paused' );
951 dom.wrapper.classList.add( 'paused' );
953 if( wasPaused === false ) {
954 dispatchEvent( 'paused' );
960 * Exits from the paused mode.
964 var wasPaused = dom.wrapper.classList.contains( 'paused' );
967 dom.wrapper.classList.remove( 'paused' );
970 dispatchEvent( 'resumed' );
976 * Toggles the paused mode on and off.
978 function togglePause() {
990 * Checks if we are currently in the paused mode.
992 function isPaused() {
994 return dom.wrapper.classList.contains( 'paused' );
999 * Steps from the current point in the presentation to the
1000 * slide which matches the specified horizontal and vertical
1003 * @param {int} h Horizontal index of the target slide
1004 * @param {int} v Vertical index of the target slide
1005 * @param {int} f Optional index of a fragment within the
1006 * target slide to activate
1008 function slide( h, v, f ) {
1010 // Remember where we were at before
1011 previousSlide = currentSlide;
1013 // Query all horizontal slides in the deck
1014 var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
1016 // If no vertical index is specified and the upcoming slide is a
1017 // stack, resume at its previous vertical index
1018 if( v === undefined ) {
1019 v = getPreviousVerticalIndex( horizontalSlides[ h ] );
1022 // If we were on a vertical stack, remember what vertical index
1023 // it was on so we can resume at the same position when returning
1024 if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
1025 setPreviousVerticalIndex( previousSlide.parentNode, indexv );
1028 // Remember the state before this slide
1029 var stateBefore = state.concat();
1031 // Reset the state array
1034 var indexhBefore = indexh,
1035 indexvBefore = indexv;
1037 // Activate and transition to the new slide
1038 indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
1039 indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
1043 // Apply the new state
1044 stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
1045 // Check if this state existed on the previous slide. If it
1046 // did, we will avoid adding it repeatedly
1047 for( var j = 0; j < stateBefore.length; j++ ) {
1048 if( stateBefore[j] === state[i] ) {
1049 stateBefore.splice( j, 1 );
1054 document.documentElement.classList.add( state[i] );
1056 // Dispatch custom event matching the state's name
1057 dispatchEvent( state[i] );
1060 // Clean up the remains of the previous state
1061 while( stateBefore.length ) {
1062 document.documentElement.classList.remove( stateBefore.pop() );
1065 // If the overview is active, re-activate it to update positions
1066 if( isOverview() ) {
1070 // Update the URL hash after a delay since updating it mid-transition
1071 // is likely to cause visual lag
1074 // Find the current horizontal slide and any possible vertical slides
1076 var currentHorizontalSlide = horizontalSlides[ indexh ],
1077 currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
1079 // Store references to the previous and current slides
1080 currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
1083 // Show fragment, if specified
1084 if( typeof f !== 'undefined' ) {
1085 var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
1087 toArray( fragments ).forEach( function( fragment, indexf ) {
1089 fragment.classList.add( 'visible' );
1092 fragment.classList.remove( 'visible' );
1097 // Dispatch an event if the slide changed
1098 if( indexh !== indexhBefore || indexv !== indexvBefore ) {
1099 dispatchEvent( 'slidechanged', {
1102 'previousSlide': previousSlide,
1103 'currentSlide': currentSlide
1107 // Ensure that the previous slide is never the same as the current
1108 previousSlide = null;
1111 // Solves an edge case where the previous slide maintains the
1112 // 'present' class when navigating between adjacent vertical
1114 if( previousSlide ) {
1115 previousSlide.classList.remove( 'present' );
1117 // Reset all slides upon navigate to home
1119 if ( document.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
1120 // Launch async task
1121 setTimeout( function () {
1122 var slides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
1123 for( i in slides ) {
1126 setPreviousVerticalIndex( slides[i], 0 );
1139 * Updates one dimension of slides by showing the slide
1140 * with the specified index.
1142 * @param {String} selector A CSS selector that will fetch
1143 * the group of slides we are working with
1144 * @param {Number} index The index of the slide that should be
1147 * @return {Number} The index of the slide that is now shown,
1148 * might differ from the passed in index if it was out of
1151 function updateSlides( selector, index ) {
1153 // Select all slides and convert the NodeList result to
1155 var slides = toArray( document.querySelectorAll( selector ) ),
1156 slidesLength = slides.length;
1158 if( slidesLength ) {
1160 // Should the index loop?
1162 index %= slidesLength;
1165 index = slidesLength + index;
1169 // Enforce max and minimum index bounds
1170 index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
1172 for( var i = 0; i < slidesLength; i++ ) {
1173 var element = slides[i];
1175 // Optimization; hide all slides that are three or more steps
1176 // away from the present slide
1177 if( isOverview() === false ) {
1178 // The distance loops so that it measures 1 between the first
1180 var distance = Math.abs( ( index - i ) % ( slidesLength - 3 ) ) || 0;
1182 element.style.display = distance > 3 ? 'none' : 'block';
1185 slides[i].classList.remove( 'past' );
1186 slides[i].classList.remove( 'present' );
1187 slides[i].classList.remove( 'future' );
1190 // Any element previous to index is given the 'past' class
1191 slides[i].classList.add( 'past' );
1193 else if( i > index ) {
1194 // Any element subsequent to index is given the 'future' class
1195 slides[i].classList.add( 'future' );
1198 // If this element contains vertical slides
1199 if( element.querySelector( 'section' ) ) {
1200 slides[i].classList.add( 'stack' );
1204 // Mark the current slide as present
1205 slides[index].classList.add( 'present' );
1207 // If this slide has a state associated with it, add it
1208 // onto the current state of the deck
1209 var slideState = slides[index].getAttribute( 'data-state' );
1211 state = state.concat( slideState.split( ' ' ) );
1214 // If this slide has a data-autoslide attribtue associated use this as
1215 // autoSlide value otherwise use the global configured time
1216 var slideAutoSlide = slides[index].getAttribute( 'data-autoslide' );
1217 if( slideAutoSlide ) {
1218 autoSlide = parseInt( slideAutoSlide, 10 );
1221 autoSlide = config.autoSlide;
1226 // Since there are no slides we can't be anywhere beyond the
1236 * Updates the progress bar to reflect the current slide.
1238 function updateProgress() {
1240 // Update progress if enabled
1241 if( config.progress && dom.progress ) {
1243 var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
1245 // The number of past and total slides
1246 var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
1249 // Step through all slides and count the past ones
1250 mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
1252 var horizontalSlide = horizontalSlides[i];
1253 var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
1255 for( var j = 0; j < verticalSlides.length; j++ ) {
1257 // Stop as soon as we arrive at the present
1258 if( verticalSlides[j].classList.contains( 'present' ) ) {
1266 // Stop as soon as we arrive at the present
1267 if( horizontalSlide.classList.contains( 'present' ) ) {
1271 // Don't count the wrapping section for vertical slides
1272 if( horizontalSlide.classList.contains( 'stack' ) === false ) {
1278 dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px';
1285 * Updates the state of all control/navigation arrows.
1287 function updateControls() {
1289 if ( config.controls && dom.controls ) {
1291 var routes = availableRoutes();
1293 // Remove the 'enabled' class from all directions
1294 dom.controlsLeft.concat( dom.controlsRight )
1295 .concat( dom.controlsUp )
1296 .concat( dom.controlsDown )
1297 .concat( dom.controlsPrev )
1298 .concat( dom.controlsNext ).forEach( function( node ) {
1299 node.classList.remove( 'enabled' );
1302 // Add the 'enabled' class to the available routes
1303 if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1304 if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1305 if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1306 if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1308 // Prev/next buttons
1309 if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1310 if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1317 * Determine what available routes there are for navigation.
1319 * @return {Object} containing four booleans: left/right/up/down
1321 function availableRoutes() {
1323 var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
1324 verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
1328 right: indexh < horizontalSlides.length - 1,
1330 down: indexv < verticalSlides.length - 1
1336 * Reads the current URL (hash) and navigates accordingly.
1338 function readURL() {
1340 var hash = window.location.hash;
1342 // Attempt to parse the hash as either an index or name
1343 var bits = hash.slice( 2 ).split( '/' ),
1344 name = hash.replace( /#|\//gi, '' );
1346 // If the first bit is invalid and there is a name we can
1347 // assume that this is a named link
1348 if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
1349 // Find the slide with the specified name
1350 var element = document.querySelector( '#' + name );
1353 // Find the position of the named slide and navigate to it
1354 var indices = Reveal.getIndices( element );
1355 slide( indices.h, indices.v );
1357 // If the slide doesn't exist, navigate to the current slide
1359 slide( indexh, indexv );
1363 // Read the index components of the hash
1364 var h = parseInt( bits[0], 10 ) || 0,
1365 v = parseInt( bits[1], 10 ) || 0;
1373 * Updates the page URL (hash) to reflect the current
1376 * @param {Number} delay The time in ms to wait before
1379 function writeURL( delay ) {
1381 if( config.history ) {
1383 // Make sure there's never more than one timeout running
1384 clearTimeout( writeURLTimeout );
1386 // If a delay is specified, timeout this call
1387 if( typeof delay === 'number' ) {
1388 writeURLTimeout = setTimeout( writeURL, delay );
1393 // If the current slide has an ID, use that as a named link
1394 if( currentSlide && typeof currentSlide.getAttribute( 'id' ) === 'string' ) {
1395 url = '/' + currentSlide.getAttribute( 'id' );
1397 // Otherwise use the /h/v index
1399 if( indexh > 0 || indexv > 0 ) url += indexh;
1400 if( indexv > 0 ) url += '/' + indexv;
1403 window.location.hash = url;
1410 * Retrieves the h/v location of the current, or specified,
1413 * @param {HTMLElement} slide If specified, the returned
1414 * index will be for this slide rather than the currently
1417 * @return {Object} { h: <int>, v: <int> }
1419 function getIndices( slide ) {
1421 // By default, return the current indices
1425 // If a slide is specified, return the indices of that slide
1427 var isVertical = !!slide.parentNode.nodeName.match( /section/gi );
1428 var slideh = isVertical ? slide.parentNode : slide;
1430 // Select all horizontal slides
1431 var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
1433 // Now that we know which the horizontal slide is, get its index
1434 h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
1436 // If this is a vertical slide, grab the vertical index
1438 v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
1442 return { h: h, v: v };
1447 * Navigate to the next slide fragment.
1449 * @return {Boolean} true if there was a next fragment,
1452 function nextFragment() {
1455 if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
1456 var verticalFragments = sortFragments( document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' ) );
1458 if( verticalFragments.length ) {
1459 verticalFragments[0].classList.add( 'visible' );
1461 // Notify subscribers of the change
1462 dispatchEvent( 'fragmentshown', { fragment: verticalFragments[0] } );
1466 // Horizontal slides:
1468 var horizontalFragments = sortFragments( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' ) );
1470 if( horizontalFragments.length ) {
1471 horizontalFragments[0].classList.add( 'visible' );
1473 // Notify subscribers of the change
1474 dispatchEvent( 'fragmentshown', { fragment: horizontalFragments[0] } );
1484 * Navigate to the previous slide fragment.
1486 * @return {Boolean} true if there was a previous fragment,
1489 function previousFragment() {
1492 if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
1493 var verticalFragments = sortFragments( document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment.visible' ) );
1495 if( verticalFragments.length ) {
1496 verticalFragments[ verticalFragments.length - 1 ].classList.remove( 'visible' );
1498 // Notify subscribers of the change
1499 dispatchEvent( 'fragmenthidden', { fragment: verticalFragments[ verticalFragments.length - 1 ] } );
1503 // Horizontal slides:
1505 var horizontalFragments = sortFragments( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment.visible' ) );
1507 if( horizontalFragments.length ) {
1508 horizontalFragments[ horizontalFragments.length - 1 ].classList.remove( 'visible' );
1510 // Notify subscribers of the change
1511 dispatchEvent( 'fragmenthidden', { fragment: horizontalFragments[ horizontalFragments.length - 1 ] } );
1521 * Cues a new automated slide if enabled in the config.
1523 function cueAutoSlide() {
1525 clearTimeout( autoSlideTimeout );
1527 // Cue the next auto-slide if enabled
1528 if( autoSlide && !isPaused() && !isOverview() ) {
1529 autoSlideTimeout = setTimeout( navigateNext, autoSlide );
1535 * Cancels any ongoing request to auto-slide.
1537 function cancelAutoSlide() {
1539 clearTimeout( autoSlideTimeout );
1543 function navigateLeft() {
1545 // Prioritize hiding fragments
1546 if( availableRoutes().left && isOverview() || previousFragment() === false ) {
1547 slide( indexh - 1 );
1552 function navigateRight() {
1554 // Prioritize revealing fragments
1555 if( availableRoutes().right && isOverview() || nextFragment() === false ) {
1556 slide( indexh + 1 );
1561 function navigateUp() {
1563 // Prioritize hiding fragments
1564 if( availableRoutes().up && isOverview() || previousFragment() === false ) {
1565 slide( indexh, indexv - 1 );
1570 function navigateDown() {
1572 // Prioritize revealing fragments
1573 if( availableRoutes().down && isOverview() || nextFragment() === false ) {
1574 slide( indexh, indexv + 1 );
1580 * Navigates backwards, prioritized in the following order:
1581 * 1) Previous fragment
1582 * 2) Previous vertical slide
1583 * 3) Previous horizontal slide
1585 function navigatePrev() {
1587 // Prioritize revealing fragments
1588 if( previousFragment() === false ) {
1589 if( availableRoutes().up ) {
1593 // Fetch the previous horizontal slide, if there is one
1594 var previousSlide = document.querySelector( HORIZONTAL_SLIDES_SELECTOR + '.past:nth-child(' + indexh + ')' );
1596 if( previousSlide ) {
1597 indexv = ( previousSlide.querySelectorAll( 'section' ).length + 1 ) || undefined;
1607 * Same as #navigatePrev() but navigates forwards.
1609 function navigateNext() {
1611 // Prioritize revealing fragments
1612 if( nextFragment() === false ) {
1613 availableRoutes().down ? navigateDown() : navigateRight();
1616 // If auto-sliding is enabled we need to cue up
1623 // --------------------------------------------------------------------//
1624 // ----------------------------- EVENTS -------------------------------//
1625 // --------------------------------------------------------------------//
1629 * Handler for the document level 'keydown' event.
1631 * @param {Object} event
1633 function onDocumentKeyDown( event ) {
1635 // Check if there's a focused element that could be using
1637 var activeElement = document.activeElement;
1638 var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) );
1640 // Disregard the event if there's a focused element or a
1641 // keyboard modifier key is present
1642 if( hasFocus || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey ) return;
1644 var triggered = true;
1646 // while paused only allow "unpausing" keyboard events (b and .)
1647 if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) {
1651 switch( event.keyCode ) {
1653 case 80: case 33: navigatePrev(); break;
1655 case 78: case 34: navigateNext(); break;
1657 case 72: case 37: navigateLeft(); break;
1659 case 76: case 39: navigateRight(); break;
1661 case 75: case 38: navigateUp(); break;
1663 case 74: case 40: navigateDown(); break;
1665 case 36: slide( 0 ); break;
1667 case 35: slide( Number.MAX_VALUE ); break;
1669 case 32: isOverview() ? deactivateOverview() : navigateNext(); break;
1671 case 13: isOverview() ? deactivateOverview() : triggered = false; break;
1672 // b, period, Logitech presenter tools "black screen" button
1673 case 66: case 190: case 191: togglePause(); break;
1675 case 70: enterFullscreen(); break;
1680 // If the input resulted in a triggered action we should prevent
1681 // the browsers default behavior
1683 event.preventDefault();
1685 else if ( event.keyCode === 27 && supports3DTransforms ) {
1688 event.preventDefault();
1691 // If auto-sliding is enabled we need to cue up
1698 * Handler for the document level 'touchstart' event,
1699 * enables support for swipe and pinch gestures.
1701 function onDocumentTouchStart( event ) {
1703 touch.startX = event.touches[0].clientX;
1704 touch.startY = event.touches[0].clientY;
1705 touch.startCount = event.touches.length;
1707 // If there's two touches we need to memorize the distance
1708 // between those two points to detect pinching
1709 if( event.touches.length === 2 && config.overview ) {
1710 touch.startSpan = distanceBetween( {
1711 x: event.touches[1].clientX,
1712 y: event.touches[1].clientY
1722 * Handler for the document level 'touchmove' event.
1724 function onDocumentTouchMove( event ) {
1726 // Each touch should only trigger one action
1727 if( !touch.handled ) {
1728 var currentX = event.touches[0].clientX;
1729 var currentY = event.touches[0].clientY;
1731 // If the touch started off with two points and still has
1732 // two active touches; test for the pinch gesture
1733 if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
1735 // The current distance in pixels between the two touch points
1736 var currentSpan = distanceBetween( {
1737 x: event.touches[1].clientX,
1738 y: event.touches[1].clientY
1744 // If the span is larger than the desire amount we've got
1745 // ourselves a pinch
1746 if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
1747 touch.handled = true;
1749 if( currentSpan < touch.startSpan ) {
1753 deactivateOverview();
1757 event.preventDefault();
1760 // There was only one touch point, look for a swipe
1761 else if( event.touches.length === 1 && touch.startCount !== 2 ) {
1763 var deltaX = currentX - touch.startX,
1764 deltaY = currentY - touch.startY;
1766 if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
1767 touch.handled = true;
1770 else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
1771 touch.handled = true;
1774 else if( deltaY > touch.threshold ) {
1775 touch.handled = true;
1778 else if( deltaY < -touch.threshold ) {
1779 touch.handled = true;
1783 event.preventDefault();
1787 // There's a bug with swiping on some Android devices unless
1788 // the default action is always prevented
1789 else if( navigator.userAgent.match( /android/gi ) ) {
1790 event.preventDefault();
1796 * Handler for the document level 'touchend' event.
1798 function onDocumentTouchEnd( event ) {
1800 touch.handled = false;
1805 * Handles mouse wheel scrolling, throttled to avoid skipping
1808 function onDocumentMouseScroll( event ) {
1810 clearTimeout( mouseWheelTimeout );
1812 mouseWheelTimeout = setTimeout( function() {
1813 var delta = event.detail || -event.wheelDelta;
1825 * Clicking on the progress bar results in a navigation to the
1826 * closest approximate horizontal slide using this equation:
1828 * ( clickX / presentationWidth ) * numberOfSlides
1830 function onProgressClicked( event ) {
1832 event.preventDefault();
1834 var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
1835 var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
1837 slide( slideIndex );
1842 * Event handler for navigation control buttons.
1844 function onNavigateLeftClicked( event ) { event.preventDefault(); navigateLeft(); }
1845 function onNavigateRightClicked( event ) { event.preventDefault(); navigateRight(); }
1846 function onNavigateUpClicked( event ) { event.preventDefault(); navigateUp(); }
1847 function onNavigateDownClicked( event ) { event.preventDefault(); navigateDown(); }
1848 function onNavigatePrevClicked( event ) { event.preventDefault(); navigatePrev(); }
1849 function onNavigateNextClicked( event ) { event.preventDefault(); navigateNext(); }
1852 * Handler for the window level 'hashchange' event.
1854 function onWindowHashChange( event ) {
1861 * Handler for the window level 'resize' event.
1863 function onWindowResize( event ) {
1870 * Invoked when a slide is and we're in the overview.
1872 function onOverviewSlideClicked( event ) {
1874 // TODO There's a bug here where the event listeners are not
1875 // removed after deactivating the overview.
1876 if( eventsAreBound && isOverview() ) {
1877 event.preventDefault();
1879 var element = event.target;
1881 while( element && !element.nodeName.match( /section/gi ) ) {
1882 element = element.parentNode;
1885 if( element && !element.classList.contains( 'disabled' ) ) {
1887 deactivateOverview();
1889 if( element.nodeName.match( /section/gi ) ) {
1890 var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
1891 v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
1902 // --------------------------------------------------------------------//
1903 // ------------------------------- API --------------------------------//
1904 // --------------------------------------------------------------------//
1908 initialize: initialize,
1909 configure: configure,
1911 // Navigation methods
1914 right: navigateRight,
1919 prevFragment: previousFragment,
1920 nextFragment: nextFragment,
1922 // Deprecated aliases
1924 navigateLeft: navigateLeft,
1925 navigateRight: navigateRight,
1926 navigateUp: navigateUp,
1927 navigateDown: navigateDown,
1928 navigatePrev: navigatePrev,
1929 navigateNext: navigateNext,
1931 // Forces an update in slide layout
1934 // Toggles the overview mode on/off
1935 toggleOverview: toggleOverview,
1937 // Toggles the "black screen" mode on/off
1938 togglePause: togglePause,
1941 isOverview: isOverview,
1944 // Adds or removes all internal event listeners (such as keyboard)
1945 addEventListeners: addEventListeners,
1946 removeEventListeners: removeEventListeners,
1948 // Returns the indices of the current, or specified, slide
1949 getIndices: getIndices,
1951 // Returns the slide at the specified index, y is optional
1952 getSlide: function( x, y ) {
1953 var horizontalSlide = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
1954 var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
1956 if( typeof y !== 'undefined' ) {
1957 return verticalSlides ? verticalSlides[ y ] : undefined;
1960 return horizontalSlide;
1963 // Returns the previous slide element, may be null
1964 getPreviousSlide: function() {
1965 return previousSlide;
1968 // Returns the current slide element
1969 getCurrentSlide: function() {
1970 return currentSlide;
1973 // Returns the current scale of the presentation content
1974 getScale: function() {
1978 // Helper method, retrieves query string as a key/value hash
1979 getQueryHash: function() {
1982 location.search.replace( /[A-Z0-9]+?=(\w*)/gi, function(a) {
1983 query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
1989 // Returns true if we're currently on the first slide
1990 isFirstSlide: function() {
1991 return document.querySelector( SLIDES_SELECTOR + '.past' ) == null ? true : false;
1994 // Returns true if we're currently on the last slide
1995 isLastSlide: function() {
1996 if( currentSlide && currentSlide.classList.contains( '.stack' ) ) {
1997 return currentSlide.querySelector( SLIDES_SELECTOR + '.future' ) == null ? true : false;
2000 return document.querySelector( SLIDES_SELECTOR + '.future' ) == null ? true : false;
2004 // Forward event binding to the reveal DOM element
2005 addEventListener: function( type, listener, useCapture ) {
2006 if( 'addEventListener' in window ) {
2007 ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
2010 removeEventListener: function( type, listener, useCapture ) {
2011 if( 'addEventListener' in window ) {
2012 ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );