aboutsummaryrefslogtreecommitdiff
path: root/js/reveal.js
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2013-02-27 13:25:28 -0500
committerHakim El Hattab <hakim.elhattab@gmail.com>2013-02-27 13:25:28 -0500
commit25f26bdc155a280a6cd15c5a3b96a518db402970 (patch)
tree00e5dd1fa97eca5a21cf0e9d15955eb2770cc35e /js/reveal.js
parent3f740c8553e4a961f552a8ec01e0a8b1d2599b6f (diff)
parente4016792dd3da16e858a47f855388e0fc91b5341 (diff)
downloadperl-software-in-gnu-guix-25f26bdc155a280a6cd15c5a3b96a518db402970.tar
perl-software-in-gnu-guix-25f26bdc155a280a6cd15c5a3b96a518db402970.tar.gz
Merge branch 'sort_fragments' of https://github.com/jaberg/reveal.js into dev
Diffstat (limited to 'js/reveal.js')
-rw-r--r--js/reveal.js32
1 files changed, 31 insertions, 1 deletions
diff --git a/js/reveal.js b/js/reveal.js
index f47006f..456f418 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -142,6 +142,31 @@ var Reveal = (function(){
threshold: 80
};
+ /**
+ * Return a sorted fragments list, ordered by an increasing "fragment-pos" attribute.
+ *
+ * Fragments will be revealed in the order that they are returned by
+ * this function, so you can use "fragment-pos" attributes to control
+ * the order of fragment appearance.
+ *
+ * To maintain a sensible default fragment order, fragments are presumed
+ * to be passed in document order. This function adds a "fragment-pos"
+ * attribute to each node if such an attribute is not already present,
+ * and sets that attribute to an integer value which is the position of
+ * the fragment within the fragments list.
+ *
+ */
+ function sort_fragments( fragments ) {
+ var a = toArray(fragments)
+ a.forEach( function (el, idx) {
+ if (!el.hasAttribute('fragment-pos')) {
+ el.setAttribute('fragment-pos', idx) }})
+ a.sort(function(l, r) {
+ return l.getAttribute( 'fragment-pos' )
+ - r.getAttribute( 'fragment-pos') })
+ return a
+ }
+
/**
* Starts up the presentation if the client is capable.
*/
@@ -1022,6 +1047,7 @@ var Reveal = (function(){
// Show fragment, if specified
if( typeof f !== 'undefined' ) {
var fragments = currentSlide.querySelectorAll( '.fragment' );
+ fragments = sort_fragments(fragments)
toArray( fragments ).forEach( function( fragment, indexf ) {
if( indexf < f ) {
@@ -1393,6 +1419,7 @@ var Reveal = (function(){
// Vertical slides:
if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' );
+ verticalFragments = sort_fragments(verticalFragments)
if( verticalFragments.length ) {
verticalFragments[0].classList.add( 'visible' );
@@ -1404,6 +1431,7 @@ var Reveal = (function(){
// Horizontal slides:
else {
var horizontalFragments = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' );
+ horizontalFragments = sort_fragments(horizontalFragments)
if( horizontalFragments.length ) {
horizontalFragments[0].classList.add( 'visible' );
@@ -1428,6 +1456,7 @@ var Reveal = (function(){
// Vertical slides:
if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment.visible' );
+ verticalFragments = sort_fragments(verticalFragments)
if( verticalFragments.length ) {
verticalFragments[ verticalFragments.length - 1 ].classList.remove( 'visible' );
@@ -1439,6 +1468,7 @@ var Reveal = (function(){
// Horizontal slides:
else {
var horizontalFragments = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment.visible' );
+ horizontalFragments = sort_fragments(horizontalFragments)
if( horizontalFragments.length ) {
horizontalFragments[ horizontalFragments.length - 1 ].classList.remove( 'visible' );
@@ -1949,4 +1979,4 @@ var Reveal = (function(){
}
};
-})(); \ No newline at end of file
+})();