Skip to content
Snippets Groups Projects
reveal.js 104 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	 * Returns the remaining height within the parent of the
    
    	 * target element.
    
    	 * remaining height = [ configured parent height ] - [ current parent height ]
    
    	function getRemainingHeight( element, height ) {
    
    			var newHeight, oldHeight = element.style.height;
    
    			// Change the .stretch element height to 0 in order find the height of all
    			// the other elements
    			element.style.height = '0px';
    			newHeight = height - element.parentNode.offsetHeight;
    
    			// Restore the old height, just in case
    			element.style.height = oldHeight + 'px';
    
    			return newHeight;
    
    	/**
    	 * Checks if this instance is being used to print a PDF.
    	 */
    	function isPrintingPDF() {
    
    		return ( /print-pdf/gi ).test( window.location.search );
    
    	}
    
    
    	/**
    	 * Hides the address bar if we're on a mobile device.
    	 */
    	function hideAddressBar() {
    
    
    		if( config.hideAddressBar && isMobileDevice ) {
    
    			// Events that should trigger the address bar to hide
    			window.addEventListener( 'load', removeAddressBar, false );
    			window.addEventListener( 'orientationchange', removeAddressBar, false );
    		}
    
    	}
    
    
    	 * Causes the address bar to hide on mobile devices,
    
    	 * more vertical space ftw.
    	 */
    	function removeAddressBar() {
    
    		setTimeout( function() {
    			window.scrollTo( 0, 1 );
    
    	 * Dispatches an event of the specified type from the
    
    	function dispatchEvent( type, args ) {
    
    		var event = document.createEvent( 'HTMLEvents', 1, 2 );
    
    		event.initEvent( type, true, true );
    
    		dom.wrapper.dispatchEvent( event );
    
    		// If we're in an iframe, post each reveal.js event to the
    		// parent window. Used by the notes plugin
    
    		if( config.postMessageEvents && window.parent !== window.self ) {
    			window.parent.postMessage( JSON.stringify({ namespace: 'reveal', eventName: type, state: getState() }), '*' );
    
    	/**
    	 * Wrap all links in 3D goodness.
    	 */
    	function enableRollingLinks() {
    
    
    		if( features.transforms3d && !( 'msPerspective' in document.body.style ) ) {
    
    			var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a' );
    
    
    			for( var i = 0, len = anchors.length; i < len; i++ ) {
    				var anchor = anchors[i];
    
    				if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
    					var span = document.createElement('span');
    					span.setAttribute('data-title', anchor.text);
    					span.innerHTML = anchor.innerHTML;
    
    					anchor.classList.add( 'roll' );
    					anchor.innerHTML = '';
    					anchor.appendChild(span);
    				}
    			}
    		}
    
    	}
    
    	/**
    	 * Unwrap all 3D links.
    	 */
    	function disableRollingLinks() {
    
    		var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
    
    		for( var i = 0, len = anchors.length; i < len; i++ ) {
    			var anchor = anchors[i];
    			var span = anchor.querySelector( 'span' );
    
    			if( span ) {
    				anchor.classList.remove( 'roll' );
    				anchor.innerHTML = span.innerHTML;
    			}
    		}
    
    	}
    
    
    	/**
    	 * Bind preview frame links.
    	 */
    	function enablePreviewLinks( selector ) {
    
    		var anchors = toArray( document.querySelectorAll( selector ? selector : 'a' ) );
    
    		anchors.forEach( function( element ) {
    			if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
    				element.addEventListener( 'click', onPreviewLinkClicked, false );
    			}
    		} );
    
    	}
    
    	/**
    	 * Unbind preview frame links.
    	 */
    	function disablePreviewLinks() {
    
    		var anchors = toArray( document.querySelectorAll( 'a' ) );
    
    		anchors.forEach( function( element ) {
    			if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
    				element.removeEventListener( 'click', onPreviewLinkClicked, false );
    			}
    		} );
    
    	}
    
    	/**
    	 * Opens a preview window for the target URL.
    	 */
    	function openPreview( url ) {
    
    		closePreview();
    
    		dom.preview = document.createElement( 'div' );
    		dom.preview.classList.add( 'preview-link-overlay' );
    		dom.wrapper.appendChild( dom.preview );
    
    		dom.preview.innerHTML = [
    			'<header>',
    				'<a class="close" href="#"><span class="icon"></span></a>',
    				'<a class="external" href="'+ url +'" target="_blank"><span class="icon"></span></a>',
    			'</header>',
    			'<div class="spinner"></div>',
    			'<div class="viewport">',
    				'<iframe src="'+ url +'"></iframe>',
    			'</div>'
    		].join('');
    
    		dom.preview.querySelector( 'iframe' ).addEventListener( 'load', function( event ) {
    			dom.preview.classList.add( 'loaded' );
    		}, false );
    
    		dom.preview.querySelector( '.close' ).addEventListener( 'click', function( event ) {
    			closePreview();
    			event.preventDefault();
    		}, false );
    
    		dom.preview.querySelector( '.external' ).addEventListener( 'click', function( event ) {
    			closePreview();
    		}, false );
    
    		setTimeout( function() {
    			dom.preview.classList.add( 'visible' );
    		}, 1 );
    
    	}
    
    	/**
    	 * Closes the iframe preview window.
    	 */
    	function closePreview() {
    
    		if( dom.preview ) {
    			dom.preview.setAttribute( 'src', '' );
    			dom.preview.parentNode.removeChild( dom.preview );
    			dom.preview = null;
    		}
    
    	}
    
    
    	/**
    	 * Applies JavaScript-controlled layout rules to the
    	 * presentation.
    	 */
    	function layout() {
    
    		if( dom.wrapper && !isPrintingPDF() ) {
    
    			var size = getComputedSlideSize();
    
    			var slidePadding = 20; // TODO Dig this out of DOM
    
    			// Layout the contents of the slides
    			layoutSlideContents( config.width, config.height, slidePadding );
    
    
    			dom.slides.style.width = size.width + 'px';
    			dom.slides.style.height = size.height + 'px';
    
    			// Determine scale of content to fit within available space
    
    			scale = Math.min( size.presentationWidth / size.width, size.presentationHeight / size.height );
    
    			// Respect max/min scale settings
    			scale = Math.max( scale, config.minScale );
    			scale = Math.min( scale, config.maxScale );
    
    			// Prefer zooming in WebKit so that content remains crisp
    			if( /webkit/i.test( navigator.userAgent ) && typeof dom.slides.style.zoom !== 'undefined' ) {
    
    				dom.slides.style.zoom = scale;
    			}
    			// Apply scale transform as a fallback
    			else {
    
    				dom.slides.style.left = '50%';
    				dom.slides.style.top = '50%';
    				dom.slides.style.bottom = 'auto';
    				dom.slides.style.right = 'auto';
    				transformElement( dom.slides, 'translate(-50%, -50%) scale('+ scale +')' );
    
    			// Select all slides, vertical and horizontal
    			var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
    
    			for( var i = 0, len = slides.length; i < len; i++ ) {
    				var slide = slides[ i ];
    
    				// Don't bother updating invisible slides
    				if( slide.style.display === 'none' ) {
    					continue;
    				}
    
    				if( config.center || slide.classList.contains( 'center' ) ) {
    
    					// Vertical stacks are not centred since their section
    
    					// children will be
    					if( slide.classList.contains( 'stack' ) ) {
    						slide.style.top = 0;
    					}
    					else {
    
    						slide.style.top = Math.max( ( ( size.height - getAbsoluteHeight( slide ) ) / 2 ) - slidePadding, 0 ) + 'px';
    
    			updateProgress();
    
    	/**
    	 * Applies layout logic to the contents of all slides in
    	 * the presentation.
    	 */
    	function layoutSlideContents( width, height, padding ) {
    
    
    		// Handle sizing of elements with the 'stretch' class
    		toArray( dom.slides.querySelectorAll( 'section > .stretch' ) ).forEach( function( element ) {
    
    
    			// Determine how much vertical space we can use
    
    			var remainingHeight = getRemainingHeight( element, height );
    
    
    			// Consider the aspect ratio of media elements
    			if( /(img|video)/gi.test( element.nodeName ) ) {
    
    				var nw = element.naturalWidth || element.videoWidth,
    					nh = element.naturalHeight || element.videoHeight;
    
    
    				var es = Math.min( width / nw, remainingHeight / nh );
    
    				element.style.width = ( nw * es ) + 'px';
    				element.style.height = ( nh * es ) + 'px';
    
    			}
    			else {
    				element.style.width = width + 'px';
    				element.style.height = remainingHeight + 'px';
    			}
    
    		} );
    
    	}
    
    
    	/**
    	 * Calculates the computed pixel size of our slides. These
    	 * values are based on the width and height configuration
    	 * options.
    	 */
    	function getComputedSlideSize( presentationWidth, presentationHeight ) {
    
    		var size = {
    			// Slide size
    			width: config.width,
    			height: config.height,
    
    			// Presentation size
    			presentationWidth: presentationWidth || dom.wrapper.offsetWidth,
    			presentationHeight: presentationHeight || dom.wrapper.offsetHeight
    		};
    
    		// Reduce available space by margin
    		size.presentationWidth -= ( size.presentationHeight * config.margin );
    		size.presentationHeight -= ( size.presentationHeight * config.margin );
    
    		// Slide width may be a percentage of available width
    		if( typeof size.width === 'string' && /%$/.test( size.width ) ) {
    			size.width = parseInt( size.width, 10 ) / 100 * size.presentationWidth;
    		}
    
    		// Slide height may be a percentage of available height
    		if( typeof size.height === 'string' && /%$/.test( size.height ) ) {
    			size.height = parseInt( size.height, 10 ) / 100 * size.presentationHeight;
    		}
    
    		return size;
    
    	}
    
    
    	 * Stores the vertical index of a stack so that the same
    	 * vertical slide can be selected when navigating to and
    
    	 * @param {HTMLElement} stack The vertical stack element
    	 * @param {int} v Index to memorize
    	 */
    	function setPreviousVerticalIndex( stack, v ) {
    
    		if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
    
    			stack.setAttribute( 'data-previous-indexv', v || 0 );
    		}
    
    	 * Retrieves the vertical index which was stored using
    
    	 * #setPreviousVerticalIndex() or 0 if no previous index
    	 * exists.
    	 *
    	 * @param {HTMLElement} stack The vertical stack element
    	 */
    	function getPreviousVerticalIndex( stack ) {
    
    		if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
    
    			// Prefer manually defined start-indexv
    			var attributeName = stack.hasAttribute( 'data-start-indexv' ) ? 'data-start-indexv' : 'data-previous-indexv';
    
    			return parseInt( stack.getAttribute( attributeName ) || 0, 10 );
    
    	 * Displays the overview of slides (quick nav) by
    
    	 * scaling down and arranging all slide elements.
    
    	 *
    	 * Experimental feature, might be dropped if perf
    
    	 * can't be improved.
    	 */
    	function activateOverview() {
    
    		// Only proceed if enabled in config
    
    		if( config.overview ) {
    
    			// Don't auto-slide while in overview mode
    			cancelAutoSlide();
    
    
    			var wasActive = dom.wrapper.classList.contains( 'overview' );
    
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    			// Vary the depth of the overview based on screen size
    			var depth = window.innerWidth < 400 ? 1000 : 2500;
    
    			dom.wrapper.classList.add( 'overview' );
    
    			dom.wrapper.classList.remove( 'overview-deactivating' );
    
    hakimel's avatar
    hakimel committed
    
    
    			var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
    
    			for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
    				var hslide = horizontalSlides[i],
    					hoffset = config.rtl ? -105 : 105;
    
    				hslide.setAttribute( 'data-index-h', i );
    
    				// Apply CSS transform
    				transformElement( hslide, 'translateZ(-'+ depth +'px) translate(' + ( ( i - indexh ) * hoffset ) + '%, 0%)' );
    
    				if( hslide.classList.contains( 'stack' ) ) {
    
    					var verticalSlides = hslide.querySelectorAll( 'section' );
    
    					for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
    						var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
    
    						var vslide = verticalSlides[j];
    
    						vslide.setAttribute( 'data-index-h', i );
    						vslide.setAttribute( 'data-index-v', j );
    
    						// Apply CSS transform
    						transformElement( vslide, 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)' );
    
    						vslide.addEventListener( 'click', onOverviewSlideClicked, true );
    
    					// Navigate to this slide on click
    					hslide.addEventListener( 'click', onOverviewSlideClicked, true );
    
    			updateSlidesVisibility();
    
    			layout();
    
    			if( !wasActive ) {
    				// Notify observers of the overview showing
    				dispatchEvent( 'overviewshown', {
    					'indexh': indexh,
    					'indexv': indexv,
    					'currentSlide': currentSlide
    				} );
    			}
    
    	/**
    	 * Exits the slide overview and enters the currently
    	 * active slide.
    	 */
    
    	function deactivateOverview() {
    
    		// Only proceed if enabled in config
    
    		if( config.overview ) {
    
    			dom.wrapper.classList.remove( 'overview' );
    
    hakimel's avatar
    hakimel committed
    
    
    Joel Brandt's avatar
    Joel Brandt committed
    			// Temporarily add a class so that transitions can do different things
    			// depending on whether they are exiting/entering overview, or just
    			// moving from slide to slide
    
    			dom.wrapper.classList.add( 'overview-deactivating' );
    
    hakimel's avatar
    hakimel committed
    
    
    			setTimeout( function () {
    
    				dom.wrapper.classList.remove( 'overview-deactivating' );
    			}, 1 );
    
    			toArray( document.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
    
    				// Resets all transforms to use the external styles
    
    				transformElement( slide, '' );
    
    				slide.removeEventListener( 'click', onOverviewSlideClicked, true );
    			} );
    
    			// Notify observers of the overview hiding
    			dispatchEvent( 'overviewhidden', {
    				'indexh': indexh,
    				'indexv': indexv,
    				'currentSlide': currentSlide
    			} );
    
    
    	 * @param {Boolean} override Optional flag which overrides the
    	 * toggle logic and forcibly sets the desired state. True means
    
    	 * overview is open, false means it's closed.
    	 */
    	function toggleOverview( override ) {
    
    		if( typeof override === 'boolean' ) {
    			override ? activateOverview() : deactivateOverview();
    		}
    		else {
    
    			isOverview() ? deactivateOverview() : activateOverview();
    
    	/**
    	 * Checks if the overview is currently active.
    
    	 * @return {Boolean} true if the overview is active,
    	 * false otherwise
    	 */
    
    		return dom.wrapper.classList.contains( 'overview' );
    
    	/**
    	 * Checks if the current or specified slide is vertical
    	 * (nested within another slide).
    	 *
    	 * @param {HTMLElement} slide [optional] The slide to check
    	 * orientation of
    	 */
    	function isVerticalSlide( slide ) {
    
    		// Prefer slide argument, otherwise use current slide
    		slide = slide ? slide : currentSlide;
    
    
    		return slide && slide.parentNode && !!slide.parentNode.nodeName.match( /section/i );
    
    	/**
    	 * Handling the fullscreen functionality via the fullscreen API
    
    	 *
    	 * @see http://fullscreen.spec.whatwg.org/
    	 * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
    
    	 */
    	function enterFullscreen() {
    
    		var element = document.body;
    
    		// Check which implementation is available
    		var requestMethod = element.requestFullScreen ||
    
    							element.webkitRequestFullScreen ||
    							element.mozRequestFullScreen ||
    
    							element.msRequestFullscreen;
    
    		if( requestMethod ) {
    			requestMethod.apply( element );
    		}
    
    	 * Enters the paused mode which fades everything on screen to
    
    		var wasPaused = dom.wrapper.classList.contains( 'paused' );
    
    
    		if( wasPaused === false ) {
    			dispatchEvent( 'paused' );
    		}
    
    
    		var wasPaused = dom.wrapper.classList.contains( 'paused' );
    
    		dom.wrapper.classList.remove( 'paused' );
    
    		if( wasPaused ) {
    			dispatchEvent( 'resumed' );
    		}
    
    
    		if( typeof override === 'boolean' ) {
    			override ? pause() : resume();
    
    	}
    
    	/**
    	 * Checks if we are currently in the paused mode.
    	 */
    	function isPaused() {
    
    		return dom.wrapper.classList.contains( 'paused' );
    
    	/**
    	 * Toggles the auto slide mode on and off.
    	 *
    	 * @param {Boolean} override Optional flag which sets the desired state. 
    	 * True means autoplay starts, false means it stops.
    	 */
    
    	function toggleAutoSlide( override ) {
    
    		if( typeof override === 'boolean' ) {
    			override ? resumeAutoSlide() : pauseAutoSlide();
    		}
    
    		else {
    			autoSlidePaused ? resumeAutoSlide() : pauseAutoSlide();
    		}
    
    	}
    
    	/**
    	 * Checks if the auto slide mode is currently on.
    	 */
    
    	function isAutoSliding() {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	/**
    
    	 * Steps from the current point in the presentation to the
    	 * slide which matches the specified horizontal and vertical
    	 * indices.
    
    	 *
    	 * @param {int} h Horizontal index of the target slide
    	 * @param {int} v Vertical index of the target slide
    
    	 * @param {int} f Optional index of a fragment within the
    
    	 * target slide to activate
    
    David Banham's avatar
    David Banham committed
    	 * @param {int} o Optional origin for use in multimaster environments
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	 */
    
    David Banham's avatar
    David Banham committed
    	function slide( h, v, f, o ) {
    
    		// Remember where we were at before
    		previousSlide = currentSlide;
    
    
    		// Query all horizontal slides in the deck
    		var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
    
    		// If no vertical index is specified and the upcoming slide is a
    
    		// stack, resume at its previous vertical index
    
    		if( v === undefined ) {
    			v = getPreviousVerticalIndex( horizontalSlides[ h ] );
    
    		// If we were on a vertical stack, remember what vertical index
    
    		// it was on so we can resume at the same position when returning
    
    		if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
    
    			setPreviousVerticalIndex( previousSlide.parentNode, indexv );
    
    		// Remember the state before this slide
    		var stateBefore = state.concat();
    
    		// Reset the state array
    		state.length = 0;
    
    		var indexhBefore = indexh || 0,
    			indexvBefore = indexv || 0;
    
    		// Activate and transition to the new slide
    
    		indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
    		indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
    
    		// Update the visibility of slides now that the indices have changed
    		updateSlidesVisibility();
    
    
    		stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
    
    			// Check if this state existed on the previous slide. If it
    
    			// did, we will avoid adding it repeatedly
    
    			for( var j = 0; j < stateBefore.length; j++ ) {
    				if( stateBefore[j] === state[i] ) {
    					stateBefore.splice( j, 1 );
    					continue stateLoop;
    				}
    			}
    
    
    			// Dispatch custom event matching the state's name
    			dispatchEvent( state[i] );
    
    		// Clean up the remains of the previous state
    
    		while( stateBefore.length ) {
    			document.documentElement.classList.remove( stateBefore.pop() );
    
    		// If the overview is active, re-activate it to update positions
    
    		// Find the current horizontal slide and any possible vertical slides
    		// within it
    		var currentHorizontalSlide = horizontalSlides[ indexh ],
    			currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
    
    		// Store references to the previous and current slides
    		currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
    
    		// Show fragment, if specified
    
    		if( typeof f !== 'undefined' ) {
    
    			navigateFragment( f );
    
    		// Dispatch an event if the slide changed
    
    		var slideChanged = ( indexh !== indexhBefore || indexv !== indexvBefore );
    
    				'indexh': indexh,
    
    David Banham's avatar
    David Banham committed
    				'currentSlide': currentSlide,
    				'origin': o
    
    		else {
    			// Ensure that the previous slide is never the same as the current
    			previousSlide = null;
    		}
    
    		// Solves an edge case where the previous slide maintains the
    		// 'present' class when navigating between adjacent vertical
    
    		// stacks
    		if( previousSlide ) {
    			previousSlide.classList.remove( 'present' );
    
    karimsa's avatar
    karimsa committed
    
    
    			// Reset all slides upon navigate to home
    			// Issue: #285
    			if ( document.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
    				// Launch async task
    				setTimeout( function () {
    					var slides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
    					for( i in slides ) {
    						if( slides[i] ) {
    							// Reset stack
    							setPreviousVerticalIndex( slides[i], 0 );
    						}
    					}
    				}, 0 );
    			}
    
    		if( slideChanged ) {
    
    			stopEmbeddedContent( previousSlide );
    			startEmbeddedContent( currentSlide );
    		}
    
    		updateControls();
    		updateProgress();
    
    		updateParallax();
    
    		// Update the URL hash
    		writeURL();
    
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	/**
    	 * Syncs the presentation with the current DOM. Useful
    	 * when new slides or control elements are added or when
    	 * the configuration has changed.
    	 */
    	function sync() {
    
    		// Subscribe to input
    		removeEventListeners();
    		addEventListeners();
    
    		// Force a layout to make sure the current config is accounted for
    		layout();
    
    		// Reflect the current autoSlide value
    		autoSlide = config.autoSlide;
    
    		// Start auto-sliding if it's enabled
    		cueAutoSlide();
    
    
    		// Re-create the slide backgrounds
    		createBackgrounds();
    
    
    		updateControls();
    		updateProgress();
    
    		updateBackground( true );
    
    	 * Resets all vertical slides so that only the first
    	 * is visible.
    
    	function resetVerticalSlides() {
    
    
    		var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
    		horizontalSlides.forEach( function( horizontalSlide ) {
    
    			var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
    			verticalSlides.forEach( function( verticalSlide, y ) {
    
    
    				if( y > 0 ) {
    					verticalSlide.classList.remove( 'present' );
    					verticalSlide.classList.remove( 'past' );
    					verticalSlide.classList.add( 'future' );
    				}
    
    			} );
    
    		} );
    
    	}
    
    	/**
    	 * Sorts and formats all of fragments in the
    	 * presentation.
    	 */
    	function sortAllFragments() {
    
    		var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
    		horizontalSlides.forEach( function( horizontalSlide ) {
    
    			var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
    			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( document.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', '' );
    
    
    				// 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' );
    
    
    			// 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.
    	 */