Skip to content

Commit d41a5ca

Browse files
committed
update future classes when syncing
1 parent 0fcff33 commit d41a5ca

File tree

2 files changed

+91
-89
lines changed

2 files changed

+91
-89
lines changed

js/reveal.js

Lines changed: 88 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ var Reveal = (function(){
305305
setupDOM();
306306

307307
// Decorate the slide DOM elements with state classes (past/future)
308-
setupSlides();
308+
formatSlides();
309309

310310
// Updates the presentation to match the current configuration values
311311
configure();
@@ -333,30 +333,6 @@ var Reveal = (function(){
333333

334334
}
335335

336-
/**
337-
* Iterates through and decorates slides DOM elements with
338-
* appropriate classes.
339-
*/
340-
function setupSlides() {
341-
342-
var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
343-
horizontalSlides.forEach( function( horizontalSlide ) {
344-
345-
var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
346-
verticalSlides.forEach( function( verticalSlide, y ) {
347-
348-
if( y > 0 ) verticalSlide.classList.add( 'future' );
349-
350-
sortFragments( verticalSlide.querySelectorAll( '.fragment' ) );
351-
352-
} );
353-
354-
if( verticalSlides.length === 0 ) sortFragments( horizontalSlide.querySelectorAll( '.fragment' ) );
355-
356-
} );
357-
358-
}
359-
360336
/**
361337
* Finds and stores references to DOM elements which are
362338
* required by the presentation. If a required element is
@@ -1031,67 +1007,6 @@ var Reveal = (function(){
10311007

10321008
}
10331009

1034-
/**
1035-
* Return a sorted fragments list, ordered by an increasing
1036-
* "data-fragment-index" attribute.
1037-
*
1038-
* Fragments will be revealed in the order that they are returned by
1039-
* this function, so you can use the index attributes to control the
1040-
* order of fragment appearance.
1041-
*
1042-
* To maintain a sensible default fragment order, fragments are presumed
1043-
* to be passed in document order. This function adds a "fragment-index"
1044-
* attribute to each node if such an attribute is not already present,
1045-
* and sets that attribute to an integer value which is the position of
1046-
* the fragment within the fragments list.
1047-
*/
1048-
function sortFragments( fragments ) {
1049-
1050-
fragments = toArray( fragments );
1051-
1052-
var ordered = [],
1053-
unordered = [],
1054-
sorted = [];
1055-
1056-
// Group ordered and unordered elements
1057-
fragments.forEach( function( fragment, i ) {
1058-
if( fragment.hasAttribute( 'data-fragment-index' ) ) {
1059-
var index = parseInt( fragment.getAttribute( 'data-fragment-index' ), 10 );
1060-
1061-
if( !ordered[index] ) {
1062-
ordered[index] = [];
1063-
}
1064-
1065-
ordered[index].push( fragment );
1066-
}
1067-
else {
1068-
unordered.push( [ fragment ] );
1069-
}
1070-
} );
1071-
1072-
// Append fragments without explicit indices in their
1073-
// DOM order
1074-
ordered = ordered.concat( unordered );
1075-
1076-
// Manually count the index up per group to ensure there
1077-
// are no gaps
1078-
var index = 0;
1079-
1080-
// Push all fragments in their sorted order to an array,
1081-
// this flattens the groups
1082-
ordered.forEach( function( group ) {
1083-
group.forEach( function( fragment ) {
1084-
sorted.push( fragment );
1085-
fragment.setAttribute( 'data-fragment-index', index );
1086-
} );
1087-
1088-
index ++;
1089-
} );
1090-
1091-
return sorted;
1092-
1093-
}
1094-
10951010
/**
10961011
* Applies JavaScript-controlled layout rules to the
10971012
* presentation.
@@ -1676,13 +1591,39 @@ var Reveal = (function(){
16761591
// Re-create the slide backgrounds
16771592
createBackgrounds();
16781593

1594+
formatSlides();
1595+
16791596
updateControls();
16801597
updateProgress();
16811598
updateBackground( true );
16821599
updateSlideNumber();
16831600

16841601
}
16851602

1603+
/**
1604+
* Iterates through and decorates slides DOM elements with
1605+
* appropriate classes.
1606+
*/
1607+
function formatSlides() {
1608+
1609+
var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
1610+
horizontalSlides.forEach( function( horizontalSlide ) {
1611+
1612+
var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
1613+
verticalSlides.forEach( function( verticalSlide, y ) {
1614+
1615+
if( y > 0 ) verticalSlide.classList.add( 'future' );
1616+
1617+
sortFragments( verticalSlide.querySelectorAll( '.fragment' ) );
1618+
1619+
} );
1620+
1621+
if( verticalSlides.length === 0 ) sortFragments( horizontalSlide.querySelectorAll( '.fragment' ) );
1622+
1623+
} );
1624+
1625+
}
1626+
16861627
/**
16871628
* Updates one dimension of slides by showing the slide
16881629
* with the specified index.
@@ -2306,6 +2247,67 @@ var Reveal = (function(){
23062247

23072248
}
23082249

2250+
/**
2251+
* Return a sorted fragments list, ordered by an increasing
2252+
* "data-fragment-index" attribute.
2253+
*
2254+
* Fragments will be revealed in the order that they are returned by
2255+
* this function, so you can use the index attributes to control the
2256+
* order of fragment appearance.
2257+
*
2258+
* To maintain a sensible default fragment order, fragments are presumed
2259+
* to be passed in document order. This function adds a "fragment-index"
2260+
* attribute to each node if such an attribute is not already present,
2261+
* and sets that attribute to an integer value which is the position of
2262+
* the fragment within the fragments list.
2263+
*/
2264+
function sortFragments( fragments ) {
2265+
2266+
fragments = toArray( fragments );
2267+
2268+
var ordered = [],
2269+
unordered = [],
2270+
sorted = [];
2271+
2272+
// Group ordered and unordered elements
2273+
fragments.forEach( function( fragment, i ) {
2274+
if( fragment.hasAttribute( 'data-fragment-index' ) ) {
2275+
var index = parseInt( fragment.getAttribute( 'data-fragment-index' ), 10 );
2276+
2277+
if( !ordered[index] ) {
2278+
ordered[index] = [];
2279+
}
2280+
2281+
ordered[index].push( fragment );
2282+
}
2283+
else {
2284+
unordered.push( [ fragment ] );
2285+
}
2286+
} );
2287+
2288+
// Append fragments without explicit indices in their
2289+
// DOM order
2290+
ordered = ordered.concat( unordered );
2291+
2292+
// Manually count the index up per group to ensure there
2293+
// are no gaps
2294+
var index = 0;
2295+
2296+
// Push all fragments in their sorted order to an array,
2297+
// this flattens the groups
2298+
ordered.forEach( function( group ) {
2299+
group.forEach( function( fragment ) {
2300+
sorted.push( fragment );
2301+
fragment.setAttribute( 'data-fragment-index', index );
2302+
} );
2303+
2304+
index ++;
2305+
} );
2306+
2307+
return sorted;
2308+
2309+
}
2310+
23092311
/**
23102312
* Navigate to the specified slide fragment.
23112313
*

0 commit comments

Comments
 (0)