Skip to content
Snippets Groups Projects
reveal.js 114 KiB
Newer Older
  • Learn to ignore specific revisions
  • 		for( var i in b ) {
    			a[ i ] = b[ i ];
    		}
    
    	/**
    	 * Converts the target object to an array.
    	 */
    	function toArray( o ) {
    
    	/**
    	 * Utility for deserializing a value.
    	 */
    	function deserialize( value ) {
    
    		if( typeof value === 'string' ) {
    			if( value === 'null' ) return null;
    			else if( value === 'true' ) return true;
    			else if( value === 'false' ) return false;
    			else if( value.match( /^\d+$/ ) ) return parseFloat( value );
    		}
    
    		return value;
    
    	}
    
    
    	/**
    	 * Measures the distance in pixels between point a
    
    	 * @param {Object} a point with x/y properties
    	 * @param {Object} b point with x/y properties
    	 */
    
    	function distanceBetween( a, b ) {
    
    		var dx = a.x - b.x,
    			dy = a.y - b.y;
    
    		return Math.sqrt( dx*dx + dy*dy );
    
    	/**
    	 * Applies a CSS transform to the target element.
    	 */
    	function transformElement( element, transform ) {
    
    		element.style.WebkitTransform = transform;
    		element.style.MozTransform = transform;
    		element.style.msTransform = transform;
    		element.style.OTransform = transform;
    		element.style.transform = transform;
    
    	}
    
    
    	/**
    	 * Injects the given CSS styles into the DOM.
    	 */
    	function injectStyleSheet( value ) {
    
    		var tag = document.createElement( 'style' );
    		tag.type = 'text/css';
    		if( tag.styleSheet ) {
    			tag.styleSheet.cssText = value;
    		}
    		else {
    			tag.appendChild( document.createTextNode( value ) );
    		}
    		document.getElementsByTagName( 'head' )[0].appendChild( tag );
    
    	}
    
    
    	/**
    	 * Measures the distance in pixels between point a and point b.
    	 *
    	 * @param {String} color The string representation of a color,
    	 * the following formats are supported:
    	 * - #000
    	 * - #000000
    	 * - rgb(0,0,0)
    	 */
    	function colorToRgb( color ) {
    
    		var hex3 = color.match( /^#([0-9a-f]{3})$/i );
    		if( hex3 && hex3[1] ) {
    			hex3 = hex3[1];
    			return {
    				r: parseInt( hex3.charAt( 0 ), 16 ) * 0x11,
    				g: parseInt( hex3.charAt( 1 ), 16 ) * 0x11,
    				b: parseInt( hex3.charAt( 2 ), 16 ) * 0x11
    			};
    		}
    
    		var hex6 = color.match( /^#([0-9a-f]{6})$/i );
    		if( hex6 && hex6[1] ) {
    			hex6 = hex6[1];
    			return {
    				r: parseInt( hex6.substr( 0, 2 ), 16 ),
    				g: parseInt( hex6.substr( 2, 2 ), 16 ),
    				b: parseInt( hex6.substr( 4, 2 ), 16 )
    			};
    		}
    
    		var rgb = color.match( /^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i );
    		if( rgb ) {
    			return {
    
    				r: parseInt( rgb[1], 10 ),
    				g: parseInt( rgb[2], 10 ),
    				b: parseInt( rgb[3], 10 )
    			};
    		}
    
    		var rgba = color.match( /^rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\,\s*([\d]+|[\d]*.[\d]+)\s*\)$/i );
    		if( rgba ) {
    			return {
    				r: parseInt( rgba[1], 10 ),
    				g: parseInt( rgba[2], 10 ),
    				b: parseInt( rgba[3], 10 ),
    				a: parseFloat( rgba[4] )
    
    			};
    		}
    
    		return null;
    
    	}
    
    	/**
    	 * Calculates brightness on a scale of 0-255.
    	 *
    	 * @param color See colorStringToRgb for supported formats.
    	 */
    	function colorBrightness( color ) {
    
    		if( typeof color === 'string' ) color = colorToRgb( color );
    
    
    		if( color ) {
    			return ( color.r * 299 + color.g * 587 + color.b * 114 ) / 1000;
    		}
    
    		return null;
    
    	/**
    	 * Retrieves the height of the given element by looking
    	 * at the position and height of its immediate children.
    	 */
    	function getAbsoluteHeight( element ) {
    
    		var height = 0;
    
    		if( element ) {
    			var absoluteChildren = 0;
    
    			toArray( element.childNodes ).forEach( function( child ) {
    
    				if( typeof child.offsetTop === 'number' && child.style ) {
    					// Count # of abs children
    
    					if( window.getComputedStyle( child ).position === 'absolute' ) {
    
    						absoluteChildren += 1;
    					}
    
    					height = Math.max( height, child.offsetTop + child.offsetHeight );
    				}
    
    			} );
    
    			// If there are no absolute children, use offsetHeight
    			if( absoluteChildren === 0 ) {
    				height = element.offsetHeight;
    			}
    
    		}
    
    		return height;
    
    	}
    
    
    	 * 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 = dom.wrapper.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 = dom.wrapper.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 showPreview( url ) {
    
    		dom.overlay = document.createElement( 'div' );
    		dom.overlay.classList.add( 'overlay' );
    		dom.overlay.classList.add( 'overlay-preview' );
    		dom.wrapper.appendChild( dom.overlay );
    
    		dom.overlay.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.overlay.querySelector( 'iframe' ).addEventListener( 'load', function( event ) {
    			dom.overlay.classList.add( 'loaded' );
    
    		dom.overlay.querySelector( '.close' ).addEventListener( 'click', function( event ) {
    			closeOverlay();
    
    		dom.overlay.querySelector( '.external' ).addEventListener( 'click', function( event ) {
    			closeOverlay();
    
    			dom.overlay.classList.add( 'visible' );
    
    	 * Opens a overlay window with help material.
    
    	function showHelp() {
    
    		if( config.help ) {
    
    			dom.overlay = document.createElement( 'div' );
    			dom.overlay.classList.add( 'overlay' );
    			dom.overlay.classList.add( 'overlay-help' );
    			dom.wrapper.appendChild( dom.overlay );
    
    			var html = '<p class="title">Keyboard Shortcuts</p><br/>';
    
    			html += '<table><th>KEY</th><th>ACTION</th>';
    			for( var key in keyboardShortcuts ) {
    				html += '<tr><td>' + key + '</td><td>' + keyboardShortcuts[ key ] + '</td></tr>';
    			}
    
    			html += '</table>';
    
    			dom.overlay.innerHTML = [
    				'<header>',
    					'<a class="close" href="#"><span class="icon"></span></a>',
    				'</header>',
    				'<div class="viewport">',
    					'<div class="viewport-inner">'+ html +'</div>',
    				'</div>'
    			].join('');
    
    			dom.overlay.querySelector( '.close' ).addEventListener( 'click', function( event ) {
    				closeOverlay();
    				event.preventDefault();
    			}, false );
    
    			setTimeout( function() {
    				dom.overlay.classList.add( 'visible' );
    			}, 1 );
    
    		}
    
    	/**
    	 * Closes any currently open overlay.
    	 */
    	function closeOverlay() {
    
    		if( dom.overlay ) {
    			dom.overlay.parentNode.removeChild( dom.overlay );
    			dom.overlay = 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 );
    
    			// Don't apply any scaling styles if scale is 1
    			if( scale === 1 ) {
    				dom.slides.style.zoom = '';
    				dom.slides.style.left = '';
    				dom.slides.style.top = '';
    				dom.slides.style.bottom = '';
    				dom.slides.style.right = '';
    				transformElement( dom.slides, '' );
    			}
    			else {
    
    				// Prefer zooming in desktop Chrome so that content remains crisp
    				if( !isMobileDevice && /chrome/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( dom.wrapper.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 = dom.wrapper.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( dom.wrapper.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
    
    		if( config.pause ) {
    			var wasPaused = dom.wrapper.classList.contains( 'paused' );
    
    			cancelAutoSlide();
    			dom.wrapper.classList.add( '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 = dom.wrapper.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