瀏覽代碼

jump-to-slide; add support for 'h.v' format, adapat to match slide number format #3501

Hakim El Hattab 1 年之前
父節點
當前提交
3d7d3152a4
共有 7 個文件被更改,包括 50 次插入10 次删除
  1. 0 0
      dist/reveal.esm.js
  2. 0 0
      dist/reveal.esm.js.map
  3. 0 0
      dist/reveal.js
  4. 0 0
      dist/reveal.js.map
  5. 31 4
      js/controllers/jumptoslide.js
  6. 12 5
      js/controllers/slidenumber.js
  7. 7 1
      js/utils/constants.js

文件差異過大導致無法顯示
+ 0 - 0
dist/reveal.esm.js


文件差異過大導致無法顯示
+ 0 - 0
dist/reveal.esm.js.map


文件差異過大導致無法顯示
+ 0 - 0
dist/reveal.js


文件差異過大導致無法顯示
+ 0 - 0
dist/reveal.js.map


+ 31 - 4
js/controllers/jumptoslide.js

@@ -1,3 +1,8 @@
+import {
+	SLIDE_NUMBER_FORMAT_CURRENT,
+	SLIDE_NUMBER_FORMAT_CURRENT_SLASH_TOTAL
+} from "../utils/constants";
+
 /**
  * Makes it possible to jump to a slide by entering its
  * slide number or id.
@@ -66,11 +71,33 @@ export default class JumpToSlide {
 		clearTimeout( this.jumpTimeout );
 		delete this.jumpTimeout;
 
-		const query = this.jumpInput.value.trim( '' );
-		let indices = this.Reveal.location.getIndicesFromHash( query, { oneBasedIndex: true } );
+		let query = this.jumpInput.value.trim( '' );
+		let indices;
+
+		// When slide numbers are formatted to be a single linear mumber
+		// (instead of showing a separate horizontal/vertical index) we
+		// use the same format for slide jumps
+		if( /^\d+$/.test( query ) ) {
+			const slideNumberFormat = this.Reveal.getConfig().slideNumber;
+			if( slideNumberFormat === SLIDE_NUMBER_FORMAT_CURRENT || slideNumberFormat === SLIDE_NUMBER_FORMAT_CURRENT_SLASH_TOTAL ) {
+				const slide = this.Reveal.getSlides()[ parseInt( query, 10 ) - 1 ];
+				if( slide ) {
+					indices = this.Reveal.getIndices( slide );
+				}
+			}
+		}
+
+		if( !indices ) {
+			// If the query uses "horizontal.vertical" format, convert to
+			// "horizontal/vertical" so that our URL parser can understand
+			if( /^\d+\.\d+$/.test( query ) ) {
+				query = query.replace( '.', '/' );
+			}
+
+			indices = this.Reveal.location.getIndicesFromHash( query, { oneBasedIndex: true } );
+		}
 
-		// If no valid index was found and the input query is a
-		// string, fall back on a simple search
+		// Still no valid index? Fall back on a text search
 		if( !indices && /\S+/i.test( query ) && query.length > 1 ) {
 			indices = this.search( query );
 		}

+ 12 - 5
js/controllers/slidenumber.js

@@ -1,3 +1,10 @@
+import {
+	SLIDE_NUMBER_FORMAT_CURRENT,
+	SLIDE_NUMBER_FORMAT_CURRENT_SLASH_TOTAL,
+	SLIDE_NUMBER_FORMAT_HORIZONTAL_DOT_VERTICAL,
+	SLIDE_NUMBER_FORMAT_HORIZONTAL_SLASH_VERTICAL
+} from "../utils/constants";
+
 /**
  * Handles the display of reveal.js' optional slide number.
  */
@@ -56,7 +63,7 @@ export default class SlideNumber {
 
 		let config = this.Reveal.getConfig();
 		let value;
-		let format = 'h.v';
+		let format = SLIDE_NUMBER_FORMAT_HORIZONTAL_DOT_VERTICAL;
 
 		if ( typeof config.slideNumber === 'function' ) {
 			value = config.slideNumber( slide );
@@ -69,7 +76,7 @@ export default class SlideNumber {
 			// If there are ONLY vertical slides in this deck, always use
 			// a flattened slide number
 			if( !/c/.test( format ) && this.Reveal.getHorizontalSlides().length === 1 ) {
-				format = 'c';
+				format = SLIDE_NUMBER_FORMAT_CURRENT;
 			}
 
 			// Offset the current slide number by 1 to make it 1-indexed
@@ -77,16 +84,16 @@ export default class SlideNumber {
 
 			value = [];
 			switch( format ) {
-				case 'c':
+				case SLIDE_NUMBER_FORMAT_CURRENT:
 					value.push( this.Reveal.getSlidePastCount( slide ) + horizontalOffset );
 					break;
-				case 'c/t':
+				case SLIDE_NUMBER_FORMAT_CURRENT_SLASH_TOTAL:
 					value.push( this.Reveal.getSlidePastCount( slide ) + horizontalOffset, '/', this.Reveal.getTotalSlides() );
 					break;
 				default:
 					let indices = this.Reveal.getIndices( slide );
 					value.push( indices.h + horizontalOffset );
-					let sep = format === 'h/v' ? '/' : '.';
+					let sep = format === SLIDE_NUMBER_FORMAT_HORIZONTAL_SLASH_VERTICAL ? '/' : '.';
 					if( this.Reveal.isVerticalSlide( slide ) ) value.push( sep, indices.v + 1 );
 			}
 		}

+ 7 - 1
js/utils/constants.js

@@ -7,4 +7,10 @@ export const VERTICAL_SLIDES_SELECTOR = '.slides>section.present>section';
 export const POST_MESSAGE_METHOD_BLACKLIST = /registerPlugin|registerKeyboardShortcut|addKeyBinding|addEventListener|showPreview/;
 
 // Regex for retrieving the fragment style from a class attribute
-export const FRAGMENT_STYLE_REGEX = /fade-(down|up|right|left|out|in-then-out|in-then-semi-out)|semi-fade-out|current-visible|shrink|grow/;
+export const FRAGMENT_STYLE_REGEX = /fade-(down|up|right|left|out|in-then-out|in-then-semi-out)|semi-fade-out|current-visible|shrink|grow/;
+
+// Slide number formats
+export const SLIDE_NUMBER_FORMAT_HORIZONTAL_DOT_VERTICAL = 'h.v';
+export const SLIDE_NUMBER_FORMAT_HORIZONTAL_SLASH_VERTICAL = 'h/v';
+export const SLIDE_NUMBER_FORMAT_CURRENT = 'c';
+export const SLIDE_NUMBER_FORMAT_CURRENT_SLASH_TOTAL = 'c/t';

部分文件因文件數量過多而無法顯示