aboutsummaryrefslogtreecommitdiff
path: root/js/reveal.js
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2012-08-20 22:13:00 -0400
committerHakim El Hattab <hakim.elhattab@gmail.com>2012-08-20 22:13:00 -0400
commit141d69469c5773b0f6850c40688fb91240751ea9 (patch)
tree6831b75b40f4a9c9d30d71aa5772d59221e100dc /js/reveal.js
parent5bd5ac67a4ddab7e5b2b1cb36b41be02a8a741e9 (diff)
downloadfosdem-2018-presentation-141d69469c5773b0f6850c40688fb91240751ea9.tar
fosdem-2018-presentation-141d69469c5773b0f6850c40688fb91240751ea9.tar.gz
support for named links (closes #55)
Diffstat (limited to 'js/reveal.js')
-rw-r--r--js/reveal.js67
1 files changed, 53 insertions, 14 deletions
diff --git a/js/reveal.js b/js/reveal.js
index 322d06e..9c26f29 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -1,5 +1,5 @@
/*!
- * reveal.js 2.0 r19
+ * reveal.js 2.0 r20
* http://lab.hakim.se/reveal-js
* MIT licensed
*
@@ -834,14 +834,35 @@ var Reveal = (function(){
* Reads the current URL (hash) and navigates accordingly.
*/
function readURL() {
- // Break the hash down to separate components
- var bits = window.location.hash.slice(2).split('/');
-
- // Read the index components of the hash
- var h = parseInt( bits[0] ) || 0 ;
- var v = parseInt( bits[1] ) || 0 ;
+ var hash = window.location.hash;
+
+ // Attempt to parse the hash as either an index or name
+ var bits = hash.slice( 2 ).split( '/' ),
+ name = hash.replace( /#|\//gi, '' );
+
+ // If the first bit is invalid and there is a name we can
+ // assume that this is a named link
+ if( isNaN( parseInt( bits[0] ) ) && name.length ) {
+ // Find the slide with the specified name
+ var slide = document.querySelector( '#' + name );
+
+ if( slide ) {
+ // Find the position of the named slide and navigate to it
+ var indices = Reveal.getIndices( slide );
+ navigateTo( indices.h, indices.v );
+ }
+ // If the slide doesn't exist, navigate to the current slide
+ else {
+ navigateTo( indexh, indexv );
+ }
+ }
+ else {
+ // Read the index components of the hash
+ var h = parseInt( bits[0] ) || 0,
+ v = parseInt( bits[1] ) || 0;
- navigateTo( h, v );
+ navigateTo( h, v );
+ }
}
/**
@@ -1049,12 +1070,30 @@ var Reveal = (function(){
addEventListeners: addEventListeners,
removeEventListeners: removeEventListeners,
- // Returns the indices of the current slide
- getIndices: function() {
- return {
- h: indexh,
- v: indexv
- };
+ // Returns the indices of the current, or specified, slide
+ getIndices: function( slide ) {
+ // By default, return the current indices
+ var h = indexh,
+ v = indexv;
+
+ // If a slide is specified, return the indices of that slide
+ if( slide ) {
+ var isVertical = !!slide.parentNode.nodeName.match( /section/gi );
+ var slideh = isVertical ? slide.parentNode : slide;
+
+ // Select all horizontal slides
+ var horizontalSlides = Array.prototype.slice.call( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
+
+ // Now that we know which the horizontal slide is, get its index
+ h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
+
+ // If this is a vertical slide, grab the vertical index
+ if( isVertical ) {
+ v = Math.max( Array.prototype.slice.call( slide.parentNode.children ).indexOf( slide ), 0 );
+ }
+ }
+
+ return { h: h, v: v };
},
// Returns the previous slide element, may be null