fragments are now zero-indexed

This commit is contained in:
Hakim El Hattab 2013-11-21 09:01:18 -05:00
parent 9d0ac52780
commit 60a74ebfa3
3 changed files with 24 additions and 24 deletions

View File

@ -1047,7 +1047,7 @@ var Reveal = (function(){
a.forEach( function( el, idx ) {
if( !el.hasAttribute( 'data-fragment-index' ) ) {
el.setAttribute( 'data-fragment-index', idx + 1 );
el.setAttribute( 'data-fragment-index', idx );
}
} );
@ -2261,7 +2261,7 @@ var Reveal = (function(){
var hasFragments = currentSlide.querySelectorAll( '.fragment' ).length > 0;
if( hasFragments ) {
var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
f = visibleFragments.length;
f = visibleFragments.length - 1;
}
}
@ -2273,7 +2273,7 @@ var Reveal = (function(){
* Navigate to the specified slide fragment.
*
* @param {Number} index The index of the fragment that
* should be shown, 1-based, 0 means all are invisible
* should be shown, -1 means all are invisible
* @param {Number} offset Integer offset to apply to the
* fragment index
*
@ -2292,10 +2292,10 @@ var Reveal = (function(){
var lastVisibleFragment = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) ).pop();
if( lastVisibleFragment ) {
index = parseInt( lastVisibleFragment.getAttribute( 'data-fragment-index' ) || 1, 10 );
index = parseInt( lastVisibleFragment.getAttribute( 'data-fragment-index' ) || 0, 10 );
}
else {
index = 0;
index = -1;
}
}
@ -2309,8 +2309,14 @@ var Reveal = (function(){
toArray( fragments ).forEach( function( element, i ) {
// Hidden fragments
if( i > index ) {
if( element.classList.contains( 'visible' ) ) fragmentsHidden.push( element );
element.classList.remove( 'visible' );
element.classList.remove( 'current-fragment' );
}
// Visible fragments
if( i < index ) {
else {
if( !element.classList.contains( 'visible' ) ) fragmentsShown.push( element );
element.classList.add( 'visible' );
element.classList.remove( 'current-fragment' );
@ -2319,12 +2325,6 @@ var Reveal = (function(){
element.classList.add( 'current-fragment' );
}
}
// Hidden fragments
else {
if( element.classList.contains( 'visible' ) ) fragmentsHidden.push( element );
element.classList.remove( 'visible' );
element.classList.remove( 'current-fragment' );
}
} );

4
js/reveal.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -139,6 +139,9 @@ Reveal.addEventListener( 'ready', function() {
deepEqual( Reveal.getIndices(), { h: 1, v: 2, f: undefined } );
// There's fragments on this slide
Reveal.next();
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: -1 } );
Reveal.next();
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 } );
@ -148,9 +151,6 @@ Reveal.addEventListener( 'ready', function() {
Reveal.next();
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 } );
Reveal.next();
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 3 } );
Reveal.next();
deepEqual( Reveal.getIndices(), { h: 3, v: 0, f: undefined } );
@ -177,31 +177,31 @@ Reveal.addEventListener( 'ready', function() {
});
test( 'Stepping through fragments', function() {
Reveal.slide( 2, 0, 0 );
Reveal.slide( 2, 0, -1 );
// forwards:
Reveal.next();
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'next() goes to next fragment' );
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'next() goes to next fragment' );
Reveal.right();
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'right() goes to next fragment' );
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'right() goes to next fragment' );
Reveal.down();
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 3 }, 'down() goes to next fragment' );
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'down() goes to next fragment' );
Reveal.down(); // moves to f #3
// backwards:
Reveal.prev();
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 2 }, 'prev() goes to prev fragment' );
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'prev() goes to prev fragment' );
Reveal.left();
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 1 }, 'left() goes to prev fragment' );
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'left() goes to prev fragment' );
Reveal.up();
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: 0 }, 'left() goes to prev fragment' );
deepEqual( Reveal.getIndices(), { h: 2, v: 0, f: -1 }, 'up() goes to prev fragment' );
});
test( 'Stepping past fragments', function() {