Skip to content
Snippets Groups Projects
reveal.js 35 KiB
Newer Older
  • Learn to ignore specific revisions
  • 		if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
    
    			// Find the slide with the specified name
    			var slide = document.querySelector( '#' + name );
    
    			if( slide ) {
    				// Find the position of the named slide and navigate to it
    				var indices = Reveal.getIndices( slide );
    				navigateTo( indices.h, indices.v );
    			}
    			// If the slide doesn't exist, navigate to the current slide
    			else {
    				navigateTo( indexh, indexv );
    			}
    		}
    		else {
    			// Read the index components of the hash
    
    			var h = parseInt( bits[0], 10 ) || 0,
    				v = parseInt( bits[1], 10 ) || 0;
    
    			navigateTo( h, v );
    		}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    	
    	/**
    	 * Updates the page URL (hash) to reflect the current
    
    	 * state. 
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	 */
    	function writeURL() {
    
    		if( config.history ) {
    			var url = '/';
    			
    			// Only include the minimum possible number of components in
    			// the URL
    			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
    	}
    
    	 * Navigate to the next slide fragment.
    
    	 * 
    	 * @return {Boolean} true if there was a next fragment,
    	 * false otherwise
    	 */
    
    	function nextFragment() {
    		// Vertical slides:
    
    		if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
    			var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' );
    			if( verticalFragments.length ) {
    
    				verticalFragments[0].classList.add( 'visible' );
    
    
    				// Notify subscribers of the change
    				dispatchEvent( 'fragmentshown', { fragment: verticalFragments[0] } );
    
    		// Horizontal slides:
    
    		else {
    			var horizontalFragments = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' );
    			if( horizontalFragments.length ) {
    
    				horizontalFragments[0].classList.add( 'visible' );
    
    
    				// Notify subscribers of the change
    				dispatchEvent( 'fragmentshown', { fragment: horizontalFragments[0] } );
    
    		}
    
    		return false;
    	}
    
    	/**
    	 * Navigate to the previous slide fragment.
    	 * 
    	 * @return {Boolean} true if there was a previous fragment,
    	 * false otherwise
    	 */
    	function previousFragment() {
    
    		// Vertical slides:
    
    		if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
    			var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment.visible' );
    			if( verticalFragments.length ) {
    
    				verticalFragments[ verticalFragments.length - 1 ].classList.remove( 'visible' );
    
    				dispatchEvent( 'fragmenthidden', { fragment: verticalFragments[ verticalFragments.length - 1 ] } );
    
    		// Horizontal slides:
    
    		else {
    			var horizontalFragments = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment.visible' );
    			if( horizontalFragments.length ) {
    
    				horizontalFragments[ horizontalFragments.length - 1 ].classList.remove( 'visible' );
    
    				dispatchEvent( 'fragmenthidden', { fragment: horizontalFragments[ horizontalFragments.length - 1 ] } );
    
    	/**
    	 * Cues a new automated slide if enabled in the config.
    	 */
    
    	function cueAutoSlide() {
    		clearTimeout( autoSlideTimeout );
    
    		// Cue the next auto-slide if enabled
    		if( config.autoSlide ) {
    			autoSlideTimeout = setTimeout( navigateNext, config.autoSlide );
    		}
    	}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	/**
    	 * Triggers a navigation to the specified indices.
    	 * 
    	 * @param {Number} h The horizontal index of the slide to show
    	 * @param {Number} v The vertical index of the slide to show
    	 */
    	function navigateTo( h, v ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    	
    	function navigateLeft() {
    
    		// Prioritize hiding fragments
    
    		if( isOverviewActive() || previousFragment() === false ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	function navigateRight() {
    
    		// Prioritize revealing fragments
    
    		if( isOverviewActive() || nextFragment() === false ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	function navigateUp() {
    
    		// Prioritize hiding fragments
    
    		if( isOverviewActive() || previousFragment() === false ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	function navigateDown() {
    
    		// Prioritize revealing fragments
    
    		if( isOverviewActive() || nextFragment() === false ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    
    
    	/**
    	 * Navigates backwards, prioritized in the following order:
    	 * 1) Previous fragment
    	 * 2) Previous vertical slide
    	 * 3) Previous horizontal slide
    	 */
    	function navigatePrev() {
    		// Prioritize revealing fragments
    		if( previousFragment() === false ) {
    			if( availableRoutes().up ) {
    				navigateUp();
    			}
    			else {
    				// Fetch the previous horizontal slide, if there is one
    
    				var previousSlide = document.querySelector( '.reveal .slides>section.past:nth-child(' + indexh + ')' );
    
    
    				if( previousSlide ) {
    					indexv = ( previousSlide.querySelectorAll('section').length + 1 ) || 0;
    					indexh --;
    					slide();
    				}
    			}
    		}
    	}
    
    	/**
    	 * Same as #navigatePrev() but navigates forwards.
    	 */
    	function navigateNext() {
    		// Prioritize revealing fragments
    		if( nextFragment() === false ) {
    			availableRoutes().down ? navigateDown() : navigateRight();
    		}
    
    
    		// If auto-sliding is enabled we need to cue up 
    		// another timeout
    		cueAutoSlide();
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	
    	// Expose some methods publicly
    	return {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    		navigateTo: navigateTo,
    		navigateLeft: navigateLeft,
    		navigateRight: navigateRight,
    		navigateUp: navigateUp,
    
    		navigatePrev: navigatePrev,
    		navigateNext: navigateNext,
    
    		toggleOverview: toggleOverview,
    
    		// Adds or removes all internal event listeners (such as keyboard)
    
    		addEventListeners: addEventListeners,
    		removeEventListeners: removeEventListeners,
    
    
    		// Returns the indices of the current, or specified, slide
    		getIndices: function( slide ) {
    			// By default, return the current indices
    			var h = indexh,
    				v = indexv;
    
    			// If a slide is specified, return the indices of that slide
    			if( slide ) {
    				var isVertical = !!slide.parentNode.nodeName.match( /section/gi );
    				var slideh = isVertical ? slide.parentNode : slide;
    
    				// Select all horizontal slides
    				var horizontalSlides = Array.prototype.slice.call( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
    
    				// Now that we know which the horizontal slide is, get its index
    				h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
    
    				// If this is a vertical slide, grab the vertical index
    				if( isVertical ) {
    					v = Math.max( Array.prototype.slice.call( slide.parentNode.children ).indexOf( slide ), 0 );
    				}
    			}
    
    			return { h: h, v: v };
    
    		},
    
    		// Returns the previous slide element, may be null
    		getPreviousSlide: function() {
    
    		},
    
    		// Returns the current slide element
    		getCurrentSlide: function() {
    
    		// Helper method, retrieves query string as a key/value hash
    		getQueryHash: function() {
    			var query = {};
    
    			location.search.replace( /[A-Z0-9]+?=(\w*)/gi, function(a) {
    				query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
    			} );
    
    			return query;
    		},
    
    
    		// Forward event binding to the reveal DOM element
    		addEventListener: function( type, listener, useCapture ) {
    
    hakimel's avatar
    hakimel committed
    			if( 'addEventListener' in window ) {
    				( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
    			}
    
    		},
    		removeEventListener: function( type, listener, useCapture ) {
    
    hakimel's avatar
    hakimel committed
    			if( 'addEventListener' in window ) {
    				( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
    			}