honor slide number config in pdf mode
This commit is contained in:
parent
1cf5ffe029
commit
c189a21efd
|
@ -1011,9 +1011,9 @@ Reveal.configure({ slideNumber: true });
|
||||||
Reveal.configure({ slideNumber: 'c/t' });
|
Reveal.configure({ slideNumber: 'c/t' });
|
||||||
|
|
||||||
// You can provide a function to fully customize the number:
|
// You can provide a function to fully customize the number:
|
||||||
Reveal.configure({ slideNumber: function() {
|
Reveal.configure({ slideNumber: function( slide ) {
|
||||||
// Ignore numbering of vertical slides
|
// Ignore numbering of vertical slides
|
||||||
return [ Reveal.getIndices().h ];
|
return [ Reveal.getIndices( slide ).h ];
|
||||||
}});
|
}});
|
||||||
|
|
||||||
// Control which views the slide number displays on using the "showSlideNumber" value:
|
// Control which views the slide number displays on using the "showSlideNumber" value:
|
||||||
|
|
71
js/reveal.js
71
js/reveal.js
|
@ -77,9 +77,9 @@
|
||||||
// - "c/t": Flattened slide number / total slides
|
// - "c/t": Flattened slide number / total slides
|
||||||
//
|
//
|
||||||
// Alternatively, you can provide a function that returns the slide
|
// Alternatively, you can provide a function that returns the slide
|
||||||
// number for the current slide. The function needs to return an array
|
// number for the current slide. The function should take in a slide
|
||||||
// with one string [slideNumber] or three strings [n1,delimiter,n2].
|
// object and return an array with one string [slideNumber] or
|
||||||
// See #formatSlideNumber().
|
// three strings [n1,delimiter,n2]. See #formatSlideNumber().
|
||||||
slideNumber: false,
|
slideNumber: false,
|
||||||
|
|
||||||
// Can be used to limit the contexts in which the slide number appears
|
// Can be used to limit the contexts in which the slide number appears
|
||||||
|
@ -850,17 +850,10 @@
|
||||||
// Make sure stretch elements fit on slide
|
// Make sure stretch elements fit on slide
|
||||||
layoutSlideContents( slideWidth, slideHeight );
|
layoutSlideContents( slideWidth, slideHeight );
|
||||||
|
|
||||||
// Add each slide's index as attributes on itself, we need these
|
// Compute slide numbers now, before we start duplicating slides
|
||||||
// indices to generate slide numbers below
|
var doingSlideNumbers = config.slideNumber && /all|print/i.test( config.showSlideNumber );
|
||||||
toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).forEach( function( hslide, h ) {
|
toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
|
||||||
hslide.setAttribute( 'data-index-h', h );
|
slide.setAttribute( 'data-slide-number', getSlideNumber( slide ) );
|
||||||
|
|
||||||
if( hslide.classList.contains( 'stack' ) ) {
|
|
||||||
toArray( hslide.querySelectorAll( 'section' ) ).forEach( function( vslide, v ) {
|
|
||||||
vslide.setAttribute( 'data-index-h', h );
|
|
||||||
vslide.setAttribute( 'data-index-v', v );
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// Slide and slide background layout
|
// Slide and slide background layout
|
||||||
|
@ -931,14 +924,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject slide numbers if `slideNumbers` are enabled
|
// Inject slide numbers if `slideNumbers` are enabled
|
||||||
if( config.slideNumber && /all|print/i.test( config.showSlideNumber ) ) {
|
if( doingSlideNumbers ) {
|
||||||
var slideNumberH = parseInt( slide.getAttribute( 'data-index-h' ), 10 ) + 1,
|
|
||||||
slideNumberV = parseInt( slide.getAttribute( 'data-index-v' ), 10 ) + 1;
|
|
||||||
|
|
||||||
var numberElement = document.createElement( 'div' );
|
var numberElement = document.createElement( 'div' );
|
||||||
numberElement.classList.add( 'slide-number' );
|
numberElement.classList.add( 'slide-number' );
|
||||||
numberElement.classList.add( 'slide-number-pdf' );
|
numberElement.classList.add( 'slide-number-pdf' );
|
||||||
numberElement.innerHTML = formatSlideNumber( slideNumberH, '.', slideNumberV );
|
numberElement.innerHTML = slide.getAttribute( 'data-slide-number' );
|
||||||
page.appendChild( numberElement );
|
page.appendChild( numberElement );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3425,14 +3415,26 @@
|
||||||
|
|
||||||
// Update slide number if enabled
|
// Update slide number if enabled
|
||||||
if( config.slideNumber && dom.slideNumber ) {
|
if( config.slideNumber && dom.slideNumber ) {
|
||||||
|
dom.slideNumber.innerHTML = getSlideNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the HTML string corresponding to the current slide number,
|
||||||
|
* including formatting.
|
||||||
|
*/
|
||||||
|
function getSlideNumber( slide ) {
|
||||||
|
|
||||||
var value;
|
var value;
|
||||||
var format = 'h.v';
|
var format = 'h.v';
|
||||||
|
if( slide === undefined ) {
|
||||||
|
slide = currentSlide;
|
||||||
|
}
|
||||||
|
|
||||||
if ( typeof config.slideNumber === 'function' ) {
|
if ( typeof config.slideNumber === 'function' ) {
|
||||||
value = config.slideNumber();
|
value = config.slideNumber( slide );
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Check if a custom number format is available
|
// Check if a custom number format is available
|
||||||
if( typeof config.slideNumber === 'string' ) {
|
if( typeof config.slideNumber === 'string' ) {
|
||||||
format = config.slideNumber;
|
format = config.slideNumber;
|
||||||
|
@ -3447,23 +3449,21 @@
|
||||||
value = [];
|
value = [];
|
||||||
switch( format ) {
|
switch( format ) {
|
||||||
case 'c':
|
case 'c':
|
||||||
value.push( getSlidePastCount() + 1 );
|
value.push( getSlidePastCount( slide ) + 1 );
|
||||||
break;
|
break;
|
||||||
case 'c/t':
|
case 'c/t':
|
||||||
value.push( getSlidePastCount() + 1, '/', getTotalSlides() );
|
value.push( getSlidePastCount( slide ) + 1, '/', getTotalSlides() );
|
||||||
break;
|
|
||||||
case 'h/v':
|
|
||||||
value.push( indexh + 1 );
|
|
||||||
if( isVerticalSlide() ) value.push( '/', indexv + 1 );
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
value.push( indexh + 1 );
|
var indices = getIndices( slide );
|
||||||
if( isVerticalSlide() ) value.push( '.', indexv + 1 );
|
value.push( indices.h + 1 );
|
||||||
|
var sep = format === 'h/v' ? '/' : '.';
|
||||||
|
if( isVerticalSlide( slide ) ) value.push( sep, indices.v + 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dom.slideNumber.innerHTML = formatSlideNumber( value[0], value[1], value[2] );
|
var url = '#' + locationHash( slide );
|
||||||
}
|
return formatSlideNumber( value[0], value[1], value[2], url );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3474,11 +3474,14 @@
|
||||||
* @param {number} a Current slide
|
* @param {number} a Current slide
|
||||||
* @param {string} delimiter Character to separate slide numbers
|
* @param {string} delimiter Character to separate slide numbers
|
||||||
* @param {(number|*)} b Total slides
|
* @param {(number|*)} b Total slides
|
||||||
|
* @param {HTMLElement} [url='#'+locationHash()] The url to link to
|
||||||
* @return {string} HTML string fragment
|
* @return {string} HTML string fragment
|
||||||
*/
|
*/
|
||||||
function formatSlideNumber( a, delimiter, b ) {
|
function formatSlideNumber( a, delimiter, b, url ) {
|
||||||
|
|
||||||
var url = '#' + locationHash();
|
if( url === undefined ) {
|
||||||
|
url = '#' + locationHash();
|
||||||
|
}
|
||||||
if( typeof b === 'number' && !isNaN( b ) ) {
|
if( typeof b === 'number' && !isNaN( b ) ) {
|
||||||
return '<a href="' + url + '">' +
|
return '<a href="' + url + '">' +
|
||||||
'<span class="slide-number-a">'+ a +'</span>' +
|
'<span class="slide-number-a">'+ a +'</span>' +
|
||||||
|
|
Loading…
Reference in New Issue