Skip to content

Commit

Permalink
Merge pull request hakimel#2315 from dougalsutherland/slide-formats
Browse files Browse the repository at this point in the history
allow custom slide numbering functions
  • Loading branch information
hakimel authored Feb 1, 2019
2 parents 2a9edd2 + 43d1c71 commit d033724
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions js/reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3269,40 +3269,48 @@
* "h/v": horizontal / vertical slide number
* "c": flattened slide number
* "c/t": flattened slide number / total slides
*
* Alternatively, config.slideNumber can be a function returning a
* three-element array with arguments to formatSlideNumber().
*/
function updateSlideNumber() {

// Update slide number if enabled
if( config.slideNumber && dom.slideNumber ) {

var value = [];
var value;
var format = 'h.v';

// Check if a custom number format is available
if( typeof config.slideNumber === 'string' ) {
format = config.slideNumber;
}

// If there are ONLY vertical slides in this deck, always use
// a flattened slide number
if( !/c/.test( format ) && dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ).length === 1 ) {
format = 'c';
}

switch( format ) {
case 'c':
value.push( getSlidePastCount() + 1 );
break;
case 'c/t':
value.push( getSlidePastCount() + 1, '/', getTotalSlides() );
break;
case 'h/v':
value.push( indexh + 1 );
if( isVerticalSlide() ) value.push( '/', indexv + 1 );
break;
default:
value.push( indexh + 1 );
if( isVerticalSlide() ) value.push( '.', indexv + 1 );
if ( typeof config.slideNumber === 'function' ) {
value = config.slideNumber();
} else {
// Check if a custom number format is available
if( typeof config.slideNumber === 'string' ) {
format = config.slideNumber;
}

// If there are ONLY vertical slides in this deck, always use
// a flattened slide number
if( !/c/.test( format ) && dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ).length === 1 ) {
format = 'c';
}

value = [];
switch( format ) {
case 'c':
value.push( getSlidePastCount() + 1 );
break;
case 'c/t':
value.push( getSlidePastCount() + 1, '/', getTotalSlides() );
break;
case 'h/v':
value.push( indexh + 1 );
if( isVerticalSlide() ) value.push( '/', indexv + 1 );
break;
default:
value.push( indexh + 1 );
if( isVerticalSlide() ) value.push( '.', indexv + 1 );
}
}

dom.slideNumber.innerHTML = formatSlideNumber( value[0], value[1], value[2] );
Expand Down

0 comments on commit d033724

Please sign in to comment.