support for custom slide number formatting #965
This commit is contained in:
parent
817bb3bf43
commit
5fb81b1b3c
@ -572,7 +572,16 @@ By default, Reveal is configured with [highlight.js](http://softwaremaniacs.org/
|
|||||||
If you would like to display the page number of the current slide you can do so using the ```slideNumber``` configuration value.
|
If you would like to display the page number of the current slide you can do so using the ```slideNumber``` configuration value.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
// Shows the slide number using default formatting
|
||||||
Reveal.configure({ slideNumber: true });
|
Reveal.configure({ slideNumber: true });
|
||||||
|
|
||||||
|
// Slide number formatting can be configured using these variables:
|
||||||
|
// h: current slide's horizontal index
|
||||||
|
// v: current slide's vertical index
|
||||||
|
// c: current slide index (flattened)
|
||||||
|
// t: total number of slides (flattened)
|
||||||
|
Reveal.configure({ slideNumber: 'c / t' });
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
24
js/reveal.js
24
js/reveal.js
@ -2331,19 +2331,33 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the slide number div to reflect the current slide.
|
* Updates the slide number div to reflect the current slide.
|
||||||
|
*
|
||||||
|
* Slide number format can be defined as a string using the
|
||||||
|
* following variables:
|
||||||
|
* h: current slide's horizontal index
|
||||||
|
* v: current slide's vertical index
|
||||||
|
* c: current slide index (flattened)
|
||||||
|
* t: total number of slides (flattened)
|
||||||
*/
|
*/
|
||||||
function updateSlideNumber() {
|
function updateSlideNumber() {
|
||||||
|
|
||||||
// Update slide number if enabled
|
// Update slide number if enabled
|
||||||
if( config.slideNumber && dom.slideNumber) {
|
if( config.slideNumber && dom.slideNumber) {
|
||||||
|
|
||||||
// Display the number of the page using 'indexh - indexv' format
|
// Default to only showing the current slide number
|
||||||
var indexString = indexh;
|
var format = 'c';
|
||||||
if( indexv > 0 ) {
|
|
||||||
indexString += ' - ' + indexv;
|
// Check if a custom slide number format is available
|
||||||
|
if( typeof config.slideNumber === 'string' ) {
|
||||||
|
format = config.slideNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
dom.slideNumber.innerHTML = indexString;
|
var totalSlides = getTotalSlides();
|
||||||
|
|
||||||
|
dom.slideNumber.innerHTML = format.replace( /h/g, indexh )
|
||||||
|
.replace( /v/g, indexv )
|
||||||
|
.replace( /c/g, Math.round( getProgress() * totalSlides ) + 1 )
|
||||||
|
.replace( /t/g, totalSlides + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user