Skip to content

Commit

Permalink
shuffle now applies to vertical slides as well
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Aug 17, 2020
1 parent 2bfe705 commit 3a99a7b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
<body>
<div class="reveal">
<div class="slides">
<section>Slide 1</section>
<section><section>Slide 1</section>
<section>Slide 2</section>
<section>Slide 3</section></section>
</div>
</div>

Expand Down
20 changes: 15 additions & 5 deletions js/reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -1467,13 +1467,23 @@ export default function( revealElement, options ) {
/**
* Randomly shuffles all slides in the deck.
*/
function shuffle() {
function shuffle( slides = getHorizontalSlides() ) {

getHorizontalSlides().forEach( ( slide, i, slides ) => {
slides.forEach( ( slide, i ) => {

// Insert this slide next to another random slide. This may
// cause the slide to insert before itself but that's fine.
dom.slides.insertBefore( slide, slides[ Math.floor( Math.random() * slides.length ) ] );
// Insert the slide next to a randomly picked sibling slide
// slide. This may cause the slide to insert before itself,
// but that's not an issue.
let beforeSlide = slides[ Math.floor( Math.random() * slides.length ) ];
if( beforeSlide.parentNode === slide.parentNode ) {
slide.parentNode.insertBefore( slide, beforeSlide );
}

// Randomize the order of vertical slides (if there are any)
let verticalSlides = slide.querySelectorAll( 'section' );
if( verticalSlides.length ) {
shuffle( verticalSlides );
}

} );

Expand Down

0 comments on commit 3a99a7b

Please sign in to comment.