slide method now accepts fragment index argument #228

This commit is contained in:
Hakim El Hattab 2012-11-22 09:10:34 -05:00
commit 34b36753f5
4 changed files with 53 additions and 18 deletions

View File

@ -137,7 +137,7 @@ The Reveal class provides a minimal JavaScript API for controlling navigation an
```javascript ```javascript
// Navigation // Navigation
Reveal.slide( indexh, indexv ); Reveal.slide( indexh, indexv, indexf );
Reveal.left(); Reveal.left();
Reveal.right(); Reveal.right();
Reveal.up(); Reveal.up();

View File

@ -63,7 +63,8 @@ module.exports = function(grunt) {
}, },
globals: { globals: {
head: false, head: false,
module: false module: false,
console: false
} }
}, },

View File

@ -741,8 +741,10 @@ var Reveal = (function(){
* *
* @param {int} h Horizontal index of the target slide * @param {int} h Horizontal index of the target slide
* @param {int} v Vertical 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
*/ */
function slide( h, v ) { function slide( h, v, f ) {
// Remember where we were at before // Remember where we were at before
previousSlide = currentSlide; previousSlide = currentSlide;
@ -774,12 +776,18 @@ var Reveal = (function(){
indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h ); indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v ); indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
// No need to proceed if we're navigating to the same slide as
// we're already on, unless a fragment index is specified
if( indexh === indexhBefore && indexv === indexvBefore && !f ) {
return;
}
layout(); layout();
// Apply the new state // Apply the new state
stateLoop: for( var i = 0, len = state.length; i < len; i++ ) { stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
// Check if this state existed on the previous slide. If it // Check if this state existed on the previous slide. If it
// did, we will avoid adding it repeatedly. // did, we will avoid adding it repeatedly
for( var j = 0; j < stateBefore.length; j++ ) { for( var j = 0; j < stateBefore.length; j++ ) {
if( stateBefore[j] === state[i] ) { if( stateBefore[j] === state[i] ) {
stateBefore.splice( j, 1 ); stateBefore.splice( j, 1 );
@ -805,8 +813,7 @@ var Reveal = (function(){
// Update the URL hash after a delay since updating it mid-transition // Update the URL hash after a delay since updating it mid-transition
// is likely to cause visual lag // is likely to cause visual lag
clearTimeout( writeURLTimeout ); writeURL( 1500 );
writeURLTimeout = setTimeout( writeURL, 1500 );
// Find the current horizontal slide and any possible vertical slides // Find the current horizontal slide and any possible vertical slides
// within it // within it
@ -816,6 +823,20 @@ var Reveal = (function(){
// Store references to the previous and current slides // Store references to the previous and current slides
currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide; currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
// Show fragment, if specified
if ( typeof f !== undefined ) {
var fragments = currentSlide.querySelectorAll( '.fragment' );
toArray( fragments ).forEach( function( fragment, indexf ) {
if( indexf < f ) {
fragment.classList.add( 'visible' );
}
else {
fragment.classList.remove( 'visible' );
}
} );
}
// Dispatch an event if the slide changed // Dispatch an event if the slide changed
if( indexh !== indexhBefore || indexv !== indexvBefore ) { if( indexh !== indexhBefore || indexv !== indexvBefore ) {
dispatchEvent( 'slidechanged', { dispatchEvent( 'slidechanged', {
@ -1068,9 +1089,21 @@ var Reveal = (function(){
/** /**
* Updates the page URL (hash) to reflect the current * Updates the page URL (hash) to reflect the current
* state. * state.
*
* @param {Number} delay The time in ms to wait before
* writing the hash
*/ */
function writeURL() { function writeURL( delay ) {
if( config.history ) { if( config.history ) {
// Make sure there's never more than one timeout running
clearTimeout( writeURLTimeout );
// If a delay is specified, timeout this call
if( typeof delay === 'number' ) {
writeURLTimeout = setTimeout( writeURL, delay );
}
else {
var url = '/'; var url = '/';
// If the current slide has an ID, use that as a named link // If the current slide has an ID, use that as a named link
@ -1086,6 +1119,7 @@ var Reveal = (function(){
window.location.hash = url; window.location.hash = url;
} }
} }
}
/** /**
* Retrieves the h/v location of the current, or specified, * Retrieves the h/v location of the current, or specified,

4
js/reveal.min.js vendored

File diff suppressed because one or more lines are too long