Add new 'hash: true' option which uses replaceState for url

Resolves #2211
This commit is contained in:
Anthony Sottile 2018-12-02 16:46:00 -08:00
parent 87d6af2cb4
commit fd6245bb28
2 changed files with 19 additions and 11 deletions

View File

@ -259,9 +259,12 @@ Reveal.initialize({
// Display the page number of the current slide // Display the page number of the current slide
slideNumber: false, slideNumber: false,
// Push each slide change to the browser history // Push each slide change to the browser history. Implies `hash: true`
history: false, history: false,
// Change the hash when changing slides -- impacts browser history with `history: true`
hash: false,
// Enable keyboard shortcuts for navigation // Enable keyboard shortcuts for navigation
keyboard: true, keyboard: true,

View File

@ -76,9 +76,12 @@
// Determine which displays to show the slide number on // Determine which displays to show the slide number on
showSlideNumber: 'all', showSlideNumber: 'all',
// Push each slide change to the browser history // Push each slide change to the browser history. Implies `hash: true`
history: false, history: false,
// Change the hash when changing slides -- impacts browser history with `history: true`
hash: false,
// Enable keyboard shortcuts for navigation // Enable keyboard shortcuts for navigation
keyboard: true, keyboard: true,
@ -4114,8 +4117,6 @@
*/ */
function writeURL( delay ) { function writeURL( delay ) {
if( config.history ) {
// Make sure there's never more than one timeout running // Make sure there's never more than one timeout running
clearTimeout( writeURLTimeout ); clearTimeout( writeURLTimeout );
@ -4124,8 +4125,12 @@
writeURLTimeout = setTimeout( writeURL, delay ); writeURLTimeout = setTimeout( writeURL, delay );
} }
else if( currentSlide ) { else if( currentSlide ) {
if ( config.history ) {
window.location.hash = locationHash(); window.location.hash = locationHash();
} }
else if ( config.hash ) {
window.history.replaceState(null, null, '#' + locationHash());
}
} }
} }