Skip to content
Snippets Groups Projects
reveal.js 29 KiB
Newer Older
 * http://lab.hakim.se/reveal-js
 * MIT licensed
Hakim El Hattab's avatar
Hakim El Hattab committed
 * Copyright (C) 2011-2012 Hakim El Hattab, http://hakim.se
Hakim El Hattab's avatar
Hakim El Hattab committed
 */
Hakim El Hattab's avatar
Hakim El Hattab committed
	
	var HORIZONTAL_SLIDES_SELECTOR = '.reveal .slides>section',
		VERTICAL_SLIDES_SELECTOR = '.reveal .slides>section.present>section',
Hakim El Hattab's avatar
Hakim El Hattab committed

		IS_TOUCH_DEVICE = !!( 'ontouchstart' in window ),

		// Configurations defaults, can be overridden at initialization time 
			// Display controls in the bottom right corner
			controls: true,

			// Display a presentation progress bar
			progress: true,

			// Push each slide change to the browser history
			// Enable keyboard shortcuts for navigation
			keyboard: true,


			// Number of milliseconds between automatically proceeding to the 
			// next slide, disabled when set to 0
			autoSlide: 0,

			// Enable slide navigation via mouse wheel
			mouseWheel: true,
			rollingLinks: true,

			// Transition style
			transition: 'default' // default/cube/page/concave/linear(2d)
		// The horizontal and verical index of the currently active slide
		indexh = 0,
		indexv = 0,

		// The previous and current slide HTML elements
		previousSlide,
		currentSlide,

		// Slides may hold a data-state attribute which we pick up and apply 
		// as a class to the body. This list contains the combined state of 
		// all current slides.
		state = [],

		// Cached references to DOM elements
		dom = {},

		// Detect support for CSS 3D transforms
		supports3DTransforms =  'WebkitPerspective' in document.body.style ||
                        		'MozPerspective' in document.body.style ||
                        		'msPerspective' in document.body.style ||
                        		'OPerspective' in document.body.style ||
                        		'perspective' in document.body.style,
        supports2DTransforms =  'WebkitTransform' in document.body.style ||
                        		'MozTransform' in document.body.style ||
                        		'msTransform' in document.body.style ||
                        		'OTransform' in document.body.style ||
                        		'transform' in document.body.style,

        // Detect support for elem.classList
        supportsClassList = !!document.body.classList;
		
		// Throttles mouse wheel navigation
		// An interval used to automatically move on to the next slide
		autoSlideTimeout = 0,

		// Delays updates to the URL due to a Chrome thumbnailer bug
		writeURLTimeout = 0,

		// Holds information about the currently ongoing touch input
		touch = {
			startX: 0,
			startY: 0,
			startSpan: 0,
			startCount: 0,
			handled: false,
			threshold: 40
		};
Hakim El Hattab's avatar
Hakim El Hattab committed
	
	/**
	 * Starts up the slideshow by applying configuration
	 * options and binding various events.
Hakim El Hattab's avatar
Hakim El Hattab committed
	 */
	function initialize( options ) {
		if( ( !supports2DTransforms && !supports3DTransforms ) || !supportsClassList ) {
			document.body.setAttribute( 'class', 'no-transforms' );

			// If the browser doesn't support core features we won't be 
			// using JavaScript to control the presentation
		// Cache references to DOM elements
		dom.wrapper = document.querySelector( '.reveal' );
		dom.progress = document.querySelector( '.reveal .progress' );
		dom.progressbar = document.querySelector( '.reveal .progress span' );
danielmitd's avatar
danielmitd committed
		if ( config.controls ) {
danielmitd's avatar
danielmitd committed
			dom.controls = document.querySelector( '.reveal .controls' );
			dom.controlsLeft = document.querySelector( '.reveal .controls .left' );
			dom.controlsRight = document.querySelector( '.reveal .controls .right' );
			dom.controlsUp = document.querySelector( '.reveal .controls .up' );
			dom.controlsDown = document.querySelector( '.reveal .controls .down' );
		}
		// Copy options over to our config object
		extend( config, options );
		
		// Subscribe to input
		addEventListeners();
		// Updates the presentation to match the current configuration values
		configure();

		// Read the initial hash
		readURL();

		// Set up hiding of the browser address bar
		if( navigator.userAgent.match( /(iphone|ipod|android)/i ) ) {
			// Give the page some scrollable overflow
			document.documentElement.style.overflow = 'scroll';
			document.body.style.height = '120%';

			// Events that should trigger the address bar to hide
			window.addEventListener( 'load', removeAddressBar, false );
			window.addEventListener( 'orientationchange', removeAddressBar, false );
		}
		
	}

	function configure() {
		if( supports3DTransforms === false ) {
			config.transition = 'linear';
danielmitd's avatar
danielmitd committed
		if( config.controls && dom.controls ) {
			dom.controls.style.display = 'block';
		}

		if( config.progress && dom.progress ) {
			dom.progress.style.display = 'block';
		}

		if( config.transition !== 'default' ) {
			dom.wrapper.classList.add( config.transition );
		if( config.mouseWheel ) {
			document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
			document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
		if( config.rollingLinks ) {
			// Add some 3D magic to our anchors
			linkify();
		}

	function addEventListeners() {
		document.addEventListener( 'touchstart', onDocumentTouchStart, false );
		document.addEventListener( 'touchmove', onDocumentTouchMove, false );
		document.addEventListener( 'touchend', onDocumentTouchEnd, false );
		window.addEventListener( 'hashchange', onWindowHashChange, false );
		if( config.keyboard ) {
			document.addEventListener( 'keydown', onDocumentKeyDown, false );
		}

danielmitd's avatar
danielmitd committed
		if ( config.controls && dom.controls ) {
danielmitd's avatar
danielmitd committed
			dom.controlsLeft.addEventListener( 'click', preventAndForward( navigateLeft ), false );
			dom.controlsRight.addEventListener( 'click', preventAndForward( navigateRight ), false );
			dom.controlsUp.addEventListener( 'click', preventAndForward( navigateUp ), false );
			dom.controlsDown.addEventListener( 'click', preventAndForward( navigateDown ), false );	
		}

	function removeEventListeners() {
		document.removeEventListener( 'keydown', onDocumentKeyDown, false );
Loading
Loading full blame...