From c33aa66666bb2409fb89656f6cbf719f63db840f Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Thu, 21 Nov 2013 09:22:20 -0500 Subject: respect original dom order of fragments with no explicit index --- js/reveal.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'js/reveal.js') diff --git a/js/reveal.js b/js/reveal.js index b5ad65f..d4c3fd0 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -1045,10 +1045,20 @@ var Reveal = (function(){ var a = toArray( fragments ); + // Elements that do not have an explicit `data-fragment-index` + // are given one which matches their order in the DOM + a.forEach( function( el, idx ) { + if( !el.hasAttribute( 'data-fragment-index' ) ) { + el.setAttribute( 'data-fragment-index', idx ); + } + } ); + a.sort( function( l, r ) { return l.getAttribute( 'data-fragment-index' ) - r.getAttribute( 'data-fragment-index'); } ); + // Set the indices to match the order of the sorted fragments, + // ensures that we're 0-indexed and have no gaps a.forEach( function( el, idx ) { el.setAttribute( 'data-fragment-index', idx ); } ); -- cgit v1.2.3