aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2020-04-22 11:11:14 +0200
committerHakim El Hattab <hakim.elhattab@gmail.com>2020-04-22 11:11:14 +0200
commit9823be99f4ae5019ee6ce272d5fefba658953959 (patch)
treecd88a8522a9ee94042d15ae71598a2a6b535369c /js
parentd727509dbcc1e6566818a8ada5b40b0cdccd42ff (diff)
downloadfosdem-2021-minimalism-presentation-9823be99f4ae5019ee6ce272d5fefba658953959.tar
fosdem-2021-minimalism-presentation-9823be99f4ae5019ee6ce272d5fefba658953959.tar.gz
fragments are now included in URL by default, even on named slides
Diffstat (limited to 'js')
-rw-r--r--js/config.js2
-rw-r--r--js/controllers/location.js54
-rw-r--r--js/reveal.js15
3 files changed, 49 insertions, 22 deletions
diff --git a/js/config.js b/js/config.js
index 846e9aa..0419f99 100644
--- a/js/config.js
+++ b/js/config.js
@@ -124,7 +124,7 @@ export default {
// Flags whether to include the current fragment in the URL,
// so that reloading brings you to the same fragment position
- fragmentInURL: false,
+ fragmentInURL: true,
// Flags if the presentation is running in an embedded mode,
// i.e. contained within a limited portion of the screen
diff --git a/js/controllers/location.js b/js/controllers/location.js
index 3a9afd5..f511ed7 100644
--- a/js/controllers/location.js
+++ b/js/controllers/location.js
@@ -12,6 +12,20 @@ export default class Location {
// Delays updates to the URL due to a Chrome thumbnailer bug
this.writeURLTimeout = 0;
+ this.onWindowHashChange = this.onWindowHashChange.bind( this );
+
+ }
+
+ bind() {
+
+ window.addEventListener( 'hashchange', this.onWindowHashChange, false );
+
+ }
+
+ unbind() {
+
+ window.removeEventListener( 'hashchange', this.onWindowHashChange, false );
+
}
/**
@@ -27,13 +41,22 @@ export default class Location {
// Attempt to parse the hash as either an index or name
let bits = hash.slice( 2 ).split( '/' ),
- name = hash.replace( /#|\//gi, '' );
+ name = hash.replace( /#\/?/gi, '' );
// If the first bit is not fully numeric and there is a name we
// can assume that this is a named link
if( !/^[0-9]*$/.test( bits[0] ) && name.length ) {
let element;
+ let f;
+
+ // Parse named links with fragments (#/named-link/2)
+ if( /\/[-\d]+$/g.test( name ) ) {
+ f = parseInt( name.split( '/' ).pop(), 10 );
+ f = isNaN(f) ? undefined : f;
+ name = name.split( '/' ).shift();
+ }
+
// Ensure the named link is a valid HTML ID attribute
try {
element = document.getElementById( decodeURIComponent( name ) );
@@ -45,10 +68,10 @@ export default class Location {
if( element ) {
// If the slide exists and is not the current slide...
- if ( !isSameNameAsCurrentSlide ) {
+ if ( !isSameNameAsCurrentSlide || typeof f !== 'undefined' ) {
// ...find the position of the named slide and navigate to it
- let elementIndex = this.Reveal.getIndices(element);
- this.Reveal.slide(elementIndex.h, elementIndex.v);
+ let slideIndices = this.Reveal.getIndices( element );
+ this.Reveal.slide( slideIndices.h, slideIndices.v, f );
}
}
// If the slide doesn't exist, navigate to the current slide
@@ -141,19 +164,34 @@ export default class Location {
// 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 && index.f === undefined ) {
+ if( typeof id === 'string' && id.length ) {
url = '/' + id;
+
+ // If there is also a fragment, append that at the end
+ // of the named link, like: #/named-link/2
+ if( index.f >= 0 ) url += '/' + index.f;
}
// Otherwise use the /h/v index
else {
let hashIndexBase = this.Reveal.getConfig().hashOneBasedIndex ? 1 : 0;
- if( index.h > 0 || index.v > 0 || index.f !== undefined ) url += index.h + hashIndexBase;
- if( index.v > 0 || index.f !== undefined ) url += '/' + (index.v + hashIndexBase );
- if( index.f !== undefined ) url += '/' + index.f;
+ if( index.h > 0 || index.v > 0 || index.f >= 0 ) url += index.h + hashIndexBase;
+ if( index.v > 0 || index.f >= 0 ) url += '/' + (index.v + hashIndexBase );
+ if( index.f >= 0 ) url += '/' + index.f;
}
return url;
}
+ /**
+ * Handler for the window level 'hashchange' event.
+ *
+ * @param {object} [event]
+ */
+ onWindowHashChange( event ) {
+
+ this.readURL();
+
+ }
+
} \ No newline at end of file
diff --git a/js/reveal.js b/js/reveal.js
index 6712529..1efce46 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -490,13 +490,13 @@ export default function( revealElement, options ) {
eventsAreBound = true;
- window.addEventListener( 'hashchange', onWindowHashChange, false );
window.addEventListener( 'resize', onWindowResize, false );
if( config.touch ) touch.bind();
if( config.keyboard ) keyboard.bind();
if( config.progress ) progress.bind();
controls.bind();
+ location.bind();
dom.slides.addEventListener( 'transitionend', onTransitionEnd, false );
dom.pauseOverlay.addEventListener( 'click', resume, false );
@@ -518,8 +518,8 @@ export default function( revealElement, options ) {
keyboard.unbind();
controls.unbind();
progress.unbind();
+ location.unbind();
- window.removeEventListener( 'hashchange', onWindowHashChange, false );
window.removeEventListener( 'resize', onWindowResize, false );
dom.slides.removeEventListener( 'transitionend', onTransitionEnd, false );
@@ -2289,17 +2289,6 @@ export default function( revealElement, options ) {
}
/**
- * Handler for the window level 'hashchange' event.
- *
- * @param {object} [event]
- */
- function onWindowHashChange( event ) {
-
- location.readURL();
-
- }
-
- /**
* Handler for the window level 'resize' event.
*
* @param {object} [event]