add get/setState methods for persisting and restoring presentation state

edit
Hakim El Hattab 2014-03-02 12:30:55 +01:00
parent 4cd1dd1a1f
commit 714102c3f8
2 changed files with 45 additions and 7 deletions

View File

@ -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,

6
js/reveal.min.js vendored

File diff suppressed because one or more lines are too long