From 714102c3f8bfacee2323e32963ee62c3d1511d19 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Sun, 2 Mar 2014 12:30:55 +0100 Subject: add get/setState methods for persisting and restoring presentation state --- js/reveal.js | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'js/reveal.js') diff --git a/js/reveal.js b/js/reveal.js index a06ce55..5cb72eb 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -1430,13 +1430,13 @@ var Reveal = (function(){ /** * Toggles the paused mode on and off. */ - function togglePause() { + function togglePause( override ) { - if( isPaused() ) { - resume(); + if( typeof override === 'boolean' ) { + override ? pause() : resume(); } else { - pause(); + isPaused() ? resume() : pause(); } } @@ -2325,6 +2325,40 @@ var Reveal = (function(){ } + /** + * Retrieves the current state of the presentation as + * an object. This state can then be restored at any + * time. + */ + function getState() { + + var indices = getIndices(); + + return { + indexh: indices.h, + indexv: indices.v, + indexf: indices.f, + paused: isPaused(), + overview: isOverview() + }; + + } + + /** + * Restores the presentation to the given state. + * + * @param {Object} state As generated by getState() + */ + function setState( state ) { + + if( typeof state === 'object' ) { + slide( state.indexh, state.indexv, state.indexf ); + togglePause( state.paused ); + toggleOverview( state.overview ); + } + + } + /** * Return a sorted fragments list, ordered by an increasing * "data-fragment-index" attribute. @@ -3345,6 +3379,10 @@ var Reveal = (function(){ addEventListeners: addEventListeners, removeEventListeners: removeEventListeners, + // Facility for persisting and restoring the presentation state + getState: getState, + setState: setState, + // Returns the indices of the current, or specified, slide getIndices: getIndices, -- cgit v1.2.3