Support for multiple elements with same data-fragment-index
authorNigel Stanger <nigel.stanger@otago.ac.nz>
Thu, 2 May 2013 00:26:23 +0000 (12:26 +1200)
committerNigel Stanger <nigel.stanger@otago.ac.nz>
Thu, 2 May 2013 00:26:23 +0000 (12:26 +1200)
When multiple elements are specified with the same data-fragment-index,
they are all shown or hidden at once.

js/reveal.js

index a4a71db49240dc5be52e95a39c91c4f64d318bda..d27b625c630b4a728daa1aae3e26d23178ac9074 100644 (file)
@@ -1629,11 +1629,19 @@ var Reveal = (function(){
                        var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment:not(.visible)' ) );
 
                        if( fragments.length ) {
-                               fragments[0].classList.add( 'visible' );
-
-                               // Notify subscribers of the change
-                               dispatchEvent( 'fragmentshown', { fragment: fragments[0] } );
-
+                               // There may be multiple fragments with the same index. We want to display all of them.
+                               var nextFragmentIndex = fragments[0].getAttribute( 'data-fragment-index' );
+                               
+                               toArray( fragments ).forEach( function( thisFragment ) {
+                                       var f = thisFragment.getAttribute( 'data-fragment-index' );
+                                       if( f === nextFragmentIndex ) {
+                                               thisFragment.classList.add( 'visible' );
+                                               
+                                               // Notify subscribers of the change
+                                               dispatchEvent( 'fragmentshown', { fragment: thisFragment } );
+                                       }
+                               } );
+                               
                                updateControls();
                                return true;
                        }
@@ -1655,10 +1663,18 @@ var Reveal = (function(){
                        var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) );
 
                        if( fragments.length ) {
-                               fragments[ fragments.length - 1 ].classList.remove( 'visible' );
-
-                               // Notify subscribers of the change
-                               dispatchEvent( 'fragmenthidden', { fragment: fragments[ fragments.length - 1 ] } );
+                               // There may be multiple fragments with the same index. We want to display all of them.
+                               var prevFragmentIndex = fragments[0].getAttribute( 'data-fragment-index' );
+                               
+                               toArray( fragments ).forEach( function( thisFragment ) {
+                                       var f = thisFragment.getAttribute( 'data-fragment-index' );
+                                       if( f === prevFragmentIndex ) {
+                                               thisFragment.classList.remove( 'visible' );
+                                               
+                                               // Notify subscribers of the change
+                                               dispatchEvent( 'fragmenthidden', { fragment: thisFragment } );
+                                       }
+                               } );
 
                                updateControls();
                                return true;
@@ -2226,4 +2242,4 @@ var Reveal = (function(){
                }
        };
 
-})();
\ No newline at end of file
+})();