Reveal.js: Remove reveal and initialize again

Created on 26 Jul 2017  路  3Comments  路  Source: hakimel/reveal.js

Hi.

I'm using reveal in a web app dynamically. I create the sections and I do the initialization. It works well but with ESC I want to remove the slide show and later create other sections for a new slide show.

I tried to remove the DIV with $('.reveal).remove() and then I create the DIV again. But the second time the initialize doesn't work and the elements don't have the reveal classes neither the arrows etc... It's like the reveal object was associated to the first .reveal DIV and I couldn't creat the object with the new DIV.

How can I do this?

Thanks.

Oscar.

question

Most helpful comment

Allright, that was a quick find! Unfortunately, they now prohibit re-initialization (see: https://github.com/hakimel/reveal.js/blob/568c7516f7ff7da7824db033946619d2c7ad761f/js/reveal.js#L264) since 3.4.0.
The problem - with our app at least - seems to be that we exchange the whole .slides div when changing to another presentation, but the internal dom.slides is still the old one. Since re-initialization is not possible anymore (but why?) there is no way to set that to the new one. This results in the new slides not being used (they don't get the necessary classes).

All 3 comments

Try using Reveal 3.3.0, not 3.4 or 3.5. I'm developing an app with a similar use case and that works. Calling Reveal.initialize(...) again will not break your app and Reveal.sync() will update the slides.
I'm currently figuring out what's the problem there as I'd like to make use of the pdf-export improvements - will report back as soon as I'll find something.

Allright, that was a quick find! Unfortunately, they now prohibit re-initialization (see: https://github.com/hakimel/reveal.js/blob/568c7516f7ff7da7824db033946619d2c7ad761f/js/reveal.js#L264) since 3.4.0.
The problem - with our app at least - seems to be that we exchange the whole .slides div when changing to another presentation, but the internal dom.slides is still the old one. Since re-initialization is not possible anymore (but why?) there is no way to set that to the new one. This results in the new slides not being used (they don't get the necessary classes).

Initializing something twice is a bad practice, and may cause unexpected side effects, especially since Reveal does so much DOM manipulation. In your case, deleting the whole .reveal slide is a bad idea as Reveal does not re-attach to the new .reveal class. What you should do is delete the slides and re-add them later and call Reveal.sync().

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deisi picture deisi  路  4Comments

togakangaroo picture togakangaroo  路  4Comments

berteh picture berteh  路  5Comments

ablakey picture ablakey  路  3Comments

karlroberts picture karlroberts  路  4Comments