Skip to content
Snippets Groups Projects
reveal.js 32 KiB
Newer Older
  • Learn to ignore specific revisions
  • Hakim El Hattab's avatar
    Hakim El Hattab committed
    	 * @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( overviewIsActive() || previousFragment() === false ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    	function navigateRight() {
    
    		// Prioritize revealing fragments
    
    		if( overviewIsActive() || nextFragment() === false ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    	function navigateUp() {
    
    		// Prioritize hiding fragments
    
    		if( overviewIsActive() || previousFragment() === false ) {
    
    Hakim El Hattab's avatar
    Hakim El Hattab committed
    	}
    	function navigateDown() {
    
    		// Prioritize revealing fragments
    
    		if( overviewIsActive() || 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();
    
    
    	/**
    	 * Toggles the slide overview mode on and off.
    	 */
    	function toggleOverview() {
    
    		if( overviewIsActive() ) {
    			deactivateOverview();
    		}
    		else {
    			activateOverview();
    		}
    	}
    
    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 );
    			}