From 260f28792644055998c7237cf879ec2a9ffe857e Mon Sep 17 00:00:00 2001 From: "Dougal J. Sutherland" Date: Thu, 4 Jan 2018 20:09:01 +0000 Subject: [PATCH 1/2] optionally put the fragment in the URL --- README.md | 4 ++++ js/reveal.js | 32 +++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9d71472..9a2d516 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,10 @@ Reveal.initialize({ // Turns fragments on and off globally 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, // i.e. contained within a limited portion of the screen embedded: false, diff --git a/js/reveal.js b/js/reveal.js index f125c55..8edf66a 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -102,6 +102,10 @@ // Turns fragments on and off globally 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, // i.e. contained within a limited portion of the screen embedded: false, @@ -3709,10 +3713,14 @@ else { // Read the index components of the hash 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 ) { - slide( h, v ); + if( h !== indexh || v !== indexv || f !== undefined ) { + slide( h, v, f ); } } @@ -3745,14 +3753,21 @@ id = id.replace( /[^a-zA-Z0-9\-\_\:\.]/g, '' ); } - // If the current slide has an ID, use that as a named link - if( typeof id === 'string' && id.length ) { + 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 ) url += indexh; - if( indexv > 0 ) url += '/' + indexv; + 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; @@ -4089,6 +4104,9 @@ updateControls(); updateProgress(); + if( config.fragmentInURL ) { + writeURL(); + } return !!( fragmentsShown.length || fragmentsHidden.length ); From d68423f310cc680352b561af3e975230e2ff54b1 Mon Sep 17 00:00:00 2001 From: "Dougal J. Sutherland" Date: Sun, 21 Jan 2018 18:03:48 +0000 Subject: [PATCH 2/2] fix fragment handling when desired fragment is 0 --- js/reveal.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/reveal.js b/js/reveal.js index 8edf66a..14b3685 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -3716,7 +3716,10 @@ v = parseInt( bits[1], 10 ) || 0, f; if( config.fragmentInURL ) { - f = parseInt( bits[2], 10 ) || undefined; + f = parseInt( bits[2], 10 ); + if( isNaN( f ) ) { + f = undefined; + } } if( h !== indexh || v !== indexv || f !== undefined ) {