1
0
Fork 0

optionally put the fragment in the URL

This commit is contained in:
Dougal J. Sutherland 2018-01-04 20:09:01 +00:00
parent a0c013606e
commit 260f287926
2 changed files with 29 additions and 7 deletions

View File

@ -231,6 +231,10 @@ Reveal.initialize({
// Turns fragments on and off globally // Turns fragments on and off globally
fragments: true, fragments: true,
// Flags whether to include the current fragment in the URL,
// so that reloading brings you to the same fragment position
fragmentInURL: false,
// Flags if the presentation is running in an embedded mode, // Flags if the presentation is running in an embedded mode,
// i.e. contained within a limited portion of the screen // i.e. contained within a limited portion of the screen
embedded: false, embedded: false,

View File

@ -102,6 +102,10 @@
// Turns fragments on and off globally // Turns fragments on and off globally
fragments: true, fragments: true,
// Flags whether to include the current fragment in the URL,
// so that reloading brings you to the same fragment position
fragmentInURL: false,
// Flags if the presentation is running in an embedded mode, // Flags if the presentation is running in an embedded mode,
// i.e. contained within a limited portion of the screen // i.e. contained within a limited portion of the screen
embedded: false, embedded: false,
@ -3709,10 +3713,14 @@
else { else {
// Read the index components of the hash // Read the index components of the hash
var h = parseInt( bits[0], 10 ) || 0, var h = parseInt( bits[0], 10 ) || 0,
v = parseInt( bits[1], 10 ) || 0; v = parseInt( bits[1], 10 ) || 0,
f;
if( config.fragmentInURL ) {
f = parseInt( bits[2], 10 ) || undefined;
}
if( h !== indexh || v !== indexv ) { if( h !== indexh || v !== indexv || f !== undefined ) {
slide( h, v ); slide( h, v, f );
} }
} }
@ -3745,14 +3753,21 @@
id = id.replace( /[^a-zA-Z0-9\-\_\:\.]/g, '' ); id = id.replace( /[^a-zA-Z0-9\-\_\:\.]/g, '' );
} }
// If the current slide has an ID, use that as a named link var indexf;
if( typeof id === 'string' && id.length ) { 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; url = '/' + id;
} }
// Otherwise use the /h/v index // Otherwise use the /h/v index
else { else {
if( indexh > 0 || indexv > 0 ) url += indexh; if( indexh > 0 || indexv > 0 || indexf !== undefined ) url += indexh;
if( indexv > 0 ) url += '/' + indexv; if( indexv > 0 || indexf !== undefined ) url += '/' + indexv;
if( indexf !== undefined ) url += '/' + indexf;
} }
window.location.hash = url; window.location.hash = url;
@ -4089,6 +4104,9 @@
updateControls(); updateControls();
updateProgress(); updateProgress();
if( config.fragmentInURL ) {
writeURL();
}
return !!( fragmentsShown.length || fragmentsHidden.length ); return !!( fragmentsShown.length || fragmentsHidden.length );