Skip to content
Snippets Groups Projects
reveal.js 101 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
    		if( horizontalSlidesLength ) {
    
    			// The number of steps away from the present slide that will
    			// be visible
    
    			var viewDistance = isOverview() ? 10 : config.viewDistance;
    
    			// Limit view distance on weaker devices
    
    				viewDistance = isOverview() ? 6 : 1;
    
    			// Limit view distance on weaker devices
    			if( isPrintingPDF() ) {
    				viewDistance = Number.MAX_VALUE;
    			}
    
    
    			for( var x = 0; x < horizontalSlidesLength; x++ ) {
    				var horizontalSlide = horizontalSlides[x];
    
    				var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) ),
    					verticalSlidesLength = verticalSlides.length;
    
    
    				// Loops so that it measures 1 between the first and last slides
    				distanceX = Math.abs( ( indexh - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0;
    
    
    				// Show the horizontal slide if it's within the view distance
    
    				if( distanceX < viewDistance ) {
    
    					horizontalSlide.style.display = 'block';
    
    					loadSlide( horizontalSlide );
    				}
    				else {
    					horizontalSlide.style.display = 'none';
    				}
    
    				if( verticalSlidesLength ) {
    
    					var oy = getPreviousVerticalIndex( horizontalSlide );
    
    
    					for( var y = 0; y < verticalSlidesLength; y++ ) {
    						var verticalSlide = verticalSlides[y];
    
    
    						distanceY = x === indexh ? Math.abs( indexv - y ) : Math.abs( y - oy );
    
    						if( distanceX + distanceY < viewDistance ) {
    
    							verticalSlide.style.display = 'block';
    
    							loadSlide( verticalSlide );
    						}
    						else {
    							verticalSlide.style.display = 'none';
    						}
    
    	 * Updates the progress bar to reflect the current slide.
    	 */
    	function updateProgress() {
    
    		// Update progress if enabled
    		if( config.progress && dom.progress ) {
    
    
    			dom.progressbar.style.width = getProgress() * window.innerWidth + 'px';
    
    	/**
    	 * Updates the slide number div to reflect the current slide.
    	 */
    	function updateSlideNumber() {
    
    		// Update slide number if enabled
    
    			// Display the number of the page using 'indexh - indexv' format
    
    				indexString += ' - ' + indexv;
    
    			dom.slideNumber.innerHTML = indexString;
    
    	/**
    	 * Updates the state of all control/navigation arrows.
    
    		var routes = availableRoutes();
    		var fragments = availableFragments();
    
    		// Remove the 'enabled' class from all directions
    		dom.controlsLeft.concat( dom.controlsRight )
    						.concat( dom.controlsUp )
    						.concat( dom.controlsDown )
    						.concat( dom.controlsPrev )
    						.concat( dom.controlsNext ).forEach( function( node ) {
    			node.classList.remove( 'enabled' );
    			node.classList.remove( 'fragmented' );
    		} );
    
    		// Add the 'enabled' class to the available routes
    		if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' );	} );
    		if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
    		if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' );	} );
    		if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
    
    		// Prev/next buttons
    		if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
    		if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
    
    		// Highlight fragment directions
    		if( currentSlide ) {
    
    			// Always apply fragment decorator to prev/next buttons
    			if( fragments.prev ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
    			if( fragments.next ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
    
    			// Apply fragment decorators to directional buttons based on
    			// what slide axis they are in
    			if( isVerticalSlide( currentSlide ) ) {
    				if( fragments.prev ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
    				if( fragments.next ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
    			}
    			else {
    				if( fragments.prev ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
    				if( fragments.next ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
    
    danielmitd's avatar
    danielmitd committed
    		}
    
    	 * Updates the background elements to reflect the current
    
    	 *
    	 * @param {Boolean} includeAll If true, the backgrounds of
    	 * all vertical slides (not just the present) will be updated.
    
    	function updateBackground( includeAll ) {
    
    		var currentBackground = null;
    
    		// Reverse past/future classes when in RTL mode
    		var horizontalPast = config.rtl ? 'future' : 'past',
    			horizontalFuture = config.rtl ? 'past' : 'future';
    
    
    		// Update the classes of all backgrounds to match the
    
    		// states of their slides (past/present/future)
    
    		toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) {
    
    
    			backgroundh.classList.remove( 'past' );
    			backgroundh.classList.remove( 'present' );
    			backgroundh.classList.remove( 'future' );
    
    
    				backgroundh.classList.add( horizontalPast );
    
    			}
    			else if ( h > indexh ) {
    
    				backgroundh.classList.add( horizontalFuture );
    
    				backgroundh.classList.add( 'present' );
    
    
    				// Store a reference to the current background element
    				currentBackground = backgroundh;
    			}
    
    			if( includeAll || h === indexh ) {
    
    				toArray( backgroundh.querySelectorAll( '.slide-background' ) ).forEach( function( backgroundv, v ) {
    
    					backgroundv.classList.remove( 'past' );
    					backgroundv.classList.remove( 'present' );
    					backgroundv.classList.remove( 'future' );
    
    
    						backgroundv.classList.add( 'past' );
    
    						backgroundv.classList.add( 'future' );
    
    						backgroundv.classList.add( 'present' );
    
    						// Only if this is the present horizontal and vertical slide
    						if( h === indexh ) currentBackground = backgroundv;
    					}
    
    		// Stop any currently playing video background
    		if( previousBackground ) {
    
    			var previousVideo = previousBackground.querySelector( 'video' );
    			if( previousVideo ) previousVideo.pause();
    
    		}
    
    
    		if( currentBackground ) {
    
    
    			// Start video playback
    			var currentVideo = currentBackground.querySelector( 'video' );
    			if( currentVideo ) currentVideo.play();
    
    			// Don't transition between identical backgrounds. This
    			// prevents unwanted flicker.
    
    			var previousBackgroundHash = previousBackground ? previousBackground.getAttribute( 'data-background-hash' ) : null;
    
    			var currentBackgroundHash = currentBackground.getAttribute( 'data-background-hash' );
    
    			if( currentBackgroundHash && currentBackgroundHash === previousBackgroundHash && currentBackground !== previousBackground ) {
    
    				dom.background.classList.add( 'no-transition' );
    			}
    
    
    			previousBackground = currentBackground;
    
    		// Allow the first background to apply without transition
    		setTimeout( function() {
    			dom.background.classList.remove( 'no-transition' );
    		}, 1 );
    
    
    	/**
    	 * Updates the position of the parallax background based
    	 * on the current slide index.
    	 */
    	function updateParallax() {
    
    
    		if( config.parallaxBackgroundImage ) {
    
    			var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
    				verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
    
    			var backgroundSize = dom.background.style.backgroundSize.split( ' ' ),
    
    				backgroundWidth, backgroundHeight;
    
    			if( backgroundSize.length === 1 ) {
    				backgroundWidth = backgroundHeight = parseInt( backgroundSize[0], 10 );
    			}
    			else {
    				backgroundWidth = parseInt( backgroundSize[0], 10 );
    				backgroundHeight = parseInt( backgroundSize[1], 10 );
    			}
    
    
    			var slideWidth = dom.background.offsetWidth;
    
    			var horizontalSlideCount = horizontalSlides.length;
    			var horizontalOffset = -( backgroundWidth - slideWidth ) / ( horizontalSlideCount-1 ) * indexh;
    
    
    			var slideHeight = dom.background.offsetHeight;
    
    			var verticalSlideCount = verticalSlides.length;
    
    			var verticalOffset = verticalSlideCount > 1 ? -( backgroundHeight - slideHeight ) / ( verticalSlideCount-1 ) * indexv : 0;
    
    			dom.background.style.backgroundPosition = horizontalOffset + 'px ' + verticalOffset + 'px';
    
    	/**
    	 * Loads any content that is set to load lazily (data-src)
    	 * inside of the given slide.
    	 */
    	function loadSlide( slide ) {
    
    
    		// Media elements with data-src attributes
    
    		toArray( slide.querySelectorAll( 'img[data-src], video[data-src], audio[data-src], iframe[data-src]' ) ).forEach( function( element ) {
    
    			element.setAttribute( 'src', element.getAttribute( 'data-src' ) );
    			element.removeAttribute( 'data-src' );
    		} );
    
    
    		// Media elements with multiple <source>s
    		toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( media ) {
    
    			toArray( media.querySelectorAll( 'source[data-src]' ) ).forEach( function( source ) {
    
    				source.setAttribute( 'src', source.getAttribute( 'data-src' ) );
    				source.removeAttribute( 'data-src' );
    				sources += 1;
    			} );
    
    
    			// If we rewrote sources for this video/audio element, we need
    			// to manually tell it to load from its new origin
    
    			if( sources > 0 ) {
    
    				media.load();
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	 * Determine what available routes there are for navigation.
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	 * @return {Object} containing four booleans: left/right/up/down
    
    		var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
    			verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
    
    			left: indexh > 0 || config.loop,
    			right: indexh < horizontalSlides.length - 1 || config.loop,
    
    			up: indexv > 0,
    			down: indexv < verticalSlides.length - 1
    		};
    
    		// reverse horizontal controls for rtl
    		if( config.rtl ) {
    			var left = routes.left;
    			routes.left = routes.right;
    			routes.right = left;
    		}
    
    		return routes;
    
    
    	/**
    	 * Returns an object describing the available fragment
    	 * directions.
    	 *
    	 * @return {Object} two boolean properties: prev/next
    	 */
    	function availableFragments() {
    
    
    		if( currentSlide && config.fragments ) {
    
    			var fragments = currentSlide.querySelectorAll( '.fragment' );
    			var hiddenFragments = currentSlide.querySelectorAll( '.fragment:not(.visible)' );
    
    			return {
    				prev: fragments.length - hiddenFragments.length > 0,
    				next: !!hiddenFragments.length
    			};
    		}
    		else {
    			return { prev: false, next: false };
    		}
    
    	}
    
    
    	/**
    	 * Start playback of any embedded content inside of
    	 * the targeted slide.
    	 */
    	function startEmbeddedContent( slide ) {
    
    
    		if( slide && !isSpeakerNotes() ) {
    
    			toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
    
    				if( el.hasAttribute( 'data-autoplay' ) ) {
    
    			// iframe embeds
    			toArray( slide.querySelectorAll( 'iframe' ) ).forEach( function( el ) {
    
    				el.contentWindow.postMessage( 'slide:start', '*' );
    
    			// YouTube embeds
    			toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
    
    				if( el.hasAttribute( 'data-autoplay' ) ) {
    
    					el.contentWindow.postMessage( '{"event":"command","func":"playVideo","args":""}', '*' );
    
    		}
    
    	}
    
    	/**
    	 * Stop playback of any embedded content inside of
    	 * the targeted slide.
    	 */
    	function stopEmbeddedContent( slide ) {
    
    		if( slide ) {
    
    			toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
    				if( !el.hasAttribute( 'data-ignore' ) ) {
    					el.pause();
    				}
    			} );
    
    			// iframe embeds
    			toArray( slide.querySelectorAll( 'iframe' ) ).forEach( function( el ) {
    
    				el.contentWindow.postMessage( 'slide:stop', '*' );
    
    			// YouTube embeds
    			toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
    				if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
    
    					el.contentWindow.postMessage( '{"event":"command","func":"pauseVideo","args":""}', '*' );
    
    	/**
    	 * Returns a value ranging from 0-1 that represents
    	 * how far into the presentation we have navigated.
    	 */
    	function getProgress() {
    
    		var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
    
    		// The number of past and total slides
    		var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
    		var pastCount = 0;
    
    		// Step through all slides and count the past ones
    		mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
    
    			var horizontalSlide = horizontalSlides[i];
    			var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
    
    			for( var j = 0; j < verticalSlides.length; j++ ) {
    
    				// Stop as soon as we arrive at the present
    				if( verticalSlides[j].classList.contains( 'present' ) ) {
    					break mainLoop;
    				}
    
    				pastCount++;
    
    			}
    
    			// Stop as soon as we arrive at the present
    			if( horizontalSlide.classList.contains( 'present' ) ) {
    				break;
    			}
    
    			// Don't count the wrapping section for vertical slides
    			if( horizontalSlide.classList.contains( 'stack' ) === false ) {
    				pastCount++;
    			}
    
    		}
    
    
    		if( currentSlide ) {
    
    			var allFragments = currentSlide.querySelectorAll( '.fragment' );
    
    			// If there are fragments in the current slide those should be
    			// accounted for in the progress.
    			if( allFragments.length > 0 ) {
    				var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
    
    				// This value represents how big a portion of the slide progress
    				// that is made up by its fragments (0-1)
    				var fragmentWeight = 0.9;
    
    				// Add fragment progress to the past slide count
    				pastCount += ( visibleFragments.length / allFragments.length ) * fragmentWeight;
    			}
    
    		}
    
    
    		return pastCount / ( totalCount - 1 );
    
    	}
    
    
    	/**
    	 * Checks if this presentation is running inside of the
    	 * speaker notes window.
    	 */
    	function isSpeakerNotes() {
    
    		return !!window.location.search.match( /receiver/gi );
    
    	}
    
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	/**
    	 * Reads the current URL (hash) and navigates accordingly.
    	 */
    	function readURL() {
    
    		var hash = window.location.hash;
    
    		// Attempt to parse the hash as either an index or name
    		var bits = hash.slice( 2 ).split( '/' ),
    			name = hash.replace( /#|\//gi, '' );
    
    
    		// If the first bit is invalid and there is a name we can
    
    		// assume that this is a named link
    
    		if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
    
    			var element;
    
    			try {
    				// Find the slide with the specified name
    				element = document.querySelector( '#' + name );
    			}
    			catch( e ) {
    				// If the ID is an invalid selector a harmless SyntaxError
    				// may be thrown here.
    			}
    
    				// Find the position of the named slide and navigate to it
    
    				var indices = Reveal.getIndices( element );
    				slide( indices.h, indices.v );
    
    			}
    			// If the slide doesn't exist, navigate to the current slide
    			else {
    
    			}
    		}
    		else {
    			// Read the index components of the hash
    
    			var h = parseInt( bits[0], 10 ) || 0,
    				v = parseInt( bits[1], 10 ) || 0;
    
    			if( h !== indexh || v !== indexv ) {
    				slide( h, v );
    			}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	/**
    	 * Updates the page URL (hash) to reflect the current
    
    	 * @param {Number} delay The time in ms to wait before
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	 */
    
    	function writeURL( delay ) {
    
    			// Make sure there's never more than one timeout running
    			clearTimeout( writeURLTimeout );
    
    			// If a delay is specified, timeout this call
    			if( typeof delay === 'number' ) {
    				writeURLTimeout = setTimeout( writeURL, delay );
    
    				// Attempt to create a named link based on the slide's ID
    				var id = currentSlide.getAttribute( 'id' );
    				if( id ) {
    					id = id.toLowerCase();
    					id = id.replace( /[^a-zA-Z0-9\-\_\:\.]/g, '' );
    				}
    
    
    				// If the current slide has an ID, use that as a named link
    
    				if( currentSlide && typeof id === 'string' && id.length ) {
    					url = '/' + id;
    
    				}
    				// Otherwise use the /h/v index
    				else {
    					if( indexh > 0 || indexv > 0 ) url += indexh;
    					if( indexv > 0 ) url += '/' + indexv;
    				}
    
    				window.location.hash = url;
    			}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    
    	 * Retrieves the h/v location of the current, or specified,
    
    	 *
    	 * @param {HTMLElement} slide If specified, the returned
    	 * index will be for this slide rather than the currently
    
    	 * @return {Object} { h: <int>, v: <int>, f: <int> }
    
    		// By default, return the current indices
    		var h = indexh,
    
    
    		// If a slide is specified, return the indices of that slide
    		if( slide ) {
    
    			var isVertical = isVerticalSlide( slide );
    
    			var slideh = isVertical ? slide.parentNode : slide;
    
    			// Select all horizontal slides
    
    			var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
    
    
    			// Now that we know which the horizontal slide is, get its index
    			h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
    
    			// If this is a vertical slide, grab the vertical index
    			if( isVertical ) {
    
    				v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
    
    			var hasFragments = currentSlide.querySelectorAll( '.fragment' ).length > 0;
    			if( hasFragments ) {
    				var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
    
    				f = visibleFragments.length - 1;
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	/**
    	 * Retrieves the total number of slides in this presentation.
    	 */
    	function getTotalSlides() {
    
    		return document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
    
    	}
    
    
    	/**
    	 * Retrieves the current state of the presentation as
    	 * an object. This state can then be restored at any
    	 * time.
    	 */
    	function getState() {
    
    		var indices = getIndices();
    
    		return {
    			indexh: indices.h,
    			indexv: indices.v,
    			indexf: indices.f,
    			paused: isPaused(),
    			overview: isOverview()
    		};
    
    	}
    
    	/**
    	 * Restores the presentation to the given state.
    	 *
    	 * @param {Object} state As generated by getState()
    	 */
    	function setState( state ) {
    
    		if( typeof state === 'object' ) {
    
    			slide( deserialize( state.indexh ), deserialize( state.indexv ), deserialize( state.indexf ) );
    
    
    			var pausedFlag = deserialize( state.paused ),
    				overviewFlag = deserialize( state.overview );
    
    			if( typeof pausedFlag === 'boolean' && pausedFlag !== isPaused() ) {
    				togglePause( pausedFlag );
    			}
    
    			if( typeof overviewFlag === 'boolean' && overviewFlag !== isOverview() ) {
    				toggleOverview( overviewFlag );
    			}
    
    	/**
    	 * Return a sorted fragments list, ordered by an increasing
    	 * "data-fragment-index" attribute.
    	 *
    	 * Fragments will be revealed in the order that they are returned by
    	 * this function, so you can use the index attributes to control the
    	 * order of fragment appearance.
    	 *
    	 * To maintain a sensible default fragment order, fragments are presumed
    	 * to be passed in document order. This function adds a "fragment-index"
    	 * attribute to each node if such an attribute is not already present,
    	 * and sets that attribute to an integer value which is the position of
    	 * the fragment within the fragments list.
    	 */
    	function sortFragments( fragments ) {
    
    		fragments = toArray( fragments );
    
    		var ordered = [],
    			unordered = [],
    			sorted = [];
    
    		// Group ordered and unordered elements
    		fragments.forEach( function( fragment, i ) {
    			if( fragment.hasAttribute( 'data-fragment-index' ) ) {
    				var index = parseInt( fragment.getAttribute( 'data-fragment-index' ), 10 );
    
    				if( !ordered[index] ) {
    					ordered[index] = [];
    				}
    
    				ordered[index].push( fragment );
    			}
    			else {
    				unordered.push( [ fragment ] );
    			}
    		} );
    
    		// Append fragments without explicit indices in their
    		// DOM order
    		ordered = ordered.concat( unordered );
    
    		// Manually count the index up per group to ensure there
    		// are no gaps
    		var index = 0;
    
    		// Push all fragments in their sorted order to an array,
    		// this flattens the groups
    		ordered.forEach( function( group ) {
    			group.forEach( function( fragment ) {
    				sorted.push( fragment );
    				fragment.setAttribute( 'data-fragment-index', index );
    			} );
    
    			index ++;
    		} );
    
    		return sorted;
    
    	}
    
    
    	 * Navigate to the specified slide fragment.
    
    	 * @param {Number} index The index of the fragment that
    
    	 * should be shown, -1 means all are invisible
    
    	 * @param {Number} offset Integer offset to apply to the
    	 * fragment index
    	 *
    	 * @return {Boolean} true if a change was made in any
    	 * fragments visibility as part of this call
    
    	function navigateFragment( index, offset ) {
    
    		if( currentSlide && config.fragments ) {
    
    			var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
    
    			if( fragments.length ) {
    
    				// If no index is specified, find the current
    
    				if( typeof index !== 'number' ) {
    					var lastVisibleFragment = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) ).pop();
    
    					if( lastVisibleFragment ) {
    
    						index = parseInt( lastVisibleFragment.getAttribute( 'data-fragment-index' ) || 0, 10 );
    
    						index = -1;
    
    				// If an offset is specified, apply it to the index
    
    				if( typeof offset === 'number' ) {
    					index += offset;
    				}
    
    				var fragmentsShown = [],
    					fragmentsHidden = [];
    
    				toArray( fragments ).forEach( function( element, i ) {
    
    
    					if( element.hasAttribute( 'data-fragment-index' ) ) {
    						i = parseInt( element.getAttribute( 'data-fragment-index' ), 10 );
    
    					// Visible fragments
    
    						if( !element.classList.contains( 'visible' ) ) fragmentsShown.push( element );
    						element.classList.add( 'visible' );
    						element.classList.remove( 'current-fragment' );
    
    						if( i === index ) {
    							element.classList.add( 'current-fragment' );
    						}
    					}
    
    					// Hidden fragments
    					else {
    						if( element.classList.contains( 'visible' ) ) fragmentsHidden.push( element );
    						element.classList.remove( 'visible' );
    						element.classList.remove( 'current-fragment' );
    					}
    
    				if( fragmentsHidden.length ) {
    
    					dispatchEvent( 'fragmenthidden', { fragment: fragmentsHidden[0], fragments: fragmentsHidden } );
    				}
    
    
    				if( fragmentsShown.length ) {
    
    					dispatchEvent( 'fragmentshown', { fragment: fragmentsShown[0], fragments: fragmentsShown } );
    				}
    
    
    				return !!( fragmentsShown.length || fragmentsHidden.length );
    
    
    	 * Navigate to the next slide fragment.
    
    	 * @return {Boolean} true if there was a next fragment,
    
    	function nextFragment() {
    
    		return navigateFragment( null, 1 );
    
    	/**
    	 * Navigate to the previous slide fragment.
    	 *
    	 * @return {Boolean} true if there was a previous fragment,
    	 * false otherwise
    	 */
    	function previousFragment() {
    
    		return navigateFragment( null, -1 );
    
    	/**
    	 * Cues a new automated slide if enabled in the config.
    	 */
    
    			var currentFragment = currentSlide.querySelector( '.current-fragment' );
    
    			var fragmentAutoSlide = currentFragment ? currentFragment.getAttribute( 'data-autoslide' ) : null;
    
    			var parentAutoSlide = currentSlide.parentNode ? currentSlide.parentNode.getAttribute( 'data-autoslide' ) : null;
    			var slideAutoSlide = currentSlide.getAttribute( 'data-autoslide' );
    
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    			// Pick value in the following priority order:
    
    			// 1. Current fragment's data-autoslide
    			// 2. Current slide's data-autoslide
    			// 3. Parent slide's data-autoslide
    			// 4. Global autoSlide setting
    			if( fragmentAutoSlide ) {
    				autoSlide = parseInt( fragmentAutoSlide, 10 );
    			}
    			else if( slideAutoSlide ) {
    
    				autoSlide = parseInt( slideAutoSlide, 10 );
    			}
    
    			else if( parentAutoSlide ) {
    				autoSlide = parseInt( parentAutoSlide, 10 );
    			}
    
    			// If there are media elements with data-autoplay,
    			// automatically set the autoSlide duration to the
    			// length of that media
    			toArray( currentSlide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
    				if( el.hasAttribute( 'data-autoplay' ) ) {
    					if( autoSlide && el.duration * 1000 > autoSlide ) {
    						autoSlide = ( el.duration * 1000 ) + 1000;
    					}
    				}
    			} );
    
    
    			// Cue the next auto-slide if:
    			// - There is an autoSlide value
    			// - Auto-sliding isn't paused by the user
    			// - The presentation isn't paused
    			// - The overview isn't active
    			// - The presentation isn't over
    			if( autoSlide && !autoSlidePaused && !isPaused() && !isOverview() && ( !Reveal.isLastSlide() || config.loop === true ) ) {
    				autoSlideTimeout = setTimeout( navigateNext, autoSlide );
    				autoSlideStartTime = Date.now();
    			}
    
    			if( autoSlidePlayer ) {
    				autoSlidePlayer.setPlaying( autoSlideTimeout !== -1 );
    			}
    
    	/**
    	 * Cancels any ongoing request to auto-slide.
    	 */
    	function cancelAutoSlide() {
    
    		clearTimeout( autoSlideTimeout );
    
    	function pauseAutoSlide() {
    
    
    		if( autoSlide && !autoSlidePaused ) {
    			autoSlidePaused = true;
    			dispatchEvent( 'autoslidepaused' );
    			clearTimeout( autoSlideTimeout );
    
    			if( autoSlidePlayer ) {
    				autoSlidePlayer.setPlaying( false );
    			}
    
    		if( autoSlide && autoSlidePaused ) {
    			autoSlidePaused = false;
    			dispatchEvent( 'autoslideresumed' );
    			cueAutoSlide();
    		}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	function navigateLeft() {
    
    		// Reverse for RTL
    		if( config.rtl ) {
    			if( ( isOverview() || nextFragment() === false ) && availableRoutes().left ) {
    				slide( indexh + 1 );
    			}
    		}
    		// Normal navigation
    		else if( ( isOverview() || previousFragment() === false ) && availableRoutes().left ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	function navigateRight() {
    
    		// Reverse for RTL
    		if( config.rtl ) {
    			if( ( isOverview() || previousFragment() === false ) && availableRoutes().right ) {
    				slide( indexh - 1 );
    			}
    		}
    		// Normal navigation
    		else if( ( isOverview() || nextFragment() === false ) && availableRoutes().right ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	function navigateUp() {
    
    		// Prioritize hiding fragments
    
    		if( ( isOverview() || previousFragment() === false ) && availableRoutes().up ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	function navigateDown() {
    
    		// Prioritize revealing fragments
    
    		if( ( isOverview() || nextFragment() === false ) && availableRoutes().down ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    
    
    	/**
    	 * Navigates backwards, prioritized in the following order:
    	 * 1) Previous fragment
    	 * 2) Previous vertical slide
    	 * 3) Previous horizontal slide
    	 */