mirror of
https://github.com/hakimel/reveal.js.git
synced 2025-08-12 17:44:53 +02:00
jump-to-slide; add support for 'h.v' format, adapat to match slide number format #3501
This commit is contained in:
2
dist/reveal.esm.js
vendored
2
dist/reveal.esm.js
vendored
File diff suppressed because one or more lines are too long
2
dist/reveal.esm.js.map
vendored
2
dist/reveal.esm.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/reveal.js
vendored
2
dist/reveal.js
vendored
File diff suppressed because one or more lines are too long
2
dist/reveal.js.map
vendored
2
dist/reveal.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -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
|
* Makes it possible to jump to a slide by entering its
|
||||||
* slide number or id.
|
* slide number or id.
|
||||||
@@ -66,11 +71,33 @@ export default class JumpToSlide {
|
|||||||
clearTimeout( this.jumpTimeout );
|
clearTimeout( this.jumpTimeout );
|
||||||
delete this.jumpTimeout;
|
delete this.jumpTimeout;
|
||||||
|
|
||||||
const query = this.jumpInput.value.trim( '' );
|
let query = this.jumpInput.value.trim( '' );
|
||||||
let indices = this.Reveal.location.getIndicesFromHash( query, { oneBasedIndex: true } );
|
let indices;
|
||||||
|
|
||||||
// If no valid index was found and the input query is a
|
// When slide numbers are formatted to be a single linear mumber
|
||||||
// string, fall back on a simple search
|
// (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 } );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Still no valid index? Fall back on a text search
|
||||||
if( !indices && /\S+/i.test( query ) && query.length > 1 ) {
|
if( !indices && /\S+/i.test( query ) && query.length > 1 ) {
|
||||||
indices = this.search( query );
|
indices = this.search( query );
|
||||||
}
|
}
|
||||||
|
@@ -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.
|
* Handles the display of reveal.js' optional slide number.
|
||||||
*/
|
*/
|
||||||
@@ -56,7 +63,7 @@ export default class SlideNumber {
|
|||||||
|
|
||||||
let config = this.Reveal.getConfig();
|
let config = this.Reveal.getConfig();
|
||||||
let value;
|
let value;
|
||||||
let format = 'h.v';
|
let format = SLIDE_NUMBER_FORMAT_HORIZONTAL_DOT_VERTICAL;
|
||||||
|
|
||||||
if ( typeof config.slideNumber === 'function' ) {
|
if ( typeof config.slideNumber === 'function' ) {
|
||||||
value = config.slideNumber( slide );
|
value = config.slideNumber( slide );
|
||||||
@@ -69,7 +76,7 @@ export default class SlideNumber {
|
|||||||
// If there are ONLY vertical slides in this deck, always use
|
// If there are ONLY vertical slides in this deck, always use
|
||||||
// a flattened slide number
|
// a flattened slide number
|
||||||
if( !/c/.test( format ) && this.Reveal.getHorizontalSlides().length === 1 ) {
|
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
|
// Offset the current slide number by 1 to make it 1-indexed
|
||||||
@@ -77,16 +84,16 @@ export default class SlideNumber {
|
|||||||
|
|
||||||
value = [];
|
value = [];
|
||||||
switch( format ) {
|
switch( format ) {
|
||||||
case 'c':
|
case SLIDE_NUMBER_FORMAT_CURRENT:
|
||||||
value.push( this.Reveal.getSlidePastCount( slide ) + horizontalOffset );
|
value.push( this.Reveal.getSlidePastCount( slide ) + horizontalOffset );
|
||||||
break;
|
break;
|
||||||
case 'c/t':
|
case SLIDE_NUMBER_FORMAT_CURRENT_SLASH_TOTAL:
|
||||||
value.push( this.Reveal.getSlidePastCount( slide ) + horizontalOffset, '/', this.Reveal.getTotalSlides() );
|
value.push( this.Reveal.getSlidePastCount( slide ) + horizontalOffset, '/', this.Reveal.getTotalSlides() );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
let indices = this.Reveal.getIndices( slide );
|
let indices = this.Reveal.getIndices( slide );
|
||||||
value.push( indices.h + horizontalOffset );
|
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 );
|
if( this.Reveal.isVerticalSlide( slide ) ) value.push( sep, indices.v + 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,4 +7,10 @@ export const VERTICAL_SLIDES_SELECTOR = '.slides>section.present>section';
|
|||||||
export const POST_MESSAGE_METHOD_BLACKLIST = /registerPlugin|registerKeyboardShortcut|addKeyBinding|addEventListener|showPreview/;
|
export const POST_MESSAGE_METHOD_BLACKLIST = /registerPlugin|registerKeyboardShortcut|addKeyBinding|addEventListener|showPreview/;
|
||||||
|
|
||||||
// Regex for retrieving the fragment style from a class attribute
|
// 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';
|
Reference in New Issue
Block a user