Skip to content
Snippets Groups Projects
reveal.js 110 KiB
Newer Older
  • Learn to ignore specific revisions
  • 			verticalSlides.forEach( function( verticalSlide, y ) {
    
    
    				sortFragments( verticalSlide.querySelectorAll( '.fragment' ) );
    
    			} );
    
    			if( verticalSlides.length === 0 ) sortFragments( horizontalSlide.querySelectorAll( '.fragment' ) );
    
    		} );
    
    	}
    
    
    	/**
    	 * Updates one dimension of slides by showing the slide
    	 * with the specified index.
    
    	 * @param {String} selector A CSS selector that will fetch
    	 * the group of slides we are working with
    	 * @param {Number} index The index of the slide that should be
    	 * shown
    
    	 * @return {Number} The index of the slide that is now shown,
    
    	 * might differ from the passed in index if it was out of
    
    	 * bounds.
    	 */
    	function updateSlides( selector, index ) {
    
    		// Select all slides and convert the NodeList result to
    		// an array
    
    		var slides = toArray( dom.wrapper.querySelectorAll( selector ) ),
    
    		var printMode = isPrintingPDF();
    
    
    		if( slidesLength ) {
    
    			// Should the index loop?
    			if( config.loop ) {
    				index %= slidesLength;
    
    				if( index < 0 ) {
    					index = slidesLength + index;
    				}
    			}
    
    			// Enforce max and minimum index bounds
    			index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
    
    			for( var i = 0; i < slidesLength; i++ ) {
    				var element = slides[i];
    
    
    				var reverse = config.rtl && !isVerticalSlide( element );
    
    
    				element.classList.remove( 'past' );
    				element.classList.remove( 'present' );
    				element.classList.remove( 'future' );
    
    				// http://www.w3.org/html/wg/drafts/html/master/editing.html#the-hidden-attribute
    				element.setAttribute( 'hidden', '' );
    
    				element.setAttribute( 'aria-hidden', 'true' );
    
    				// If this element contains vertical slides
    				if( element.querySelector( 'section' ) ) {
    					element.classList.add( 'stack' );
    				}
    
    				// If we're printing static slides, all slides are "present"
    				if( printMode ) {
    					element.classList.add( 'present' );
    					continue;
    				}
    
    
    				if( i < index ) {
    					// Any element previous to index is given the 'past' class
    
    					element.classList.add( reverse ? 'future' : 'past' );
    
    					if( config.fragments ) {
    						var pastFragments = toArray( element.querySelectorAll( '.fragment' ) );
    
    						// Show all fragments on prior slides
    						while( pastFragments.length ) {
    							var pastFragment = pastFragments.pop();
    							pastFragment.classList.add( 'visible' );
    							pastFragment.classList.remove( 'current-fragment' );
    						}
    
    				}
    				else if( i > index ) {
    					// Any element subsequent to index is given the 'future' class
    
    					element.classList.add( reverse ? 'past' : 'future' );
    
    					if( config.fragments ) {
    						var futureFragments = toArray( element.querySelectorAll( '.fragment.visible' ) );
    
    						// No fragments in future slides should be visible ahead of time
    						while( futureFragments.length ) {
    							var futureFragment = futureFragments.pop();
    							futureFragment.classList.remove( 'visible' );
    							futureFragment.classList.remove( 'current-fragment' );
    						}
    
    				}
    			}
    
    			// Mark the current slide as present
    			slides[index].classList.add( 'present' );
    
    			slides[index].removeAttribute( 'hidden' );
    
    			slides[index].removeAttribute( 'aria-hidden' );
    
    
    			// If this slide has a state associated with it, add it
    			// onto the current state of the deck
    			var slideState = slides[index].getAttribute( 'data-state' );
    			if( slideState ) {
    				state = state.concat( slideState.split( ' ' ) );
    			}
    
    		}
    		else {
    
    			// Since there are no slides we can't be anywhere beyond the
    
    	/**
    	 * Optimization method; hide all slides that are far away
    	 * from the present slide.
    	 */
    	function updateSlidesVisibility() {
    
    		// Select all slides and convert the NodeList result to
    		// an array
    
    		var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ),
    
    
    		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 : 2;
    
    			// 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 ) {
    
    					showSlide( horizontalSlide );
    
    					hideSlide( horizontalSlide );
    
    				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 ) {
    
    							showSlide( verticalSlide );
    
    							hideSlide( verticalSlide );
    
    	 * Updates the progress bar to reflect the current slide.
    	 */
    	function updateProgress() {
    
    		// Update progress if enabled
    
    		if( config.progress && dom.progressbar ) {
    
    			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 = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
    				verticalSlides = dom.wrapper.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';
    
    	 * Called when the given slide is within the configured view
    	 * distance. Shows the slide element and loads any content
    	 * that is set to load lazily (data-src).
    
    	function showSlide( slide ) {
    
    
    		// Show the slide element
    
    		slide.style.display = 'block';
    
    		// 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 <source> children
    
    		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();
    
    
    		// Show the corresponding background element
    		var indices = getIndices( slide );
    		var background = getSlideBackground( indices.h, indices.v );
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    		if( background ) {
    			background.style.display = 'block';
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    			// If the background contains media, load it
    			if( background.hasAttribute( 'data-loaded' ) === false ) {
    				background.setAttribute( 'data-loaded', 'true' );
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    				var backgroundImage = slide.getAttribute( 'data-background-image' ),
    					backgroundVideo = slide.getAttribute( 'data-background-video' );
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    				// Images
    				if( backgroundImage ) {
    					background.style.backgroundImage = 'url('+ backgroundImage +')';
    				}
    				// Videos
    				else if ( backgroundVideo ) {
    
    					var video = document.createElement( 'video' );
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    					// Support comma separated lists of video sources
    					backgroundVideo.split( ',' ).forEach( function( source ) {
    						video.innerHTML += '<source src="'+ source +'">';
    					} );
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    					background.appendChild( video );
    				}
    
    	/**
    	 * Called when the given slide is moved outside of the
    	 * configured view distance.
    	 */
    	function hideSlide( slide ) {
    
    
    		// Hide the slide element
    
    		slide.style.display = 'none';
    
    
    		// Hide the corresponding background element
    		var indices = getIndices( slide );
    		var background = getSlideBackground( indices.h, indices.v );
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    		if( background ) {
    			background.style.display = 'none';
    		}
    
    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 = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
    			verticalSlides = dom.wrapper.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 };
    		}
    
    	}
    
    
    	 * Enforces origin-specific format rules for embedded media.
    
    	 */
    	function formatEmbeddedContent() {
    
    		// YouTube frames must include "?enablejsapi=1"
    		toArray( dom.slides.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
    			var src = el.getAttribute( 'src' );
    			if( !/enablejsapi\=1/gi.test( src ) ) {
    
    				el.setAttribute( 'src', src + ( !/\?/.test( src ) ? '?' : '&' ) + 'enablejsapi=1' );
    
    		// Vimeo frames must include "?api=1"
    		toArray( dom.slides.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( function( el ) {
    			var src = el.getAttribute( 'src' );
    			if( !/api\=1/gi.test( src ) ) {
    
    				el.setAttribute( 'src', src + ( !/\?/.test( src ) ? '?' : '&' ) + 'api=1' );
    
    	/**
    	 * 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":""}', '*' );
    
    
    			// Vimeo embeds
    			toArray( slide.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( function( el ) {
    				if( el.hasAttribute( 'data-autoplay' ) ) {
    					console.log(11);
    					el.contentWindow.postMessage( '{"method":"play"}', '*' );
    				}
    			});
    
    		}
    
    	}
    
    	/**
    	 * 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":""}', '*' );
    
    
    			// Vimeo embeds
    			toArray( slide.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( function( el ) {
    				if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
    					el.contentWindow.postMessage( '{"method":"pause"}', '*' );
    				}
    			});
    
    	/**
    	 * Returns a value ranging from 0-1 that represents
    	 * how far into the presentation we have navigated.
    	 */
    	function getProgress() {
    
    
    		var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
    
    
    		// The number of past and total slides
    
    		var totalCount = dom.wrapper.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 ) {
    
    			// Ensure the named link is a valid HTML ID attribute
    			if( /^[a-zA-Z][\w:.-]*$/.test( name ) ) {
    				// Find the slide with the specified ID
    
    				element = document.querySelector( '#' + name );
    			}
    
    				// 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 );
    
    			else if( currentSlide ) {
    
    				// 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( typeof id === 'string' && id.length ) {
    
    				}
    				// 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( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
    
    
    			// Now that we know which the horizontal slide is, get its index
    			h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
    
    
    			// Assume we're not vertical
    
    			// 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 dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
    
    	/**
    	 * Returns the slide element matching the specified index.
    	 */
    
    	function getSlide( x, y ) {
    
    
    		var horizontalSlide = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
    
    		var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
    
    
    		if( verticalSlides && verticalSlides.length && typeof y === 'number' ) {
    
    			return verticalSlides ? verticalSlides[ y ] : undefined;
    		}
    
    		return horizontalSlide;
    
    	}
    
    	/**
    	 * Returns the background element for the given slide.
    	 * All slides, even the ones with no background properties
    
    	 * defined, have a background element so as long as the
    	 * index is valid an element will be returned.
    
    	 */
    	function getSlideBackground( x, y ) {
    
    
    		// When printing to PDF the slide backgrounds are nested
    		// inside of the slides
    		if( isPrintingPDF() ) {
    			var slide = getSlide( x, y );
    
    			if( slide ) {
    				var background = slide.querySelector( '.slide-background' );
    				if( background && background.parentNode === slide ) {
    					return background;
    				}
    			}
    
    			return undefined;
    
    		var horizontalBackground = dom.wrapper.querySelectorAll( '.backgrounds>.slide-background' )[ x ];
    
    		var verticalBackgrounds = horizontalBackground && horizontalBackground.querySelectorAll( '.slide-background' );
    
    
    		if( verticalBackgrounds && verticalBackgrounds.length && typeof y === 'number' ) {
    
    			return verticalBackgrounds ? verticalBackgrounds[ y ] : undefined;
    		}
    
    		return horizontalBackground;
    
    	}
    
    
    	/**
    	 * 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;