Merge pull request #2133 from sean-parent/master
Adding support for hash linked slideNumber
This commit is contained in:
commit
f713d9d67d
85
js/reveal.js
85
js/reveal.js
@ -68,6 +68,10 @@
|
|||||||
|
|
||||||
// Display the page number of the current slide
|
// Display the page number of the current slide
|
||||||
slideNumber: false,
|
slideNumber: false,
|
||||||
|
|
||||||
|
// Use 1 based indexing for # links to match slide number (default is zero
|
||||||
|
// based)
|
||||||
|
hashOneBasedIndex: false,
|
||||||
|
|
||||||
// Determine which displays to show the slide number on
|
// Determine which displays to show the slide number on
|
||||||
showSlideNumber: 'all',
|
showSlideNumber: 'all',
|
||||||
@ -2251,7 +2255,41 @@
|
|||||||
return overview;
|
return overview;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a hash URL that will resolve to the current slide location.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function locationHash() {
|
||||||
|
|
||||||
|
var url = '/';
|
||||||
|
|
||||||
|
// Attempt to create a named link based on the slide's ID
|
||||||
|
var id = currentSlide ? currentSlide.getAttribute( 'id' ) : null;
|
||||||
|
if( id ) {
|
||||||
|
id = encodeURIComponent( id );
|
||||||
|
}
|
||||||
|
|
||||||
|
var indexf;
|
||||||
|
if( config.fragmentInURL ) {
|
||||||
|
indexf = getIndices().f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the current slide has an ID, use that as a named link,
|
||||||
|
// but we don't support named links with a fragment index
|
||||||
|
if( typeof id === 'string' && id.length && indexf === undefined ) {
|
||||||
|
url = '/' + id;
|
||||||
|
}
|
||||||
|
// Otherwise use the /h/v index
|
||||||
|
else {
|
||||||
|
if( indexh > 0 || indexv > 0 || indexf !== undefined ) url += indexh + config.hashOneBasedIndex;
|
||||||
|
if( indexv > 0 || indexf !== undefined ) url += '/' + (indexv + config.hashOneBasedIndex);
|
||||||
|
if( indexf !== undefined ) url += '/' + indexf;
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the current or specified slide is vertical
|
* Checks if the current or specified slide is vertical
|
||||||
* (nested within another slide).
|
* (nested within another slide).
|
||||||
@ -2917,6 +2955,7 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the slide number div to reflect the current slide.
|
* Updates the slide number div to reflect the current slide.
|
||||||
*
|
*
|
||||||
@ -2970,14 +3009,18 @@
|
|||||||
* @return {string} HTML string fragment
|
* @return {string} HTML string fragment
|
||||||
*/
|
*/
|
||||||
function formatSlideNumber( a, delimiter, b ) {
|
function formatSlideNumber( a, delimiter, b ) {
|
||||||
|
var url = '#' + locationHash();
|
||||||
if( typeof b === 'number' && !isNaN( b ) ) {
|
if( typeof b === 'number' && !isNaN( b ) ) {
|
||||||
return '<span class="slide-number-a">'+ a +'</span>' +
|
return '<a href="' + url + '">' +
|
||||||
|
'<span class="slide-number-a">'+ a +'</span>' +
|
||||||
'<span class="slide-number-delimiter">'+ delimiter +'</span>' +
|
'<span class="slide-number-delimiter">'+ delimiter +'</span>' +
|
||||||
'<span class="slide-number-b">'+ b +'</span>';
|
'<span class="slide-number-b">'+ b +'</span>' +
|
||||||
|
'</a>';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return '<span class="slide-number-a">'+ a +'</span>';
|
return '<a href="' + url + '">' +
|
||||||
|
'<span class="slide-number-a">'+ a +'</span>' +
|
||||||
|
'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -3796,8 +3839,9 @@
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Read the index components of the hash
|
// Read the index components of the hash
|
||||||
var h = parseInt( bits[0], 10 ) || 0,
|
|
||||||
v = parseInt( bits[1], 10 ) || 0,
|
var h = parseInt( bits[0], 10 ) || 0 - config.hashOneBasedIndex,
|
||||||
|
v = parseInt( bits[1], 10 ) || 0 - config.hashOneBasedIndex,
|
||||||
f;
|
f;
|
||||||
if( config.fragmentInURL ) {
|
if( config.fragmentInURL ) {
|
||||||
f = parseInt( bits[2], 10 );
|
f = parseInt( bits[2], 10 );
|
||||||
@ -3812,7 +3856,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the page URL (hash) to reflect the current
|
* Updates the page URL (hash) to reflect the current
|
||||||
* state.
|
* state.
|
||||||
@ -3832,32 +3876,7 @@
|
|||||||
writeURLTimeout = setTimeout( writeURL, delay );
|
writeURLTimeout = setTimeout( writeURL, delay );
|
||||||
}
|
}
|
||||||
else if( currentSlide ) {
|
else if( currentSlide ) {
|
||||||
var url = '/';
|
window.location.hash = locationHash();
|
||||||
|
|
||||||
// Attempt to create a named link based on the slide's ID
|
|
||||||
var id = currentSlide.getAttribute( 'id' );
|
|
||||||
if( id ) {
|
|
||||||
id = encodeURIComponent( id );
|
|
||||||
}
|
|
||||||
|
|
||||||
var indexf;
|
|
||||||
if( config.fragmentInURL ) {
|
|
||||||
indexf = getIndices().f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the current slide has an ID, use that as a named link,
|
|
||||||
// but we don't support named links with a fragment index
|
|
||||||
if( typeof id === 'string' && id.length && indexf === undefined ) {
|
|
||||||
url = '/' + id;
|
|
||||||
}
|
|
||||||
// Otherwise use the /h/v index
|
|
||||||
else {
|
|
||||||
if( indexh > 0 || indexv > 0 || indexf !== undefined ) url += indexh;
|
|
||||||
if( indexv > 0 || indexf !== undefined ) url += '/' + indexv;
|
|
||||||
if( indexf !== undefined ) url += '/' + indexf;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.location.hash = url;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user