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 dom.wrapper.addEventListener( 'touchstart', onTouchStart, false );
420 dom.wrapper.addEventListener( 'touchmove', onTouchMove, false );
421 dom.wrapper.addEventListener( 'touchend', onTouchEnd, false );
423 // Support pointer-style touch interaction as well
424 if( window.navigator.msPointerEnabled ) {
425 dom.wrapper.addEventListener( 'MSPointerDown', onPointerDown, false );
426 dom.wrapper.addEventListener( 'MSPointerMove', onPointerMove, false );
427 dom.wrapper.addEventListener( 'MSPointerUp', onPointerUp, false );
431 if( config.keyboard ) {
432 document.addEventListener( 'keydown', onDocumentKeyDown, false );
435 if ( config.progress && dom.progress ) {
436 dom.progress.addEventListener( 'click', onProgressClicked, false );
439 if ( config.controls && dom.controls ) {
440 [ 'touchstart', 'click' ].forEach( function( eventName ) {
441 dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } );
442 dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } );
443 dom.controlsUp.forEach( function( el ) { el.addEventListener( eventName, onNavigateUpClicked, false ); } );
444 dom.controlsDown.forEach( function( el ) { el.addEventListener( eventName, onNavigateDownClicked, false ); } );
445 dom.controlsPrev.forEach( function( el ) { el.addEventListener( eventName, onNavigatePrevClicked, false ); } );
446 dom.controlsNext.forEach( function( el ) { el.addEventListener( eventName, onNavigateNextClicked, false ); } );
453 * Unbinds all event listeners.
455 function removeEventListeners() {
457 eventsAreBound = false;
459 document.removeEventListener( 'keydown', onDocumentKeyDown, false );
460 window.removeEventListener( 'hashchange', onWindowHashChange, false );
461 window.removeEventListener( 'resize', onWindowResize, false );
464 dom.wrapper.removeEventListener( 'touchstart', onTouchStart, false );
465 dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false );
466 dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false );
468 if( window.navigator.msPointerEnabled ) {
469 dom.wrapper.removeEventListener( 'MSPointerDown', onPointerDown, false );
470 dom.wrapper.removeEventListener( 'MSPointerMove', onPointerMove, false );
471 dom.wrapper.removeEventListener( 'MSPointerUp', onPointerUp, false );
475 if ( config.progress && dom.progress ) {
476 dom.progress.removeEventListener( 'click', onProgressClicked, false );
479 if ( config.controls && dom.controls ) {
480 [ 'touchstart', 'click' ].forEach( function( eventName ) {
481 dom.controlsLeft.forEach( function( el ) { el.removeEventListener( eventName, onNavigateLeftClicked, false ); } );
482 dom.controlsRight.forEach( function( el ) { el.removeEventListener( eventName, onNavigateRightClicked, false ); } );
483 dom.controlsUp.forEach( function( el ) { el.removeEventListener( eventName, onNavigateUpClicked, false ); } );
484 dom.controlsDown.forEach( function( el ) { el.removeEventListener( eventName, onNavigateDownClicked, false ); } );
485 dom.controlsPrev.forEach( function( el ) { el.removeEventListener( eventName, onNavigatePrevClicked, false ); } );
486 dom.controlsNext.forEach( function( el ) { el.removeEventListener( eventName, onNavigateNextClicked, false ); } );
493 * Extend object a with the properties of object b.
494 * If there's a conflict, object b takes precedence.
496 function extend( a, b ) {
505 * Converts the target object to an array.
507 function toArray( o ) {
509 return Array.prototype.slice.call( o );
514 * Measures the distance in pixels between point a
517 * @param {Object} a point with x/y properties
518 * @param {Object} b point with x/y properties
520 function distanceBetween( a, b ) {
525 return Math.sqrt( dx*dx + dy*dy );
530 * Causes the address bar to hide on mobile devices,
531 * more vertical space ftw.
533 function removeAddressBar() {
535 if( window.orientation === 0 ) {
536 document.documentElement.style.overflow = 'scroll';
537 document.body.style.height = '120%';
540 document.documentElement.style.overflow = '';
541 document.body.style.height = '100%';
544 setTimeout( function() {
545 window.scrollTo( 0, 1 );
551 * Dispatches an event of the specified type from the
552 * reveal DOM element.
554 function dispatchEvent( type, properties ) {
556 var event = document.createEvent( "HTMLEvents", 1, 2 );
557 event.initEvent( type, true, true );
558 extend( event, properties );
559 dom.wrapper.dispatchEvent( event );
564 * Wrap all links in 3D goodness.
566 function enable3DLinks() {
568 if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) {
569 var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
571 for( var i = 0, len = anchors.length; i < len; i++ ) {
572 var anchor = anchors[i];
574 if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
575 var span = document.createElement('span');
576 span.setAttribute('data-title', anchor.text);
577 span.innerHTML = anchor.innerHTML;
579 anchor.classList.add( 'roll' );
580 anchor.innerHTML = '';
581 anchor.appendChild(span);
589 * Unwrap all 3D links.
591 function disable3DLinks() {
593 var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
595 for( var i = 0, len = anchors.length; i < len; i++ ) {
596 var anchor = anchors[i];
597 var span = anchor.querySelector( 'span' );
600 anchor.classList.remove( 'roll' );
601 anchor.innerHTML = span.innerHTML;
608 * Return a sorted fragments list, ordered by an increasing
609 * "data-fragment-index" attribute.
611 * Fragments will be revealed in the order that they are returned by
612 * this function, so you can use the index attributes to control the
613 * order of fragment appearance.
615 * To maintain a sensible default fragment order, fragments are presumed
616 * to be passed in document order. This function adds a "fragment-index"
617 * attribute to each node if such an attribute is not already present,
618 * and sets that attribute to an integer value which is the position of
619 * the fragment within the fragments list.
621 function sortFragments( fragments ) {
623 var a = toArray( fragments );
625 a.forEach( function( el, idx ) {
626 if( !el.hasAttribute( 'data-fragment-index' ) ) {
627 el.setAttribute( 'data-fragment-index', idx );
631 a.sort( function( l, r ) {
632 return l.getAttribute( 'data-fragment-index' ) - r.getAttribute( 'data-fragment-index');
640 * Applies JavaScript-controlled layout rules to the
647 // Available space to scale within
648 var availableWidth = dom.wrapper.offsetWidth,
649 availableHeight = dom.wrapper.offsetHeight;
651 // Reduce available space by margin
652 availableWidth -= ( availableHeight * config.margin );
653 availableHeight -= ( availableHeight * config.margin );
655 // Dimensions of the content
656 var slideWidth = config.width,
657 slideHeight = config.height;
659 // Slide width may be a percentage of available width
660 if( typeof slideWidth === 'string' && /%$/.test( slideWidth ) ) {
661 slideWidth = parseInt( slideWidth, 10 ) / 100 * availableWidth;
664 // Slide height may be a percentage of available height
665 if( typeof slideHeight === 'string' && /%$/.test( slideHeight ) ) {
666 slideHeight = parseInt( slideHeight, 10 ) / 100 * availableHeight;
669 dom.slides.style.width = slideWidth + 'px';
670 dom.slides.style.height = slideHeight + 'px';
672 // Determine scale of content to fit within available space
673 scale = Math.min( availableWidth / slideWidth, availableHeight / slideHeight );
675 // Respect max/min scale settings
676 scale = Math.max( scale, config.minScale );
677 scale = Math.min( scale, config.maxScale );
679 // Prefer applying scale via zoom since Chrome blurs scaled content
680 // with nested transforms
681 if( typeof dom.slides.style.zoom !== 'undefined' && !navigator.userAgent.match( /(iphone|ipod|ipad|android)/gi ) ) {
682 dom.slides.style.zoom = scale;
684 // Apply scale transform as a fallback
686 var transform = 'translate(-50%, -50%) scale('+ scale +') translate(50%, 50%)';
688 dom.slides.style.WebkitTransform = transform;
689 dom.slides.style.MozTransform = transform;
690 dom.slides.style.msTransform = transform;
691 dom.slides.style.OTransform = transform;
692 dom.slides.style.transform = transform;
695 // Select all slides, vertical and horizontal
696 var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
698 for( var i = 0, len = slides.length; i < len; i++ ) {
699 var slide = slides[ i ];
701 // Don't bother updating invisible slides
702 if( slide.style.display === 'none' ) {
706 if( config.center ) {
707 // Vertical stacks are not centred since their section
709 if( slide.classList.contains( 'stack' ) ) {
713 slide.style.top = Math.max( - ( slide.offsetHeight / 2 ) - 20, -slideHeight / 2 ) + 'px';
717 slide.style.top = '';
727 * Stores the vertical index of a stack so that the same
728 * vertical slide can be selected when navigating to and
731 * @param {HTMLElement} stack The vertical stack element
732 * @param {int} v Index to memorize
734 function setPreviousVerticalIndex( stack, v ) {
736 if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
737 stack.setAttribute( 'data-previous-indexv', v || 0 );
743 * Retrieves the vertical index which was stored using
744 * #setPreviousVerticalIndex() or 0 if no previous index
747 * @param {HTMLElement} stack The vertical stack element
749 function getPreviousVerticalIndex( stack ) {
751 if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
752 return parseInt( stack.getAttribute( 'data-previous-indexv' ) || 0, 10 );
760 * Displays the overview of slides (quick nav) by
761 * scaling down and arranging all slide elements.
763 * Experimental feature, might be dropped if perf
766 function activateOverview() {
768 // Only proceed if enabled in config
769 if( config.overview ) {
771 // Don't auto-slide while in overview mode
774 var wasActive = dom.wrapper.classList.contains( 'overview' );
776 dom.wrapper.classList.add( 'overview' );
777 dom.wrapper.classList.remove( 'exit-overview' );
779 clearTimeout( activateOverviewTimeout );
780 clearTimeout( deactivateOverviewTimeout );
782 // Not the pretties solution, but need to let the overview
783 // class apply first so that slides are measured accurately
784 // before we can position them
785 activateOverviewTimeout = setTimeout( function(){
787 var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
789 for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
790 var hslide = horizontalSlides[i],
791 htransform = 'translateZ(-2500px) translate(' + ( ( i - indexh ) * 105 ) + '%, 0%)';
793 hslide.setAttribute( 'data-index-h', i );
794 hslide.style.display = 'block';
795 hslide.style.WebkitTransform = htransform;
796 hslide.style.MozTransform = htransform;
797 hslide.style.msTransform = htransform;
798 hslide.style.OTransform = htransform;
799 hslide.style.transform = htransform;
801 if( hslide.classList.contains( 'stack' ) ) {
803 var verticalSlides = hslide.querySelectorAll( 'section' );
805 for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
806 var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
808 var vslide = verticalSlides[j],
809 vtransform = 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)';
811 vslide.setAttribute( 'data-index-h', i );
812 vslide.setAttribute( 'data-index-v', j );
813 vslide.style.display = 'block';
814 vslide.style.WebkitTransform = vtransform;
815 vslide.style.MozTransform = vtransform;
816 vslide.style.msTransform = vtransform;
817 vslide.style.OTransform = vtransform;
818 vslide.style.transform = vtransform;
820 // Navigate to this slide on click
821 vslide.addEventListener( 'click', onOverviewSlideClicked, true );
827 // Navigate to this slide on click
828 hslide.addEventListener( 'click', onOverviewSlideClicked, true );
836 // Notify observers of the overview showing
837 dispatchEvent( 'overviewshown', {
840 'currentSlide': currentSlide
851 * Exits the slide overview and enters the currently
854 function deactivateOverview() {
856 // Only proceed if enabled in config
857 if( config.overview ) {
859 clearTimeout( activateOverviewTimeout );
860 clearTimeout( deactivateOverviewTimeout );
862 dom.wrapper.classList.remove( 'overview' );
864 // Temporarily add a class so that transitions can do different things
865 // depending on whether they are exiting/entering overview, or just
866 // moving from slide to slide
867 dom.wrapper.classList.add( 'exit-overview' );
869 deactivateOverviewTimeout = setTimeout( function () {
870 dom.wrapper.classList.remove( 'exit-overview' );
874 var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
876 for( var i = 0, len = slides.length; i < len; i++ ) {
877 var element = slides[i];
879 element.style.display = '';
881 // Resets all transforms to use the external styles
882 element.style.WebkitTransform = '';
883 element.style.MozTransform = '';
884 element.style.msTransform = '';
885 element.style.OTransform = '';
886 element.style.transform = '';
888 element.removeEventListener( 'click', onOverviewSlideClicked, true );
891 slide( indexh, indexv );
895 // Notify observers of the overview hiding
896 dispatchEvent( 'overviewhidden', {
899 'currentSlide': currentSlide
906 * Toggles the slide overview mode on and off.
908 * @param {Boolean} override Optional flag which overrides the
909 * toggle logic and forcibly sets the desired state. True means
910 * overview is open, false means it's closed.
912 function toggleOverview( override ) {
914 if( typeof override === 'boolean' ) {
915 override ? activateOverview() : deactivateOverview();
918 isOverview() ? deactivateOverview() : activateOverview();
924 * Checks if the overview is currently active.
926 * @return {Boolean} true if the overview is active,
929 function isOverview() {
931 return dom.wrapper.classList.contains( 'overview' );
936 * Handling the fullscreen functionality via the fullscreen API
938 * @see http://fullscreen.spec.whatwg.org/
939 * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
941 function enterFullscreen() {
943 var element = document.body;
945 // Check which implementation is available
946 var requestMethod = element.requestFullScreen ||
947 element.webkitRequestFullScreen ||
948 element.mozRequestFullScreen ||
949 element.msRequestFullScreen;
951 if( requestMethod ) {
952 requestMethod.apply( element );
958 * Enters the paused mode which fades everything on screen to
963 var wasPaused = dom.wrapper.classList.contains( 'paused' );
966 dom.wrapper.classList.add( 'paused' );
968 if( wasPaused === false ) {
969 dispatchEvent( 'paused' );
975 * Exits from the paused mode.
979 var wasPaused = dom.wrapper.classList.contains( 'paused' );
982 dom.wrapper.classList.remove( 'paused' );
985 dispatchEvent( 'resumed' );
991 * Toggles the paused mode on and off.
993 function togglePause() {
1005 * Checks if we are currently in the paused mode.
1007 function isPaused() {
1009 return dom.wrapper.classList.contains( 'paused' );
1014 * Steps from the current point in the presentation to the
1015 * slide which matches the specified horizontal and vertical
1018 * @param {int} h Horizontal index of the target slide
1019 * @param {int} v Vertical index of the target slide
1020 * @param {int} f Optional index of a fragment within the
1021 * target slide to activate
1022 * @param {int} o Optional origin for use in multimaster environments
1024 function slide( h, v, f, o ) {
1026 // Remember where we were at before
1027 previousSlide = currentSlide;
1029 // Query all horizontal slides in the deck
1030 var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
1032 // If no vertical index is specified and the upcoming slide is a
1033 // stack, resume at its previous vertical index
1034 if( v === undefined ) {
1035 v = getPreviousVerticalIndex( horizontalSlides[ h ] );
1038 // If we were on a vertical stack, remember what vertical index
1039 // it was on so we can resume at the same position when returning
1040 if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
1041 setPreviousVerticalIndex( previousSlide.parentNode, indexv );
1044 // Remember the state before this slide
1045 var stateBefore = state.concat();
1047 // Reset the state array
1050 var indexhBefore = indexh,
1051 indexvBefore = indexv;
1053 // Activate and transition to the new slide
1054 indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
1055 indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
1059 // Apply the new state
1060 stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
1061 // Check if this state existed on the previous slide. If it
1062 // did, we will avoid adding it repeatedly
1063 for( var j = 0; j < stateBefore.length; j++ ) {
1064 if( stateBefore[j] === state[i] ) {
1065 stateBefore.splice( j, 1 );
1070 document.documentElement.classList.add( state[i] );
1072 // Dispatch custom event matching the state's name
1073 dispatchEvent( state[i] );
1076 // Clean up the remains of the previous state
1077 while( stateBefore.length ) {
1078 document.documentElement.classList.remove( stateBefore.pop() );
1081 // If the overview is active, re-activate it to update positions
1082 if( isOverview() ) {
1086 // Update the URL hash after a delay since updating it mid-transition
1087 // is likely to cause visual lag
1090 // Find the current horizontal slide and any possible vertical slides
1092 var currentHorizontalSlide = horizontalSlides[ indexh ],
1093 currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
1095 // Store references to the previous and current slides
1096 currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
1099 // Show fragment, if specified
1100 if( typeof f !== 'undefined' ) {
1101 var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
1103 toArray( fragments ).forEach( function( fragment, indexf ) {
1105 fragment.classList.add( 'visible' );
1108 fragment.classList.remove( 'visible' );
1113 // Dispatch an event if the slide changed
1114 if( indexh !== indexhBefore || indexv !== indexvBefore ) {
1115 dispatchEvent( 'slidechanged', {
1118 'previousSlide': previousSlide,
1119 'currentSlide': currentSlide,
1124 // Ensure that the previous slide is never the same as the current
1125 previousSlide = null;
1128 // Solves an edge case where the previous slide maintains the
1129 // 'present' class when navigating between adjacent vertical
1131 if( previousSlide ) {
1132 previousSlide.classList.remove( 'present' );
1134 // Reset all slides upon navigate to home
1136 if ( document.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
1137 // Launch async task
1138 setTimeout( function () {
1139 var slides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
1140 for( i in slides ) {
1143 setPreviousVerticalIndex( slides[i], 0 );
1156 * Updates one dimension of slides by showing the slide
1157 * with the specified index.
1159 * @param {String} selector A CSS selector that will fetch
1160 * the group of slides we are working with
1161 * @param {Number} index The index of the slide that should be
1164 * @return {Number} The index of the slide that is now shown,
1165 * might differ from the passed in index if it was out of
1168 function updateSlides( selector, index ) {
1170 // Select all slides and convert the NodeList result to
1172 var slides = toArray( document.querySelectorAll( selector ) ),
1173 slidesLength = slides.length;
1175 if( slidesLength ) {
1177 // Should the index loop?
1179 index %= slidesLength;
1182 index = slidesLength + index;
1186 // Enforce max and minimum index bounds
1187 index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
1189 for( var i = 0; i < slidesLength; i++ ) {
1190 var element = slides[i];
1192 // Optimization; hide all slides that are three or more steps
1193 // away from the present slide
1194 if( isOverview() === false ) {
1195 // The distance loops so that it measures 1 between the first
1197 var distance = Math.abs( ( index - i ) % ( slidesLength - 3 ) ) || 0;
1199 element.style.display = distance > 3 ? 'none' : 'block';
1202 slides[i].classList.remove( 'past' );
1203 slides[i].classList.remove( 'present' );
1204 slides[i].classList.remove( 'future' );
1207 // Any element previous to index is given the 'past' class
1208 slides[i].classList.add( 'past' );
1210 else if( i > index ) {
1211 // Any element subsequent to index is given the 'future' class
1212 slides[i].classList.add( 'future' );
1215 // If this element contains vertical slides
1216 if( element.querySelector( 'section' ) ) {
1217 slides[i].classList.add( 'stack' );
1221 // Mark the current slide as present
1222 slides[index].classList.add( 'present' );
1224 // If this slide has a state associated with it, add it
1225 // onto the current state of the deck
1226 var slideState = slides[index].getAttribute( 'data-state' );
1228 state = state.concat( slideState.split( ' ' ) );
1231 // If this slide has a data-autoslide attribtue associated use this as
1232 // autoSlide value otherwise use the global configured time
1233 var slideAutoSlide = slides[index].getAttribute( 'data-autoslide' );
1234 if( slideAutoSlide ) {
1235 autoSlide = parseInt( slideAutoSlide, 10 );
1238 autoSlide = config.autoSlide;
1243 // Since there are no slides we can't be anywhere beyond the
1253 * Updates the progress bar to reflect the current slide.
1255 function updateProgress() {
1257 // Update progress if enabled
1258 if( config.progress && dom.progress ) {
1260 var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
1262 // The number of past and total slides
1263 var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
1266 // Step through all slides and count the past ones
1267 mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
1269 var horizontalSlide = horizontalSlides[i];
1270 var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
1272 for( var j = 0; j < verticalSlides.length; j++ ) {
1274 // Stop as soon as we arrive at the present
1275 if( verticalSlides[j].classList.contains( 'present' ) ) {
1283 // Stop as soon as we arrive at the present
1284 if( horizontalSlide.classList.contains( 'present' ) ) {
1288 // Don't count the wrapping section for vertical slides
1289 if( horizontalSlide.classList.contains( 'stack' ) === false ) {
1295 dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px';
1302 * Updates the state of all control/navigation arrows.
1304 function updateControls() {
1306 if ( config.controls && dom.controls ) {
1308 var routes = availableRoutes();
1310 // Remove the 'enabled' class from all directions
1311 dom.controlsLeft.concat( dom.controlsRight )
1312 .concat( dom.controlsUp )
1313 .concat( dom.controlsDown )
1314 .concat( dom.controlsPrev )
1315 .concat( dom.controlsNext ).forEach( function( node ) {
1316 node.classList.remove( 'enabled' );
1319 // Add the 'enabled' class to the available routes
1320 if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1321 if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1322 if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1323 if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1325 // Prev/next buttons
1326 if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1327 if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
1334 * Determine what available routes there are for navigation.
1336 * @return {Object} containing four booleans: left/right/up/down
1338 function availableRoutes() {
1340 var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
1341 verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
1344 left: indexh > 0 || config.loop,
1345 right: indexh < horizontalSlides.length - 1 || config.loop,
1347 down: indexv < verticalSlides.length - 1
1353 * Reads the current URL (hash) and navigates accordingly.
1355 function readURL() {
1357 var hash = window.location.hash;
1359 // Attempt to parse the hash as either an index or name
1360 var bits = hash.slice( 2 ).split( '/' ),
1361 name = hash.replace( /#|\//gi, '' );
1363 // If the first bit is invalid and there is a name we can
1364 // assume that this is a named link
1365 if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
1366 // Find the slide with the specified name
1367 var element = document.querySelector( '#' + name );
1370 // Find the position of the named slide and navigate to it
1371 var indices = Reveal.getIndices( element );
1372 slide( indices.h, indices.v );
1374 // If the slide doesn't exist, navigate to the current slide
1376 slide( indexh, indexv );
1380 // Read the index components of the hash
1381 var h = parseInt( bits[0], 10 ) || 0,
1382 v = parseInt( bits[1], 10 ) || 0;
1390 * Updates the page URL (hash) to reflect the current
1393 * @param {Number} delay The time in ms to wait before
1396 function writeURL( delay ) {
1398 if( config.history ) {
1400 // Make sure there's never more than one timeout running
1401 clearTimeout( writeURLTimeout );
1403 // If a delay is specified, timeout this call
1404 if( typeof delay === 'number' ) {
1405 writeURLTimeout = setTimeout( writeURL, delay );
1410 // If the current slide has an ID, use that as a named link
1411 if( currentSlide && typeof currentSlide.getAttribute( 'id' ) === 'string' ) {
1412 url = '/' + currentSlide.getAttribute( 'id' );
1414 // Otherwise use the /h/v index
1416 if( indexh > 0 || indexv > 0 ) url += indexh;
1417 if( indexv > 0 ) url += '/' + indexv;
1420 window.location.hash = url;
1427 * Retrieves the h/v location of the current, or specified,
1430 * @param {HTMLElement} slide If specified, the returned
1431 * index will be for this slide rather than the currently
1434 * @return {Object} { h: <int>, v: <int> }
1436 function getIndices( slide ) {
1438 // By default, return the current indices
1442 // If a slide is specified, return the indices of that slide
1444 var isVertical = !!slide.parentNode.nodeName.match( /section/gi );
1445 var slideh = isVertical ? slide.parentNode : slide;
1447 // Select all horizontal slides
1448 var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
1450 // Now that we know which the horizontal slide is, get its index
1451 h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
1453 // If this is a vertical slide, grab the vertical index
1455 v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
1459 return { h: h, v: v };
1464 * Navigate to the next slide fragment.
1466 * @return {Boolean} true if there was a next fragment,
1469 function nextFragment() {
1472 if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
1473 var verticalFragments = sortFragments( document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' ) );
1475 if( verticalFragments.length ) {
1476 verticalFragments[0].classList.add( 'visible' );
1478 // Notify subscribers of the change
1479 dispatchEvent( 'fragmentshown', { fragment: verticalFragments[0] } );
1483 // Horizontal slides:
1485 var horizontalFragments = sortFragments( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' ) );
1487 if( horizontalFragments.length ) {
1488 horizontalFragments[0].classList.add( 'visible' );
1490 // Notify subscribers of the change
1491 dispatchEvent( 'fragmentshown', { fragment: horizontalFragments[0] } );
1501 * Navigate to the previous slide fragment.
1503 * @return {Boolean} true if there was a previous fragment,
1506 function previousFragment() {
1509 if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
1510 var verticalFragments = sortFragments( document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment.visible' ) );
1512 if( verticalFragments.length ) {
1513 verticalFragments[ verticalFragments.length - 1 ].classList.remove( 'visible' );
1515 // Notify subscribers of the change
1516 dispatchEvent( 'fragmenthidden', { fragment: verticalFragments[ verticalFragments.length - 1 ] } );
1520 // Horizontal slides:
1522 var horizontalFragments = sortFragments( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment.visible' ) );
1524 if( horizontalFragments.length ) {
1525 horizontalFragments[ horizontalFragments.length - 1 ].classList.remove( 'visible' );
1527 // Notify subscribers of the change
1528 dispatchEvent( 'fragmenthidden', { fragment: horizontalFragments[ horizontalFragments.length - 1 ] } );
1538 * Cues a new automated slide if enabled in the config.
1540 function cueAutoSlide() {
1542 clearTimeout( autoSlideTimeout );
1544 // Cue the next auto-slide if enabled
1545 if( autoSlide && !isPaused() && !isOverview() ) {
1546 autoSlideTimeout = setTimeout( navigateNext, autoSlide );
1552 * Cancels any ongoing request to auto-slide.
1554 function cancelAutoSlide() {
1556 clearTimeout( autoSlideTimeout );
1560 function navigateLeft() {
1562 // Prioritize hiding fragments
1563 if( availableRoutes().left && ( isOverview() || previousFragment() === false ) ) {
1564 slide( indexh - 1 );
1569 function navigateRight() {
1571 // Prioritize revealing fragments
1572 if( availableRoutes().right && ( isOverview() || nextFragment() === false ) ) {
1573 slide( indexh + 1 );
1578 function navigateUp() {
1580 // Prioritize hiding fragments
1581 if( availableRoutes().up && isOverview() || previousFragment() === false ) {
1582 slide( indexh, indexv - 1 );
1587 function navigateDown() {
1589 // Prioritize revealing fragments
1590 if( availableRoutes().down && isOverview() || nextFragment() === false ) {
1591 slide( indexh, indexv + 1 );
1597 * Navigates backwards, prioritized in the following order:
1598 * 1) Previous fragment
1599 * 2) Previous vertical slide
1600 * 3) Previous horizontal slide
1602 function navigatePrev() {
1604 // Prioritize revealing fragments
1605 if( previousFragment() === false ) {
1606 if( availableRoutes().up ) {
1610 // Fetch the previous horizontal slide, if there is one
1611 var previousSlide = document.querySelector( HORIZONTAL_SLIDES_SELECTOR + '.past:nth-child(' + indexh + ')' );
1613 if( previousSlide ) {
1614 indexv = ( previousSlide.querySelectorAll( 'section' ).length + 1 ) || undefined;
1624 * Same as #navigatePrev() but navigates forwards.
1626 function navigateNext() {
1628 // Prioritize revealing fragments
1629 if( nextFragment() === false ) {
1630 availableRoutes().down ? navigateDown() : navigateRight();
1633 // If auto-sliding is enabled we need to cue up
1640 // --------------------------------------------------------------------//
1641 // ----------------------------- EVENTS -------------------------------//
1642 // --------------------------------------------------------------------//
1646 * Handler for the document level 'keydown' event.
1648 * @param {Object} event
1650 function onDocumentKeyDown( event ) {
1652 // Check if there's a focused element that could be using
1654 var activeElement = document.activeElement;
1655 var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) );
1657 // Disregard the event if there's a focused element or a
1658 // keyboard modifier key is present
1659 if( hasFocus || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey ) return;
1661 var triggered = true;
1663 // while paused only allow "unpausing" keyboard events (b and .)
1664 if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) {
1668 switch( event.keyCode ) {
1670 case 80: case 33: navigatePrev(); break;
1672 case 78: case 34: navigateNext(); break;
1674 case 72: case 37: navigateLeft(); break;
1676 case 76: case 39: navigateRight(); break;
1678 case 75: case 38: navigateUp(); break;
1680 case 74: case 40: navigateDown(); break;
1682 case 36: slide( 0 ); break;
1684 case 35: slide( Number.MAX_VALUE ); break;
1686 case 32: isOverview() ? deactivateOverview() : navigateNext(); break;
1688 case 13: isOverview() ? deactivateOverview() : triggered = false; break;
1689 // b, period, Logitech presenter tools "black screen" button
1690 case 66: case 190: case 191: togglePause(); break;
1692 case 70: enterFullscreen(); break;
1697 // If the input resulted in a triggered action we should prevent
1698 // the browsers default behavior
1700 event.preventDefault();
1702 else if ( event.keyCode === 27 && supports3DTransforms ) {
1705 event.preventDefault();
1708 // If auto-sliding is enabled we need to cue up
1715 * Handler for the 'touchstart' event, enables support for
1716 * swipe and pinch gestures.
1718 function onTouchStart( event ) {
1720 touch.startX = event.touches[0].clientX;
1721 touch.startY = event.touches[0].clientY;
1722 touch.startCount = event.touches.length;
1724 // If there's two touches we need to memorize the distance
1725 // between those two points to detect pinching
1726 if( event.touches.length === 2 && config.overview ) {
1727 touch.startSpan = distanceBetween( {
1728 x: event.touches[1].clientX,
1729 y: event.touches[1].clientY
1739 * Handler for the 'touchmove' event.
1741 function onTouchMove( event ) {
1743 // Each touch should only trigger one action
1744 if( !touch.handled ) {
1745 var currentX = event.touches[0].clientX;
1746 var currentY = event.touches[0].clientY;
1748 // If the touch started off with two points and still has
1749 // two active touches; test for the pinch gesture
1750 if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
1752 // The current distance in pixels between the two touch points
1753 var currentSpan = distanceBetween( {
1754 x: event.touches[1].clientX,
1755 y: event.touches[1].clientY
1761 // If the span is larger than the desire amount we've got
1762 // ourselves a pinch
1763 if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
1764 touch.handled = true;
1766 if( currentSpan < touch.startSpan ) {
1770 deactivateOverview();
1774 event.preventDefault();
1777 // There was only one touch point, look for a swipe
1778 else if( event.touches.length === 1 && touch.startCount !== 2 ) {
1780 var deltaX = currentX - touch.startX,
1781 deltaY = currentY - touch.startY;
1783 if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
1784 touch.handled = true;
1787 else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
1788 touch.handled = true;
1791 else if( deltaY > touch.threshold ) {
1792 touch.handled = true;
1795 else if( deltaY < -touch.threshold ) {
1796 touch.handled = true;
1800 event.preventDefault();
1804 // There's a bug with swiping on some Android devices unless
1805 // the default action is always prevented
1806 else if( navigator.userAgent.match( /android/gi ) ) {
1807 event.preventDefault();
1813 * Handler for the 'touchend' event.
1815 function onTouchEnd( event ) {
1817 touch.handled = false;
1822 * Convert pointer down to touch start.
1824 function onPointerDown( event ) {
1826 if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
1827 event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
1828 onTouchStart( event );
1834 * Convert pointer move to touch move.
1836 function onPointerMove( event ) {
1838 if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
1839 event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
1840 onTouchMove( event );
1846 * Convert pointer up to touch end.
1848 function onPointerUp( event ) {
1850 if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
1851 event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
1852 onTouchEnd( event );
1858 * Handles mouse wheel scrolling, throttled to avoid skipping
1861 function onDocumentMouseScroll( event ) {
1863 clearTimeout( mouseWheelTimeout );
1865 mouseWheelTimeout = setTimeout( function() {
1866 var delta = event.detail || -event.wheelDelta;
1878 * Clicking on the progress bar results in a navigation to the
1879 * closest approximate horizontal slide using this equation:
1881 * ( clickX / presentationWidth ) * numberOfSlides
1883 function onProgressClicked( event ) {
1885 event.preventDefault();
1887 var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
1888 var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
1890 slide( slideIndex );
1895 * Event handler for navigation control buttons.
1897 function onNavigateLeftClicked( event ) { event.preventDefault(); navigateLeft(); }
1898 function onNavigateRightClicked( event ) { event.preventDefault(); navigateRight(); }
1899 function onNavigateUpClicked( event ) { event.preventDefault(); navigateUp(); }
1900 function onNavigateDownClicked( event ) { event.preventDefault(); navigateDown(); }
1901 function onNavigatePrevClicked( event ) { event.preventDefault(); navigatePrev(); }
1902 function onNavigateNextClicked( event ) { event.preventDefault(); navigateNext(); }
1905 * Handler for the window level 'hashchange' event.
1907 function onWindowHashChange( event ) {
1914 * Handler for the window level 'resize' event.
1916 function onWindowResize( event ) {
1923 * Invoked when a slide is and we're in the overview.
1925 function onOverviewSlideClicked( event ) {
1927 // TODO There's a bug here where the event listeners are not
1928 // removed after deactivating the overview.
1929 if( eventsAreBound && isOverview() ) {
1930 event.preventDefault();
1932 var element = event.target;
1934 while( element && !element.nodeName.match( /section/gi ) ) {
1935 element = element.parentNode;
1938 if( element && !element.classList.contains( 'disabled' ) ) {
1940 deactivateOverview();
1942 if( element.nodeName.match( /section/gi ) ) {
1943 var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
1944 v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
1955 // --------------------------------------------------------------------//
1956 // ------------------------------- API --------------------------------//
1957 // --------------------------------------------------------------------//
1961 initialize: initialize,
1962 configure: configure,
1964 // Navigation methods
1967 right: navigateRight,
1972 prevFragment: previousFragment,
1973 nextFragment: nextFragment,
1975 // Deprecated aliases
1977 navigateLeft: navigateLeft,
1978 navigateRight: navigateRight,
1979 navigateUp: navigateUp,
1980 navigateDown: navigateDown,
1981 navigatePrev: navigatePrev,
1982 navigateNext: navigateNext,
1984 // Forces an update in slide layout
1987 // Toggles the overview mode on/off
1988 toggleOverview: toggleOverview,
1990 // Toggles the "black screen" mode on/off
1991 togglePause: togglePause,
1994 isOverview: isOverview,
1997 // Adds or removes all internal event listeners (such as keyboard)
1998 addEventListeners: addEventListeners,
1999 removeEventListeners: removeEventListeners,
2001 // Returns the indices of the current, or specified, slide
2002 getIndices: getIndices,
2004 // Returns the slide at the specified index, y is optional
2005 getSlide: function( x, y ) {
2006 var horizontalSlide = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
2007 var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
2009 if( typeof y !== 'undefined' ) {
2010 return verticalSlides ? verticalSlides[ y ] : undefined;
2013 return horizontalSlide;
2016 // Returns the previous slide element, may be null
2017 getPreviousSlide: function() {
2018 return previousSlide;
2021 // Returns the current slide element
2022 getCurrentSlide: function() {
2023 return currentSlide;
2026 // Returns the current scale of the presentation content
2027 getScale: function() {
2031 // Returns the current configuration object
2032 getConfig: function() {
2036 // Helper method, retrieves query string as a key/value hash
2037 getQueryHash: function() {
2040 location.search.replace( /[A-Z0-9]+?=(\w*)/gi, function(a) {
2041 query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
2047 // Returns true if we're currently on the first slide
2048 isFirstSlide: function() {
2049 return document.querySelector( SLIDES_SELECTOR + '.past' ) == null ? true : false;
2052 // Returns true if we're currently on the last slide
2053 isLastSlide: function() {
2054 if( currentSlide && currentSlide.classList.contains( '.stack' ) ) {
2055 return currentSlide.querySelector( SLIDES_SELECTOR + '.future' ) == null ? true : false;
2058 return document.querySelector( SLIDES_SELECTOR + '.future' ) == null ? true : false;
2062 // Forward event binding to the reveal DOM element
2063 addEventListener: function( type, listener, useCapture ) {
2064 if( 'addEventListener' in window ) {
2065 ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
2068 removeEventListener: function( type, listener, useCapture ) {
2069 if( 'addEventListener' in window ) {
2070 ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );