Prechádzať zdrojové kódy

add get/setState methods for persisting and restoring presentation state

Hakim El Hattab 11 rokov pred
rodič
commit
714102c3f8
2 zmenil súbory, kde vykonal 43 pridanie a 5 odobranie
  1. 42 4
      js/reveal.js
  2. 1 1
      js/reveal.min.js

+ 42 - 4
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,
 

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 1 - 1
js/reveal.min.js


Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov