浏览代码

add api method for retrieving progress

Hakim El Hattab 11 年之前
父节点
当前提交
6e9a33cf1f
共有 2 个文件被更改,包括 50 次插入37 次删除
  1. 49 36
      js/reveal.js
  2. 1 1
      js/reveal.min.js

+ 49 - 36
js/reveal.js

@@ -1882,42 +1882,7 @@ var Reveal = (function(){
 		// Update progress if enabled
 		if( config.progress && dom.progress ) {
 
-			var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
-
-			// The number of past and total slides
-			var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
-			var pastCount = 0;
-
-			// Step through all slides and count the past ones
-			mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
-
-				var horizontalSlide = horizontalSlides[i];
-				var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
-
-				for( var j = 0; j < verticalSlides.length; j++ ) {
-
-					// Stop as soon as we arrive at the present
-					if( verticalSlides[j].classList.contains( 'present' ) ) {
-						break mainLoop;
-					}
-
-					pastCount++;
-
-				}
-
-				// Stop as soon as we arrive at the present
-				if( horizontalSlide.classList.contains( 'present' ) ) {
-					break;
-				}
-
-				// Don't count the wrapping section for vertical slides
-				if( horizontalSlide.classList.contains( 'stack' ) === false ) {
-					pastCount++;
-				}
-
-			}
-
-			dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px';
+			dom.progressbar.style.width = getProgress() * window.innerWidth + 'px';
 
 		}
 
@@ -2209,6 +2174,51 @@ var Reveal = (function(){
 
 	}
 
+	/**
+	 * Returns a value ranging from 0-1 that represents
+	 * how far into the presentation we have navigated.
+	 */
+	function getProgress() {
+
+		var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
+
+		// The number of past and total slides
+		var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
+		var pastCount = 0;
+
+		// Step through all slides and count the past ones
+		mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
+
+			var horizontalSlide = horizontalSlides[i];
+			var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
+
+			for( var j = 0; j < verticalSlides.length; j++ ) {
+
+				// Stop as soon as we arrive at the present
+				if( verticalSlides[j].classList.contains( 'present' ) ) {
+					break mainLoop;
+				}
+
+				pastCount++;
+
+			}
+
+			// Stop as soon as we arrive at the present
+			if( horizontalSlide.classList.contains( 'present' ) ) {
+				break;
+			}
+
+			// Don't count the wrapping section for vertical slides
+			if( horizontalSlide.classList.contains( 'stack' ) === false ) {
+				pastCount++;
+			}
+
+		}
+
+		return pastCount / ( totalCount - 1 );
+
+	}
+
 	/**
 	 * Checks if this presentation is running inside of the
 	 * speaker notes window.
@@ -3399,6 +3409,9 @@ var Reveal = (function(){
 		getState: getState,
 		setState: setState,
 
+		// Presentation progress on range of 0-1
+		getProgress: getProgress,
+
 		// Returns the indices of the current, or specified, slide
 		getIndices: getIndices,
 

文件差异内容过多而无法显示
+ 1 - 1
js/reveal.min.js


部分文件因为文件数量过多而无法显示