aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/reveal.js728
1 files changed, 501 insertions, 227 deletions
diff --git a/js/reveal.js b/js/reveal.js
index 3c31b97..08ece7f 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -3,7 +3,7 @@
* http://revealjs.com
* MIT licensed
*
- * Copyright (C) 2018 Hakim El Hattab, http://hakim.se
+ * Copyright (C) 2019 Hakim El Hattab, http://hakim.se
*/
(function( root, factory ) {
if( typeof define === 'function' && define.amd ) {
@@ -76,7 +76,11 @@
// Determine which displays to show the slide number on
showSlideNumber: 'all',
- // Push each slide change to the browser history
+ // Add the current slide number to the URL hash so that reloading the
+ // page/copying the URL will return you to the same slide
+ hash: false,
+
+ // Push each slide change to the browser history. Implies `hash: true`
history: false,
// Enable keyboard shortcuts for navigation
@@ -104,6 +108,32 @@
// Change the presentation direction to be RTL
rtl: false,
+ // Changes the behavior of our navigation directions.
+ //
+ // "default"
+ // Left/right arrow keys step between horizontal slides, up/down
+ // arrow keys step between vertical slides. Space key steps through
+ // all slides (both horizontal and vertical).
+ //
+ // "linear"
+ // Removes the up/down arrows. Left/right arrows step through all
+ // slides (both horizontal and vertical).
+ //
+ // "grid"
+ // When this is enabled, stepping left/right from a vertical stack
+ // to an adjacent vertical stack will land you at the same vertical
+ // index.
+ //
+ // Consider a deck with six slides ordered in two vertical stacks:
+ // 1.1 2.1
+ // 1.2 2.2
+ // 1.3 2.3
+ //
+ // If you're on slide 1.3 and navigate right, you will normally move
+ // from 1.3 -> 2.1. With "gridNavigation" enabled the same navigation
+ // takes you from 1.3 -> 2.3.
+ navigationMode: 'default',
+
// Randomizes the order of slides each time the presentation loads
shuffle: false,
@@ -220,6 +250,12 @@
// The display mode that will be used to show slides
display: 'block',
+ // Hide cursor if inactive
+ hideInactiveCursor: true,
+
+ // Time before the cursor is hidden (in ms)
+ hideCursorTime: 5000,
+
// Script dependencies to load
dependencies: []
@@ -282,6 +318,12 @@
// Delays updates to the URL due to a Chrome thumbnailer bug
writeURLTimeout = 0,
+ // Is the mouse pointer currently hidden from view
+ cursorHidden = false,
+
+ // Timeout used to determine when the cursor is inactive
+ cursorInactiveTimeout = 0,
+
// Flags if the interaction event listeners are bound
eventsAreBound = false,
@@ -298,7 +340,6 @@
touch = {
startX: 0,
startY: 0,
- startSpan: 0,
startCount: 0,
captured: false,
threshold: 40
@@ -306,17 +347,17 @@
// Holds information about the keyboard shortcuts
keyboardShortcuts = {
- 'N , SPACE': 'Next slide',
- 'P': 'Previous slide',
- '← , H': 'Navigate left',
- '→ , L': 'Navigate right',
- '↑ , K': 'Navigate up',
- '↓ , J': 'Navigate down',
- 'Home': 'First slide',
- 'End': 'Last slide',
- 'B , .': 'Pause',
- 'F': 'Fullscreen',
- 'ESC, O': 'Slide overview'
+ 'N , SPACE': 'Next slide',
+ 'P': 'Previous slide',
+ '← , H': 'Navigate left',
+ '→ , L': 'Navigate right',
+ '↑ , K': 'Navigate up',
+ '↓ , J': 'Navigate down',
+ 'Home , ⌘/CTRL ←': 'First slide',
+ 'End , ⌘/CTRL →': 'Last slide',
+ 'B , .': 'Pause',
+ 'F': 'Fullscreen',
+ 'ESC, O': 'Slide overview'
},
// Holds custom key code mappings
@@ -436,41 +477,28 @@
scriptsToPreload = 0;
// Called once synchronous scripts finish loading
- function proceed() {
+ function afterSynchronousScriptsLoaded() {
+ // Load asynchronous scripts
if( scriptsAsync.length ) {
- // Load asynchronous scripts
- head.js.apply( null, scriptsAsync );
+ scriptsAsync.forEach( function( s ) {
+ loadScript( s.src, s.callback );
+ } );
}
start();
}
- function loadScript( s ) {
- head.ready( s.src.match( /([\w\d_\-]*)\.?js(\?[\w\d.=&]*)?$|[^\\\/]*$/i )[0], function() {
- // Extension may contain callback functions
- if( typeof s.callback === 'function' ) {
- s.callback.apply( this );
- }
-
- if( --scriptsToPreload === 0 ) {
- proceed();
- }
- });
- }
-
for( var i = 0, len = config.dependencies.length; i < len; i++ ) {
var s = config.dependencies[i];
// Load if there's no condition or the condition is truthy
if( !s.condition || s.condition() ) {
if( s.async ) {
- scriptsAsync.push( s.src );
+ scriptsAsync.push( s );
}
else {
- scripts.push( s.src );
+ scripts.push( s );
}
-
- loadScript( s );
}
}
@@ -478,15 +506,74 @@
scriptsToPreload = scripts.length;
// Load synchronous scripts
- head.js.apply( null, scripts );
+ scripts.forEach( function( s ) {
+ loadScript( s.src, function() {
+
+ if( typeof s.callback === 'function' ) s.callback();
+
+ if( --scriptsToPreload === 0 ) {
+
+ afterSynchronousScriptsLoaded();
+
+ }
+
+ } );
+ } );
}
else {
- proceed();
+ afterSynchronousScriptsLoaded();
}
}
/**
+ * Loads a JavaScript file from the given URL and executes it.
+ *
+ * @param {string} url Address of the .js file to load
+ * @param {function} callback Method to invoke when the script
+ * has loaded and executed
+ */
+ function loadScript( url, callback ) {
+
+ var script = document.createElement( 'script' );
+ script.type = 'text/javascript';
+ script.async = false;
+ script.defer = false;
+ script.src = url;
+
+ if( callback ) {
+
+ // Success callback
+ script.onload = script.onreadystatechange = function( event ) {
+ if( event.type === "load" || (/loaded|complete/.test( script.readyState ) ) ) {
+
+ // Kill event listeners
+ script.onload = script.onreadystatechange = script.onerror = null;
+
+ callback();
+
+ }
+ };
+
+ // Error callback
+ script.onerror = function( err ) {
+
+ // Kill event listeners
+ script.onload = script.onreadystatechange = script.onerror = null;
+
+ callback( new Error( 'Failed loading script: ' + script.src + '\n' + err) );
+
+ };
+
+ }
+
+ // Append the script at the end of <head>
+ var head = document.querySelector( 'head' );
+ head.insertBefore( script, head.lastChild );
+
+ }
+
+ /**
* Starts up reveal.js by binding input events and navigating
* to the current URL deeplink if there is one.
*/
@@ -593,8 +680,7 @@
dom.speakerNotes.setAttribute( 'tabindex', '0' );
// Overlay graphic which is displayed during the paused mode
- dom.pauseOverlay = createSingletonNode( dom.wrapper, 'div', 'pause-overlay', '<button class="resume-button">Resume presentation</button>' );
- dom.resumeButton = dom.pauseOverlay.querySelector( '.resume-button' );
+ dom.pauseOverlay = createSingletonNode( dom.wrapper, 'div', 'pause-overlay', config.controls ? '<button class="resume-button">Resume presentation</button>' : null );
dom.wrapper.setAttribute( 'role', 'application' );
@@ -1074,18 +1160,27 @@
if( data.backgroundPosition ) contentElement.style.backgroundPosition = data.backgroundPosition;
if( data.backgroundOpacity ) contentElement.style.opacity = data.backgroundOpacity;
- // If this slide has a background color, add a class that
+ // If this slide has a background color, we add a class that
// signals if it is light or dark. If the slide has no background
- // color, no class will be set
- var computedBackgroundStyle = window.getComputedStyle( element );
- if( computedBackgroundStyle && computedBackgroundStyle.backgroundColor ) {
- var rgb = colorToRgb( computedBackgroundStyle.backgroundColor );
+ // color, no class will be added
+ var contrastColor = data.backgroundColor;
+
+ // If no bg color was found, check the computed background
+ if( !contrastColor ) {
+ var computedBackgroundStyle = window.getComputedStyle( element );
+ if( computedBackgroundStyle && computedBackgroundStyle.backgroundColor ) {
+ contrastColor = computedBackgroundStyle.backgroundColor;
+ }
+ }
+
+ if( contrastColor ) {
+ var rgb = colorToRgb( contrastColor );
// Ignore fully transparent backgrounds. Some browsers return
// rgba(0,0,0,0) when reading the computed background color of
// an element with no background
if( rgb && rgb.a !== 0 ) {
- if( colorBrightness( computedBackgroundStyle.backgroundColor ) < 128 ) {
+ if( colorBrightness( contrastColor ) < 128 ) {
slide.classList.add( 'has-dark-background' );
}
else {
@@ -1208,6 +1303,18 @@
disableRollingLinks();
}
+ // Auto-hide the mouse pointer when its inactive
+ if( config.hideInactiveCursor ) {
+ document.addEventListener( 'mousemove', onDocumentCursorActive, false );
+ document.addEventListener( 'mousedown', onDocumentCursorActive, false );
+ }
+ else {
+ showCursor();
+
+ document.removeEventListener( 'mousemove', onDocumentCursorActive, false );
+ document.removeEventListener( 'mousedown', onDocumentCursorActive, false );
+ }
+
// Iframe link previews
if( config.previewLinks ) {
enablePreviewLinks();
@@ -1255,6 +1362,14 @@
dom.slideNumber.style.display = slideNumberDisplay;
+ // Add the navigation mode to the DOM so we can adjust styling
+ if( config.navigationMode !== 'default' ) {
+ dom.wrapper.setAttribute( 'data-navigation-mode', config.navigationMode );
+ }
+ else {
+ dom.wrapper.removeAttribute( 'data-navigation-mode' );
+ }
+
sync();
}
@@ -1299,7 +1414,7 @@
dom.progress.addEventListener( 'click', onProgressClicked, false );
}
- dom.resumeButton.addEventListener( 'click', resume, false );
+ dom.pauseOverlay.addEventListener( 'click', resume, false );
if( config.focusBodyOnPageVisibilityChange ) {
var visibilityChange;
@@ -1364,7 +1479,7 @@
dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false );
dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false );
- dom.resumeButton.removeEventListener( 'click', resume, false );
+ dom.pauseOverlay.removeEventListener( 'click', resume, false );
if ( config.progress && dom.progress ) {
dom.progress.removeEventListener( 'click', onProgressClicked, false );
@@ -1669,11 +1784,19 @@
// Change the .stretch element height to 0 in order find the height of all
// the other elements
element.style.height = '0px';
+
+ // In Overview mode, the parent (.slide) height is set of 700px.
+ // Restore it temporarily to its natural height.
+ element.parentNode.style.height = 'auto';
+
newHeight = height - element.parentNode.offsetHeight;
// Restore the old height, just in case
element.style.height = oldHeight + 'px';
+ // Clear the parent (.slide) height. .removeProperty works in IE9+
+ element.parentNode.style.removeProperty('height');
+
return newHeight;
}
@@ -1962,6 +2085,16 @@
if( !config.disableLayout ) {
+ // On some mobile devices '100vh' is taller than the visible
+ // viewport which leads to part of the presentation being
+ // cut off. To work around this we define our own '--vh' custom
+ // property where 100x adds up to the correct height.
+ //
+ // https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
+ if( isMobileDevice ) {
+ document.documentElement.style.setProperty( '--vh', ( window.innerHeight * 0.01 ) + 'px' );
+ }
+
var size = getComputedSlideSize();
// Layout the contents of the slides
@@ -2435,6 +2568,32 @@
}
/**
+ * Shows the mouse pointer after it has been hidden with
+ * #hideCursor.
+ */
+ function showCursor() {
+
+ if( cursorHidden ) {
+ cursorHidden = false;
+ dom.wrapper.style.cursor = '';
+ }
+
+ }
+
+ /**
+ * Hides the mouse pointer when it's on top of the .reveal
+ * container.
+ */
+ function hideCursor() {
+
+ if( cursorHidden === false ) {
+ cursorHidden = true;
+ dom.wrapper.style.cursor = 'none';
+ }
+
+ }
+
+ /**
* Enters the paused mode which fades everything on screen to
* black.
*/
@@ -2576,28 +2735,6 @@
layout();
- // Apply the new state
- stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
- // Check if this state existed on the previous slide. If it
- // did, we will avoid adding it repeatedly
- for( var j = 0; j < stateBefore.length; j++ ) {
- if( stateBefore[j] === state[i] ) {
- stateBefore.splice( j, 1 );
- continue stateLoop;
- }
- }
-
- document.documentElement.classList.add( state[i] );
-
- // Dispatch custom event matching the state's name
- dispatchEvent( state[i] );
- }
-
- // Clean up the remains of the previous state
- while( stateBefore.length ) {
- document.documentElement.classList.remove( stateBefore.pop() );
- }
-
// Update the overview if it's currently active
if( isOverview() ) {
updateOverview();
@@ -2646,6 +2783,28 @@
}
}
+ // Apply the new state
+ stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
+ // Check if this state existed on the previous slide. If it
+ // did, we will avoid adding it repeatedly
+ for( var j = 0; j < stateBefore.length; j++ ) {
+ if( stateBefore[j] === state[i] ) {
+ stateBefore.splice( j, 1 );
+ continue stateLoop;
+ }
+ }
+
+ document.documentElement.classList.add( state[i] );
+
+ // Dispatch custom event matching the state's name
+ dispatchEvent( state[i] );
+ }
+
+ // Clean up the remains of the previous state
+ while( stateBefore.length ) {
+ document.documentElement.classList.remove( stateBefore.pop() );
+ }
+
if( slideChanged ) {
dispatchEvent( 'slidechanged', {
'indexh': indexh,
@@ -2671,6 +2830,7 @@
updateParallax();
updateSlideNumber();
updateNotes();
+ updateFragments();
// Update the URL hash
writeURL();
@@ -2895,14 +3055,11 @@
element.classList.add( reverse ? 'future' : 'past' );
if( config.fragments ) {
- var pastFragments = toArray( element.querySelectorAll( '.fragment' ) );
-
- // Show all fragments on prior slides
- while( pastFragments.length ) {
- var pastFragment = pastFragments.pop();
- pastFragment.classList.add( 'visible' );
- pastFragment.classList.remove( 'current-fragment' );
- }
+ // Show all fragments in prior slides
+ toArray( element.querySelectorAll( '.fragment' ) ).forEach( function( fragment ) {
+ fragment.classList.add( 'visible' );
+ fragment.classList.remove( 'current-fragment' );
+ } );
}
}
else if( i > index ) {
@@ -2910,14 +3067,11 @@
element.classList.add( reverse ? 'past' : 'future' );
if( config.fragments ) {
- var futureFragments = toArray( element.querySelectorAll( '.fragment.visible' ) );
-
- // No fragments in future slides should be visible ahead of time
- while( futureFragments.length ) {
- var futureFragment = futureFragments.pop();
- futureFragment.classList.remove( 'visible' );
- futureFragment.classList.remove( 'current-fragment' );
- }
+ // Hide all fragments in future slides
+ toArray( element.querySelectorAll( '.fragment.visible' ) ).forEach( function( fragment ) {
+ fragment.classList.remove( 'visible' );
+ fragment.classList.remove( 'current-fragment' );
+ } );
}
}
}
@@ -3655,13 +3809,6 @@
_appendParamToIframeSource( 'src', 'player.vimeo.com/', 'api=1' );
_appendParamToIframeSource( 'data-src', 'player.vimeo.com/', 'api=1' );
- // Always show media controls on mobile devices
- if( isMobileDevice ) {
- toArray( dom.slides.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
- el.controls = true;
- } );
- }
-
}
/**
@@ -3705,7 +3852,20 @@
// Mobile devices never fire a loaded event so instead
// of waiting, we initiate playback
else if( isMobileDevice ) {
- el.play();
+ var promise = el.play();
+
+ // If autoplay does not work, ensure that the controls are visible so
+ // that the viewer can start the media on their own
+ if( promise && typeof promise.catch === 'function' && el.controls === false ) {
+ promise.catch( function() {
+ el.controls = true;
+
+ // Once the video does start playing, hide the controls again
+ el.addEventListener( 'play', function() {
+ el.controls = false;
+ } );
+ } );
+ }
}
// If the media isn't loaded, wait before playing
else {
@@ -3980,10 +4140,13 @@
// Ensure that we're not already on a slide with the same name
var isSameNameAsCurrentSlide = currentSlide ? currentSlide.getAttribute( 'id' ) === name : false;
- if( element && !isSameNameAsCurrentSlide ) {
- // Find the position of the named slide and navigate to it
- var indices = Reveal.getIndices( element );
- slide( indices.h, indices.v );
+ if( element ) {
+ // If the slide exists and is not the current slide...
+ if ( !isSameNameAsCurrentSlide ) {
+ // ...find the position of the named slide and navigate to it
+ var indices = Reveal.getIndices(element);
+ slide(indices.h, indices.v);
+ }
}
// If the slide doesn't exist, navigate to the current slide
else {
@@ -4021,18 +4184,20 @@
*/
function writeURL( delay ) {
- if( config.history ) {
-
- // Make sure there's never more than one timeout running
- clearTimeout( writeURLTimeout );
+ // Make sure there's never more than one timeout running
+ clearTimeout( writeURLTimeout );
- // If a delay is specified, timeout this call
- if( typeof delay === 'number' ) {
- writeURLTimeout = setTimeout( writeURL, delay );
- }
- else if( currentSlide ) {
+ // If a delay is specified, timeout this call
+ if( typeof delay === 'number' ) {
+ writeURLTimeout = setTimeout( writeURL, delay );
+ }
+ else if( currentSlide ) {
+ if( config.history || !window.history ) {
window.location.hash = locationHash();
}
+ else if( config.hash ) {
+ window.history.replaceState(null, null, '#' + locationHash());
+ }
}
}
@@ -4100,6 +4265,25 @@
}
/**
+ * Returns an array of objects where each object represents the
+ * attributes on its respective slide.
+ */
+ function getSlidesAttributes() {
+
+ return getSlides().map( function( slide ) {
+
+ var attributes = {};
+ for( var i = 0; i < slide.attributes.length; i++ ) {
+ var attribute = slide.attributes[ i ];
+ attributes[ attribute.name ] = attribute.value;
+ }
+ return attributes;
+
+ } );
+
+ }
+
+ /**
* Retrieves the total number of slides in this presentation.
*
* @return {number}
@@ -4292,6 +4476,73 @@
}
/**
+ * Refreshes the fragments on the current slide so that they
+ * have the appropriate classes (.visible + .current-fragment).
+ *
+ * @param {number} [index] The index of the current fragment
+ * @param {array} [fragments] Array containing all fragments
+ * in the current slide
+ *
+ * @return {{shown: array, hidden: array}}
+ */
+ function updateFragments( index, fragments ) {
+
+ var changedFragments = {
+ shown: [],
+ hidden: []
+ };
+
+ if( currentSlide && config.fragments ) {
+
+ fragments = fragments || sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
+
+ if( fragments.length ) {
+
+ if( typeof index !== 'number' ) {
+ var currentFragment = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) ).pop();
+ if( currentFragment ) {
+ index = parseInt( currentFragment.getAttribute( 'data-fragment-index' ) || 0, 10 );
+ }
+ }
+
+ toArray( fragments ).forEach( function( el, i ) {
+
+ if( el.hasAttribute( 'data-fragment-index' ) ) {
+ i = parseInt( el.getAttribute( 'data-fragment-index' ), 10 );
+ }
+
+ // Visible fragments
+ if( i <= index ) {
+ if( !el.classList.contains( 'visible' ) ) changedFragments.shown.push( el );
+ el.classList.add( 'visible' );
+ el.classList.remove( 'current-fragment' );
+
+ // Announce the fragments one by one to the Screen Reader
+ dom.statusDiv.textContent = getStatusText( el );
+
+ if( i === index ) {
+ el.classList.add( 'current-fragment' );
+ startEmbeddedContent( el );
+ }
+ }
+ // Hidden fragments
+ else {
+ if( el.classList.contains( 'visible' ) ) changedFragments.hidden.push( el );
+ el.classList.remove( 'visible' );
+ el.classList.remove( 'current-fragment' );
+ }
+
+ } );
+
+ }
+
+ }
+
+ return changedFragments;
+
+ }
+
+ /**
* Navigate to the specified slide fragment.
*
* @param {?number} index The index of the fragment that
@@ -4326,53 +4577,24 @@
index += offset;
}
- var fragmentsShown = [],
- fragmentsHidden = [];
-
- toArray( fragments ).forEach( function( element, i ) {
-
- if( element.hasAttribute( 'data-fragment-index' ) ) {
- i = parseInt( element.getAttribute( 'data-fragment-index' ), 10 );
- }
-
- // Visible fragments
- if( i <= index ) {
- if( !element.classList.contains( 'visible' ) ) fragmentsShown.push( element );
- element.classList.add( 'visible' );
- element.classList.remove( 'current-fragment' );
-
- // Announce the fragments one by one to the Screen Reader
- dom.statusDiv.textContent = getStatusText( element );
+ var changedFragments = updateFragments( index, fragments );
- if( i === index ) {
- element.classList.add( 'current-fragment' );
- startEmbeddedContent( element );
- }
- }
- // Hidden fragments
- else {
- if( element.classList.contains( 'visible' ) ) fragmentsHidden.push( element );
- element.classList.remove( 'visible' );
- element.classList.remove( 'current-fragment' );
- }
-
- } );
-
- if( fragmentsHidden.length ) {
- dispatchEvent( 'fragmenthidden', { fragment: fragmentsHidden[0], fragments: fragmentsHidden } );
+ if( changedFragments.hidden.length ) {
+ dispatchEvent( 'fragmenthidden', { fragment: changedFragments.hidden[0], fragments: changedFragments.hidden } );
}
- if( fragmentsShown.length ) {
- dispatchEvent( 'fragmentshown', { fragment: fragmentsShown[0], fragments: fragmentsShown } );
+ if( changedFragments.shown.length ) {
+ dispatchEvent( 'fragmentshown', { fragment: changedFragments.shown[0], fragments: changedFragments.shown } );
}
updateControls();
updateProgress();
+
if( config.fragmentInURL ) {
writeURL();
}
- return !!( fragmentsShown.length || fragmentsHidden.length );
+ return !!( changedFragments.shown.length || changedFragments.hidden.length );
}
@@ -4519,12 +4741,12 @@
// Reverse for RTL
if( config.rtl ) {
if( ( isOverview() || nextFragment() === false ) && availableRoutes().left ) {
- slide( indexh + 1 );
+ slide( indexh + 1, config.navigationMode === 'grid' ? indexv : undefined );
}
}
// Normal navigation
else if( ( isOverview() || previousFragment() === false ) && availableRoutes().left ) {
- slide( indexh - 1 );
+ slide( indexh - 1, config.navigationMode === 'grid' ? indexv : undefined );
}
}
@@ -4536,12 +4758,12 @@
// Reverse for RTL
if( config.rtl ) {
if( ( isOverview() || previousFragment() === false ) && availableRoutes().right ) {
- slide( indexh - 1 );
+ slide( indexh - 1, config.navigationMode === 'grid' ? indexv : undefined );
}
}
// Normal navigation
else if( ( isOverview() || nextFragment() === false ) && availableRoutes().right ) {
- slide( indexh + 1 );
+ slide( indexh + 1, config.navigationMode === 'grid' ? indexv : undefined );
}
}
@@ -4668,6 +4890,22 @@
}
/**
+ * Called whenever there is mouse input at the document level
+ * to determine if the cursor is active or not.
+ *
+ * @param {object} event
+ */
+ function onDocumentCursorActive( event ) {
+
+ showCursor();
+
+ clearTimeout( cursorInactiveTimeout );
+
+ cursorInactiveTimeout = setTimeout( hideCursor, config.hideCursorTime );
+
+ }
+
+ /**
* Handler for the document level 'keypress' event.
*
* @param {object} event
@@ -4694,20 +4932,31 @@
return true;
}
+ // Shorthand
+ var keyCode = event.keyCode;
+
// Remember if auto-sliding was paused so we can toggle it
var autoSlideWasPaused = autoSlidePaused;
onUserInput( event );
- // Check if there's a focused element that could be using
- // the keyboard
+ // Is there a focused element that could be using the keyboard?
var activeElementIsCE = document.activeElement && document.activeElement.contentEditable !== 'inherit';
var activeElementIsInput = document.activeElement && document.activeElement.tagName && /input|textarea/i.test( document.activeElement.tagName );
var activeElementIsNotes = document.activeElement && document.activeElement.className && /speaker-notes/i.test( document.activeElement.className);
+ // Whitelist specific modified + keycode combinations
+ var prevSlideShortcut = event.shiftKey && event.keyCode === 32;
+ var firstSlideShortcut = ( event.metaKey || event.ctrlKey ) && keyCode === 37;
+ var lastSlideShortcut = ( event.metaKey || event.ctrlKey ) && keyCode === 39;
+
+ // Prevent all other events when a modifier is pressed
+ var unusedModifier = !prevSlideShortcut && !firstSlideShortcut && !lastSlideShortcut &&
+ ( event.shiftKey || event.altKey || event.ctrlKey || event.metaKey );
+
// Disregard the event if there's a focused element or a
// keyboard modifier key is present
- if( activeElementIsCE || activeElementIsInput || activeElementIsNotes || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
+ if( activeElementIsCE || activeElementIsInput || activeElementIsNotes || unusedModifier ) return;
// While paused only allow resume keyboard events; 'b', 'v', '.'
var resumeKeyCodes = [66,86,190,191];
@@ -4722,7 +4971,7 @@
}
}
- if( isPaused() && resumeKeyCodes.indexOf( event.keyCode ) === -1 ) {
+ if( isPaused() && resumeKeyCodes.indexOf( keyCode ) === -1 ) {
return false;
}
@@ -4734,7 +4983,7 @@
for( key in config.keyboard ) {
// Check if this binding matches the pressed key
- if( parseInt( key, 10 ) === event.keyCode ) {
+ if( parseInt( key, 10 ) === keyCode ) {
var value = config.keyboard[ key ];
@@ -4761,7 +5010,7 @@
for( key in registeredKeyBindings ) {
// Check if this binding matches the pressed key
- if( parseInt( key, 10 ) === event.keyCode ) {
+ if( parseInt( key, 10 ) === keyCode ) {
var action = registeredKeyBindings[ key ].callback;
@@ -4785,35 +5034,92 @@
// Assume true and try to prove false
triggered = true;
- switch( event.keyCode ) {
- // p, page up
- case 80: case 33: navigatePrev(); break;
- // n, page down
- case 78: case 34: navigateNext(); break;
- // h, left
- case 72: case 37: navigateLeft(); break;
- // l, right
- case 76: case 39: navigateRight(); break;
- // k, up
- case 75: case 38: navigateUp(); break;
- // j, down
- case 74: case 40: navigateDown(); break;
- // home
- case 36: slide( 0 ); break;
- // end
- case 35: slide( Number.MAX_VALUE ); break;
- // space
- case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
- // return
- case 13: isOverview() ? deactivateOverview() : triggered = false; break;
- // two-spot, semicolon, b, v, period, Logitech presenter tools "black screen" button
- case 58: case 59: case 66: case 86: case 190: case 191: togglePause(); break;
- // f
- case 70: enterFullscreen(); break;
- // a
- case 65: if ( config.autoSlideStoppable ) toggleAutoSlide( autoSlideWasPaused ); break;
- default:
- triggered = false;
+ // P, PAGE UP
+ if( keyCode === 80 || keyCode === 33 ) {
+ navigatePrev();
+ }
+ // N, PAGE DOWN
+ else if( keyCode === 78 || keyCode === 34 ) {
+ navigateNext();
+ }
+ // H, LEFT
+ else if( keyCode === 72 || keyCode === 37 ) {
+ if( firstSlideShortcut ) {
+ slide( 0 );
+ }
+ else if( !isOverview() && config.navigationMode === 'linear' ) {
+ navigatePrev();
+ }
+ else {
+ navigateLeft();
+ }
+ }
+ // L, RIGHT
+ else if( keyCode === 76 || keyCode === 39 ) {
+ if( lastSlideShortcut ) {
+ slide( Number.MAX_VALUE );
+ }
+ else if( !isOverview() && config.navigationMode === 'linear' ) {
+ navigateNext();
+ }
+ else {
+ navigateRight();
+ }
+ }
+ // K, UP
+ else if( keyCode === 75 || keyCode === 38 ) {
+ if( !isOverview() && config.navigationMode === 'linear' ) {
+ navigatePrev();
+ }
+ else {
+ navigateUp();
+ }
+ }
+ // J, DOWN
+ else if( keyCode === 74 || keyCode === 40 ) {
+ if( !isOverview() && config.navigationMode === 'linear' ) {
+ navigateNext();
+ }
+ else {
+ navigateDown();
+ }
+ }
+ // HOME
+ else if( keyCode === 36 ) {
+ slide( 0 );
+ }
+ // END
+ else if( keyCode === 35 ) {
+ slide( Number.MAX_VALUE );
+ }
+ // SPACE
+ else if( keyCode === 32 ) {
+ if( isOverview() ) {
+ deactivateOverview();
+ }
+ if( event.shiftKey ) {
+ navigatePrev();
+ }
+ else {
+ navigateNext();
+ }
+ }
+ // TWO-SPOT, SEMICOLON, B, V, PERIOD, LOGITECH PRESENTER TOOLS "BLACK SCREEN" BUTTON
+ else if( keyCode === 58 || keyCode === 59 || keyCode === 66 || keyCode === 86 || keyCode === 190 || keyCode === 191 ) {
+ togglePause();
+ }
+ // F
+ else if( keyCode === 70 ) {
+ enterFullscreen();
+ }
+ // A
+ else if( keyCode === 65 ) {
+ if ( config.autoSlideStoppable ) {
+ toggleAutoSlide( autoSlideWasPaused );
+ }
+ }
+ else {
+ triggered = false;
}
}
@@ -4824,7 +5130,7 @@
event.preventDefault && event.preventDefault();
}
// ESC or O key
- else if ( ( event.keyCode === 27 || event.keyCode === 79 ) && features.transforms3d ) {
+ else if ( ( keyCode === 27 || keyCode === 79 ) && features.transforms3d ) {
if( dom.overlay ) {
closeOverlay();
}
@@ -4855,18 +5161,6 @@
touch.startY = event.touches[0].clientY;
touch.startCount = event.touches.length;
- // If there's two touches we need to memorize the distance
- // between those two points to detect pinching
- if( event.touches.length === 2 && config.overview ) {
- touch.startSpan = distanceBetween( {
- x: event.touches[1].clientX,
- y: event.touches[1].clientY
- }, {
- x: touch.startX,
- y: touch.startY
- } );
- }
-
}
/**
@@ -4885,37 +5179,8 @@
var currentX = event.touches[0].clientX;
var currentY = event.touches[0].clientY;
- // If the touch started with two points and still has
- // two active touches; test for the pinch gesture
- if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
-
- // The current distance in pixels between the two touch points
- var currentSpan = distanceBetween( {
- x: event.touches[1].clientX,
- y: event.touches[1].clientY
- }, {
- x: touch.startX,
- y: touch.startY
- } );
-
- // If the span is larger than the desire amount we've got
- // ourselves a pinch
- if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
- touch.captured = true;
-
- if( currentSpan < touch.startSpan ) {
- activateOverview();
- }
- else {
- deactivateOverview();
- }
- }
-
- event.preventDefault();
-
- }
// There was only one touch point, look for a swipe
- else if( event.touches.length === 1 && touch.startCount !== 2 ) {
+ if( event.touches.length === 1 && touch.startCount !== 2 ) {
var deltaX = currentX - touch.startX,
deltaY = currentY - touch.startY;
@@ -5065,8 +5330,8 @@
/**
* Event handler for navigation control buttons.
*/
- function onNavigateLeftClicked( event ) { event.preventDefault(); onUserInput(); navigateLeft(); }
- function onNavigateRightClicked( event ) { event.preventDefault(); onUserInput(); navigateRight(); }
+ function onNavigateLeftClicked( event ) { event.preventDefault(); onUserInput(); config.navigationMode === 'linear' ? navigatePrev() : navigateLeft(); }
+ function onNavigateRightClicked( event ) { event.preventDefault(); onUserInput(); config.navigationMode === 'linear' ? navigateNext() : navigateRight(); }
function onNavigateUpClicked( event ) { event.preventDefault(); onUserInput(); navigateUp(); }
function onNavigateDownClicked( event ) { event.preventDefault(); onUserInput(); navigateDown(); }
function onNavigatePrevClicked( event ) { event.preventDefault(); onUserInput(); navigatePrev(); }
@@ -5455,6 +5720,10 @@
// Returns an Array of all slides
getSlides: getSlides,
+ // Returns an Array of objects representing the attributes on
+ // the slides
+ getSlidesAttributes: getSlidesAttributes,
+
// Returns the total number of slides
getTotalSlides: getTotalSlides,
@@ -5505,6 +5774,11 @@
return query;
},
+ // Returns the top-level DOM element
+ getRevealElement: function() {
+ return dom.wrapper || document.querySelector( '.reveal' );
+ },
+
// Returns true if we're currently on the first slide
isFirstSlide: function() {
return ( indexh === 0 && indexv === 0 );
@@ -5546,12 +5820,12 @@
// Forward event binding to the reveal DOM element
addEventListener: function( type, listener, useCapture ) {
if( 'addEventListener' in window ) {
- ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
+ Reveal.getRevealElement().addEventListener( type, listener, useCapture );
}
},
removeEventListener: function( type, listener, useCapture ) {
if( 'addEventListener' in window ) {
- ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
+ Reveal.getRevealElement().removeEventListener( type, listener, useCapture );
}
},