I was also interested to know about the upcoming project; looked around and could not find anything, so I wrote something for my own project, added at the end. Adding a slide after the current slide is pretty simple. Just add a section element to .llides and make sure that there is a future class in the section. Also, if you are on the last slide, you need to add the "enabled" class to ".navigate-right". Adding something before the current slide interferes with the numbering, so you need to add it using the "past" class, and then move on to the next slide.
The same goes for deleting a slide if you delete the slide ".past" that messed up your numbering. I have not tested my code very well (yet), so if you use it as a test it is good.
Reveal.addEventListener( 'ready', function( event ) { Reveal.add = function( content = '',index = -1 ){ dom = {}, dom.slides = document.querySelector( '.reveal .slides' ); var newSlide = document.createElement( 'section' ); if( index === -1 ) { //adding slide to end newSlide.classList.add( 'future' ); dom.slides.appendChild(newSlide); document.querySelector( '.navigate-right' ).classList.add( 'enabled' ); //just enable it, even if it is } else if( index > Reveal.getIndices().h ) { newSlide.classList.add( 'future' ); dom.slides.insertBefore(newSlide,dom.slides.querySelectorAll('section:nth-child('+(index+1)+')')[0]); } else if( index <= Reveal.getIndices().h ) { newSlide.classList.add( 'past' ); dom.slides.insertBefore(newSlide,dom.slides.querySelectorAll('section:nth-child('+(index+1)+')')[0]); Reveal.next(); } newSlide.innerHTML = content; }; Reveal.remove = function( index = -1 ){ dom = {}, dom.wrapper = document.querySelector( '.reveal' ); dom.slides = document.querySelector( '.reveal .slides' ); var target = (dom.wrapper.querySelectorAll('.slides > section:nth-child('+(index+1)+')')[0]) ? dom.wrapper.querySelectorAll('.slides > section:nth-child('+(index+1)+')')[0] : false; if( index === -1 ) { if (Reveal.isLastSlide()) Reveal.prev(); dom.slides.removeChild(dom.wrapper.querySelectorAll('.slides > section')[dom.wrapper.querySelectorAll('.slides > section').length-1]); if (Reveal.isLastSlide()) document.querySelector( '.navigate-right' ).classList.remove( 'enabled' ); } else if( index > Reveal.getIndices().h && target ) { dom.slides.removeChild(target); if (Reveal.getIndices().h == dom.wrapper.querySelectorAll('.slides > section').length-1) document.querySelector( '.navigate-right' ).classList.remove( 'enabled' ); } else if( index < Reveal.getIndices().h && target ) { dom.slides.removeChild(target); location.hash = '/'+parseInt(Reveal.getIndices().h-1); } else if( index == Reveal.getIndices().h && target ) { if (index == 0) { Reveal.next(); document.querySelector( '.navigate-left' ).classList.remove( 'enabled' ); } else Reveal.prev(); dom.slides.removeChild(target); if( dom.wrapper.querySelectorAll('.slides > section').length == index) document.querySelector( '.navigate-right' ).classList.remove( 'enabled' ); } }; } );
If you want to use this, add it after Reveal.initialize ({...});
Name it using Reveal.add (content, index) or Reveal.remove (index).
Reveal.add('<h3>Slide title</h3>')
will add that as the last slide
Reveal.add('<h3>Slide title</h3>',0)
at the beginning.
Reveal.add('<h3>Slide title</h3>',3)
will add it to the third position.
Reveal.remove () deletes the last slide, Reveal.remove (n) any other (if it exists).
Mason
source share