add get/setState methods for persisting and restoring presentation state
This commit is contained in:
		
							
								
								
									
										46
									
								
								js/reveal.js
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								js/reveal.js
									
									
									
									
									
								
							| @@ -1430,13 +1430,13 @@ var Reveal = (function(){ | |||||||
| 	/** | 	/** | ||||||
| 	 * Toggles the paused mode on and off. | 	 * Toggles the paused mode on and off. | ||||||
| 	 */ | 	 */ | ||||||
| 	function togglePause() { | 	function togglePause( override ) { | ||||||
|  |  | ||||||
| 		if( isPaused() ) { | 		if( typeof override === 'boolean' ) { | ||||||
| 			resume(); | 			override ? pause() : resume(); | ||||||
| 		} | 		} | ||||||
| 		else { | 		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 | 	 * Return a sorted fragments list, ordered by an increasing | ||||||
| 	 * "data-fragment-index" attribute. | 	 * "data-fragment-index" attribute. | ||||||
| @@ -3345,6 +3379,10 @@ var Reveal = (function(){ | |||||||
| 		addEventListeners: addEventListeners, | 		addEventListeners: addEventListeners, | ||||||
| 		removeEventListeners: removeEventListeners, | 		removeEventListeners: removeEventListeners, | ||||||
|  |  | ||||||
|  | 		// Facility for persisting and restoring the presentation state | ||||||
|  | 		getState: getState, | ||||||
|  | 		setState: setState, | ||||||
|  |  | ||||||
| 		// Returns the indices of the current, or specified, slide | 		// Returns the indices of the current, or specified, slide | ||||||
| 		getIndices: getIndices, | 		getIndices: getIndices, | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										6
									
								
								js/reveal.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								js/reveal.min.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
		Reference in New Issue
	
	Block a user