Reputation: 799
I'm looking for the counterpart/opposite of Reveal.initialize()
. A way to programmatically end a reveal.js presentation.
Upvotes: 2
Views: 761
Reputation: 2300
Reveal.js did not implement a method which programmatically ends the presentation. Here is the list of methods available.
If you are looking for destroy the instance of Reveal.js, that is not possible unless Reveal.js team implements it. What you can do is, you can remove the DOM elements on which Reveal event is initialized.
Here is the code using which you can destroy all/any instance(s) of Reveal.js presentation.
Element.prototype.remove = function() {
this.parentElement.removeChild(this);
}
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
for(var i = this.length - 1; i >= 0; i--) {
if(this[i] && this[i].parentElement) {
this[i].parentElement.removeChild(this[i]);
}
}
}
document.querySelectorAll('.reveal').remove();
//To remove all containers created by Math Plugin
var mathPluginContainers = document.querySelectorAll("[id^='MathJax']");
mathPluginContainers = Array.prototype.slice.call(mathPluginContainers);
var mathPluginParents = mathPluginContainers.map(function(container) {
return container.parentElement;
});
mathPluginParents.forEach(function (container, index) {
if (container.tagName === 'DIV') {
container.remove();
} else {
container.removeChild(mathPluginContainers[index]);
}
});
Upvotes: 4
Reputation: 986
Before starting the presentation you can create the DOM tree copy (1) and then, when needed, you can restore it (2).
// (1) create DOM copy
window.saved = document.body.cloneNode(true);
Reveal.initialize({
// initialisation parameters
});
// (2) restore DOM to previous state
document.body.parentNode.replaceChild(window.saved, document.body)
It is stopping the presentation and not making any errors. The only problem might be is that something extra has to be done to be able to start the presentation again.
Upvotes: 0