expose layout api method (closes #305), consistent spacing across all functions in core JS, remove unused each() method

This commit is contained in:
hakimel 2013-01-21 12:22:30 -05:00
parent 305e70d99b
commit 09bf962d32
2 changed files with 115 additions and 20 deletions

View file

@ -88,6 +88,7 @@ var Reveal = (function(){
'OPerspective' in document.body.style || 'OPerspective' in document.body.style ||
'perspective' in document.body.style, 'perspective' in document.body.style,
// Detect support for CSS 2D transforms
supports2DTransforms = 'WebkitTransform' in document.body.style || supports2DTransforms = 'WebkitTransform' in document.body.style ||
'MozTransform' in document.body.style || 'MozTransform' in document.body.style ||
'msTransform' in document.body.style || 'msTransform' in document.body.style ||
@ -123,6 +124,7 @@ var Reveal = (function(){
* Starts up the presentation if the client is capable. * Starts up the presentation if the client is capable.
*/ */
function initialize( options ) { function initialize( options ) {
if( ( !supports2DTransforms && !supports3DTransforms ) ) { if( ( !supports2DTransforms && !supports3DTransforms ) ) {
document.body.setAttribute( 'class', 'no-transforms' ); document.body.setAttribute( 'class', 'no-transforms' );
@ -151,6 +153,7 @@ var Reveal = (function(){
* not found, it is created. * not found, it is created.
*/ */
function setupDOM() { function setupDOM() {
// Cache references to key DOM elements // Cache references to key DOM elements
dom.theme = document.querySelector( '#theme' ); dom.theme = document.querySelector( '#theme' );
dom.wrapper = document.querySelector( '.reveal' ); dom.wrapper = document.querySelector( '.reveal' );
@ -204,12 +207,14 @@ var Reveal = (function(){
dom.controlsPrev = toArray( document.querySelectorAll( '.navigate-prev' ) ); dom.controlsPrev = toArray( document.querySelectorAll( '.navigate-prev' ) );
dom.controlsNext = toArray( document.querySelectorAll( '.navigate-next' ) ); dom.controlsNext = toArray( document.querySelectorAll( '.navigate-next' ) );
} }
} }
/** /**
* Hides the address bar if we're on a mobile device. * Hides the address bar if we're on a mobile device.
*/ */
function hideAddressBar() { function hideAddressBar() {
if( navigator.userAgent.match( /(iphone|ipod)/i ) ) { if( navigator.userAgent.match( /(iphone|ipod)/i ) ) {
// Give the page some scrollable overflow // Give the page some scrollable overflow
document.documentElement.style.overflow = 'scroll'; document.documentElement.style.overflow = 'scroll';
@ -219,6 +224,7 @@ var Reveal = (function(){
window.addEventListener( 'load', removeAddressBar, false ); window.addEventListener( 'load', removeAddressBar, false );
window.addEventListener( 'orientationchange', removeAddressBar, false ); window.addEventListener( 'orientationchange', removeAddressBar, false );
} }
} }
/** /**
@ -229,6 +235,7 @@ var Reveal = (function(){
* will load after reveal.js has been started up. * will load after reveal.js has been started up.
*/ */
function load() { function load() {
var scripts = [], var scripts = [],
scriptsAsync = []; scriptsAsync = [];
@ -270,6 +277,7 @@ var Reveal = (function(){
else { else {
proceed(); proceed();
} }
} }
/** /**
@ -277,6 +285,7 @@ var Reveal = (function(){
* to the current URL deeplink if there is one. * to the current URL deeplink if there is one.
*/ */
function start() { function start() {
// Make sure we've got all the DOM elements we need // Make sure we've got all the DOM elements we need
setupDOM(); setupDOM();
@ -305,12 +314,14 @@ var Reveal = (function(){
'currentSlide': currentSlide 'currentSlide': currentSlide
} ); } );
}, 1 ); }, 1 );
} }
/** /**
* Applies the configuration settings from the config object. * Applies the configuration settings from the config object.
*/ */
function configure() { function configure() {
if( supports3DTransforms === false ) { if( supports3DTransforms === false ) {
config.transition = 'linear'; config.transition = 'linear';
} }
@ -356,12 +367,14 @@ var Reveal = (function(){
dom.theme.setAttribute( 'href', themeURL ); dom.theme.setAttribute( 'href', themeURL );
} }
} }
} }
/** /**
* Binds all event listeners. * Binds all event listeners.
*/ */
function addEventListeners() { function addEventListeners() {
document.addEventListener( 'touchstart', onDocumentTouchStart, false ); document.addEventListener( 'touchstart', onDocumentTouchStart, false );
document.addEventListener( 'touchmove', onDocumentTouchMove, false ); document.addEventListener( 'touchmove', onDocumentTouchMove, false );
document.addEventListener( 'touchend', onDocumentTouchEnd, false ); document.addEventListener( 'touchend', onDocumentTouchEnd, false );
@ -385,12 +398,14 @@ var Reveal = (function(){
dom.controlsPrev.forEach( function( el ) { el.addEventListener( actionEvent, preventAndForward( navigatePrev ), false ); } ); dom.controlsPrev.forEach( function( el ) { el.addEventListener( actionEvent, preventAndForward( navigatePrev ), false ); } );
dom.controlsNext.forEach( function( el ) { el.addEventListener( actionEvent, preventAndForward( navigateNext ), false ); } ); dom.controlsNext.forEach( function( el ) { el.addEventListener( actionEvent, preventAndForward( navigateNext ), false ); } );
} }
} }
/** /**
* Unbinds all event listeners. * Unbinds all event listeners.
*/ */
function removeEventListeners() { function removeEventListeners() {
document.removeEventListener( 'keydown', onDocumentKeyDown, false ); document.removeEventListener( 'keydown', onDocumentKeyDown, false );
document.removeEventListener( 'touchstart', onDocumentTouchStart, false ); document.removeEventListener( 'touchstart', onDocumentTouchStart, false );
document.removeEventListener( 'touchmove', onDocumentTouchMove, false ); document.removeEventListener( 'touchmove', onDocumentTouchMove, false );
@ -411,6 +426,7 @@ var Reveal = (function(){
dom.controlsPrev.forEach( function( el ) { el.removeEventListener( actionEvent, preventAndForward( navigatePrev ), false ); } ); dom.controlsPrev.forEach( function( el ) { el.removeEventListener( actionEvent, preventAndForward( navigatePrev ), false ); } );
dom.controlsNext.forEach( function( el ) { el.removeEventListener( actionEvent, preventAndForward( navigateNext ), false ); } ); dom.controlsNext.forEach( function( el ) { el.removeEventListener( actionEvent, preventAndForward( navigateNext ), false ); } );
} }
} }
/** /**
@ -418,22 +434,20 @@ var Reveal = (function(){
* If there's a conflict, object b takes precedence. * If there's a conflict, object b takes precedence.
*/ */
function extend( a, b ) { function extend( a, b ) {
for( var i in b ) { for( var i in b ) {
a[ i ] = b[ i ]; a[ i ] = b[ i ];
} }
} }
/** /**
* Converts the target object to an array. * Converts the target object to an array.
*/ */
function toArray( o ) { function toArray( o ) {
return Array.prototype.slice.call( o );
}
function each( targets, method, args ) { return Array.prototype.slice.call( o );
targets.forEach( function( el ) {
el[method].apply( el, args );
} );
} }
/** /**
@ -444,10 +458,12 @@ var Reveal = (function(){
* @param {Object} b point with x/y properties * @param {Object} b point with x/y properties
*/ */
function distanceBetween( a, b ) { function distanceBetween( a, b ) {
var dx = a.x - b.x, var dx = a.x - b.x,
dy = a.y - b.y; dy = a.y - b.y;
return Math.sqrt( dx*dx + dy*dy ); return Math.sqrt( dx*dx + dy*dy );
} }
/** /**
@ -458,10 +474,12 @@ var Reveal = (function(){
* after the wrapper has been executed * after the wrapper has been executed
*/ */
function preventAndForward( delegate ) { function preventAndForward( delegate ) {
return function( event ) { return function( event ) {
event.preventDefault(); event.preventDefault();
delegate.call( null, event ); delegate.call( null, event );
}; };
} }
/** /**
@ -469,9 +487,11 @@ var Reveal = (function(){
* more vertical space ftw. * more vertical space ftw.
*/ */
function removeAddressBar() { function removeAddressBar() {
setTimeout( function() { setTimeout( function() {
window.scrollTo( 0, 1 ); window.scrollTo( 0, 1 );
}, 0 ); }, 0 );
} }
/** /**
@ -479,16 +499,19 @@ var Reveal = (function(){
* reveal DOM element. * reveal DOM element.
*/ */
function dispatchEvent( type, properties ) { function dispatchEvent( type, properties ) {
var event = document.createEvent( "HTMLEvents", 1, 2 ); var event = document.createEvent( "HTMLEvents", 1, 2 );
event.initEvent( type, true, true ); event.initEvent( type, true, true );
extend( event, properties ); extend( event, properties );
dom.wrapper.dispatchEvent( event ); dom.wrapper.dispatchEvent( event );
} }
/** /**
* Wrap all links in 3D goodness. * Wrap all links in 3D goodness.
*/ */
function linkify() { function linkify() {
if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) { if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) {
var nodes = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' ); var nodes = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
@ -506,6 +529,7 @@ var Reveal = (function(){
} }
} }
} }
} }
/** /**
@ -525,7 +549,7 @@ var Reveal = (function(){
for( var i = 0, len = slides.length; i < len; i++ ) { for( var i = 0, len = slides.length; i < len; i++ ) {
var slide = slides[ i ]; var slide = slides[ i ];
// Don't bother update invisible slides // Don't bother updating invisible slides
if( slide.style.display === 'none' ) { if( slide.style.display === 'none' ) {
continue; continue;
} }
@ -545,17 +569,19 @@ var Reveal = (function(){
} }
/** /**
* Stores the vertical index of a stack so that the same * Stores the vertical index of a stack so that the same
* vertical slide can be selected when navigating to and * vertical slide can be selected when navigating to and
* from the stack. * from the stack.
* *
* @param {HTMLElement} stack The vertical stack element * @param {HTMLElement} stack The vertical stack element
* @param {int} v Index to memorize * @param {int} v Index to memorize
*/ */
function setPreviousVerticalIndex( stack, v ) { function setPreviousVerticalIndex( stack, v ) {
if( stack ) { if( stack ) {
stack.setAttribute( 'data-previous-indexv', v || 0 ); stack.setAttribute( 'data-previous-indexv', v || 0 );
} }
} }
/** /**
@ -566,11 +592,13 @@ var Reveal = (function(){
* @param {HTMLElement} stack The vertical stack element * @param {HTMLElement} stack The vertical stack element
*/ */
function getPreviousVerticalIndex( stack ) { function getPreviousVerticalIndex( stack ) {
if( stack && stack.classList.contains( 'stack' ) ) { if( stack && stack.classList.contains( 'stack' ) ) {
return parseInt( stack.getAttribute( 'data-previous-indexv' ) || 0, 10 ); return parseInt( stack.getAttribute( 'data-previous-indexv' ) || 0, 10 );
} }
return 0; return 0;
} }
/** /**
@ -593,7 +621,7 @@ var Reveal = (function(){
// Not the pretties solution, but need to let the overview // Not the pretties solution, but need to let the overview
// class apply first so that slides are measured accurately // class apply first so that slides are measured accurately
// before we can positon them // before we can position them
activateOverviewTimeout = setTimeout( function(){ activateOverviewTimeout = setTimeout( function(){
var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ); var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
@ -704,12 +732,14 @@ var Reveal = (function(){
* overview is open, false means it's closed. * overview is open, false means it's closed.
*/ */
function toggleOverview( override ) { function toggleOverview( override ) {
if( typeof override === 'boolean' ) { if( typeof override === 'boolean' ) {
override ? activateOverview() : deactivateOverview(); override ? activateOverview() : deactivateOverview();
} }
else { else {
isOverviewActive() ? deactivateOverview() : activateOverview(); isOverviewActive() ? deactivateOverview() : activateOverview();
} }
} }
/** /**
@ -719,7 +749,9 @@ var Reveal = (function(){
* false otherwise * false otherwise
*/ */
function isOverviewActive() { function isOverviewActive() {
return dom.wrapper.classList.contains( 'overview' ); return dom.wrapper.classList.contains( 'overview' );
} }
/** /**
@ -729,6 +761,7 @@ var Reveal = (function(){
* @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
*/ */
function enterFullscreen() { function enterFullscreen() {
var element = document.body; var element = document.body;
// Check which implementation is available // Check which implementation is available
@ -740,6 +773,7 @@ var Reveal = (function(){
if( requestMethod ) { if( requestMethod ) {
requestMethod.apply( element ); requestMethod.apply( element );
} }
} }
/** /**
@ -747,33 +781,41 @@ var Reveal = (function(){
* black. * black.
*/ */
function pause() { function pause() {
dom.wrapper.classList.add( 'paused' ); dom.wrapper.classList.add( 'paused' );
} }
/** /**
* Exits from the paused mode. * Exits from the paused mode.
*/ */
function resume() { function resume() {
dom.wrapper.classList.remove( 'paused' ); dom.wrapper.classList.remove( 'paused' );
} }
/** /**
* Toggles the paused mode on and off. * Toggles the paused mode on and off.
*/ */
function togglePause() { function togglePause() {
if( isPaused() ) { if( isPaused() ) {
resume(); resume();
} }
else { else {
pause(); pause();
} }
} }
/** /**
* Checks if we are currently in the paused mode. * Checks if we are currently in the paused mode.
*/ */
function isPaused() { function isPaused() {
return dom.wrapper.classList.contains( 'paused' ); return dom.wrapper.classList.contains( 'paused' );
} }
/** /**
@ -783,23 +825,24 @@ var Reveal = (function(){
* *
* @param {int} h Horizontal index of the target slide * @param {int} h Horizontal index of the target slide
* @param {int} v Vertical index of the target slide * @param {int} v Vertical index of the target slide
* @param {int} f Optional index of a fragment within the * @param {int} f Optional index of a fragment within the
* target slide to activate * target slide to activate
*/ */
function slide( h, v, f ) { function slide( h, v, f ) {
// Remember where we were at before // Remember where we were at before
previousSlide = currentSlide; previousSlide = currentSlide;
// Query all horizontal slides in the deck // Query all horizontal slides in the deck
var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ); var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
// If no vertical index is specified and the upcoming slide is a // If no vertical index is specified and the upcoming slide is a
// stack, resume at its previous vertical index // stack, resume at its previous vertical index
if( v === undefined ) { if( v === undefined ) {
v = getPreviousVerticalIndex( horizontalSlides[ h ] ); v = getPreviousVerticalIndex( horizontalSlides[ h ] );
} }
// If we were on a vertical stack, remember what vertical index // If we were on a vertical stack, remember what vertical index
// it was on so we can resume at the same position when returning // it was on so we can resume at the same position when returning
if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) { if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
setPreviousVerticalIndex( previousSlide.parentNode, indexv ); setPreviousVerticalIndex( previousSlide.parentNode, indexv );
@ -837,7 +880,7 @@ var Reveal = (function(){
dispatchEvent( state[i] ); dispatchEvent( state[i] );
} }
// Clean up the remaints of the previous state // Clean up the remains of the previous state
while( stateBefore.length ) { while( stateBefore.length ) {
document.documentElement.classList.remove( stateBefore.pop() ); document.documentElement.classList.remove( stateBefore.pop() );
} }
@ -912,6 +955,7 @@ var Reveal = (function(){
updateControls(); updateControls();
updateProgress(); updateProgress();
} }
/** /**
@ -928,6 +972,7 @@ var Reveal = (function(){
* bounds. * bounds.
*/ */
function updateSlides( selector, index ) { function updateSlides( selector, index ) {
// Select all slides and convert the NodeList result to // Select all slides and convert the NodeList result to
// an array // an array
var slides = toArray( document.querySelectorAll( selector ) ), var slides = toArray( document.querySelectorAll( selector ) ),
@ -1014,6 +1059,7 @@ var Reveal = (function(){
* Updates the progress bar to reflect the current slide. * Updates the progress bar to reflect the current slide.
*/ */
function updateProgress() { function updateProgress() {
// Update progress if enabled // Update progress if enabled
if( config.progress && dom.progress ) { if( config.progress && dom.progress ) {
@ -1055,12 +1101,14 @@ var Reveal = (function(){
dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px'; dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px';
} }
} }
/** /**
* Updates the state of all control/navigation arrows. * Updates the state of all control/navigation arrows.
*/ */
function updateControls() { function updateControls() {
if ( config.controls && dom.controls ) { if ( config.controls && dom.controls ) {
var routes = availableRoutes(); var routes = availableRoutes();
@ -1085,6 +1133,7 @@ var Reveal = (function(){
if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } ); if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
} }
} }
/** /**
@ -1093,6 +1142,7 @@ var Reveal = (function(){
* @return {Object} containing four booleans: left/right/up/down * @return {Object} containing four booleans: left/right/up/down
*/ */
function availableRoutes() { function availableRoutes() {
var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ), var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR ); verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
@ -1102,12 +1152,14 @@ var Reveal = (function(){
up: indexv > 0, up: indexv > 0,
down: indexv < verticalSlides.length - 1 down: indexv < verticalSlides.length - 1
}; };
} }
/** /**
* Reads the current URL (hash) and navigates accordingly. * Reads the current URL (hash) and navigates accordingly.
*/ */
function readURL() { function readURL() {
var hash = window.location.hash; var hash = window.location.hash;
// Attempt to parse the hash as either an index or name // Attempt to parse the hash as either an index or name
@ -1137,16 +1189,18 @@ var Reveal = (function(){
slide( h, v ); slide( h, v );
} }
} }
/** /**
* Updates the page URL (hash) to reflect the current * Updates the page URL (hash) to reflect the current
* state. * state.
* *
* @param {Number} delay The time in ms to wait before * @param {Number} delay The time in ms to wait before
* writing the hash * writing the hash
*/ */
function writeURL( delay ) { function writeURL( delay ) {
if( config.history ) { if( config.history ) {
// Make sure there's never more than one timeout running // Make sure there's never more than one timeout running
@ -1172,6 +1226,7 @@ var Reveal = (function(){
window.location.hash = url; window.location.hash = url;
} }
} }
} }
/** /**
@ -1185,6 +1240,7 @@ var Reveal = (function(){
* @return {Object} { h: <int>, v: <int> } * @return {Object} { h: <int>, v: <int> }
*/ */
function getIndices( slide ) { function getIndices( slide ) {
// By default, return the current indices // By default, return the current indices
var h = indexh, var h = indexh,
v = indexv; v = indexv;
@ -1207,6 +1263,7 @@ var Reveal = (function(){
} }
return { h: h, v: v }; return { h: h, v: v };
} }
/** /**
@ -1216,6 +1273,7 @@ var Reveal = (function(){
* false otherwise * false otherwise
*/ */
function nextFragment() { function nextFragment() {
// Vertical slides: // Vertical slides:
if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) { if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' ); var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' );
@ -1240,6 +1298,7 @@ var Reveal = (function(){
} }
return false; return false;
} }
/** /**
@ -1249,6 +1308,7 @@ var Reveal = (function(){
* false otherwise * false otherwise
*/ */
function previousFragment() { function previousFragment() {
// Vertical slides: // Vertical slides:
if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) { if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment.visible' ); var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment.visible' );
@ -1273,46 +1333,57 @@ var Reveal = (function(){
} }
return false; return false;
} }
/** /**
* Cues a new automated slide if enabled in the config. * Cues a new automated slide if enabled in the config.
*/ */
function cueAutoSlide() { function cueAutoSlide() {
clearTimeout( autoSlideTimeout ); clearTimeout( autoSlideTimeout );
// Cue the next auto-slide if enabled // Cue the next auto-slide if enabled
if( autoSlide ) { if( autoSlide ) {
autoSlideTimeout = setTimeout( navigateNext, autoSlide ); autoSlideTimeout = setTimeout( navigateNext, autoSlide );
} }
} }
function navigateLeft() { function navigateLeft() {
// Prioritize hiding fragments // Prioritize hiding fragments
if( availableRoutes().left && isOverviewActive() || previousFragment() === false ) { if( availableRoutes().left && isOverviewActive() || previousFragment() === false ) {
slide( indexh - 1 ); slide( indexh - 1 );
} }
} }
function navigateRight() { function navigateRight() {
// Prioritize revealing fragments // Prioritize revealing fragments
if( availableRoutes().right && isOverviewActive() || nextFragment() === false ) { if( availableRoutes().right && isOverviewActive() || nextFragment() === false ) {
slide( indexh + 1 ); slide( indexh + 1 );
} }
} }
function navigateUp() { function navigateUp() {
// Prioritize hiding fragments // Prioritize hiding fragments
if( availableRoutes().up && isOverviewActive() || previousFragment() === false ) { if( availableRoutes().up && isOverviewActive() || previousFragment() === false ) {
slide( indexh, indexv - 1 ); slide( indexh, indexv - 1 );
} }
} }
function navigateDown() { function navigateDown() {
// Prioritize revealing fragments // Prioritize revealing fragments
if( availableRoutes().down && isOverviewActive() || nextFragment() === false ) { if( availableRoutes().down && isOverviewActive() || nextFragment() === false ) {
slide( indexh, indexv + 1 ); slide( indexh, indexv + 1 );
} }
} }
/** /**
@ -1322,6 +1393,7 @@ var Reveal = (function(){
* 3) Previous horizontal slide * 3) Previous horizontal slide
*/ */
function navigatePrev() { function navigatePrev() {
// Prioritize revealing fragments // Prioritize revealing fragments
if( previousFragment() === false ) { if( previousFragment() === false ) {
if( availableRoutes().up ) { if( availableRoutes().up ) {
@ -1338,12 +1410,14 @@ var Reveal = (function(){
} }
} }
} }
} }
/** /**
* Same as #navigatePrev() but navigates forwards. * Same as #navigatePrev() but navigates forwards.
*/ */
function navigateNext() { function navigateNext() {
// Prioritize revealing fragments // Prioritize revealing fragments
if( nextFragment() === false ) { if( nextFragment() === false ) {
availableRoutes().down ? navigateDown() : navigateRight(); availableRoutes().down ? navigateDown() : navigateRight();
@ -1352,6 +1426,7 @@ var Reveal = (function(){
// If auto-sliding is enabled we need to cue up // If auto-sliding is enabled we need to cue up
// another timeout // another timeout
cueAutoSlide(); cueAutoSlide();
} }
@ -1366,12 +1441,13 @@ var Reveal = (function(){
* @param {Object} event * @param {Object} event
*/ */
function onDocumentKeyDown( event ) { function onDocumentKeyDown( event ) {
// Check if there's a focused element that could be using
// Check if there's a focused element that could be using
// the keyboard // the keyboard
var activeElement = document.activeElement; var activeElement = document.activeElement;
var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) ); var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) );
// Disregard the event if there's a focused element or a // Disregard the event if there's a focused element or a
// keyboard modifier key is present // keyboard modifier key is present
if ( hasFocus || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey ) return; if ( hasFocus || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey ) return;
@ -1428,6 +1504,7 @@ var Reveal = (function(){
* enables support for swipe and pinch gestures. * enables support for swipe and pinch gestures.
*/ */
function onDocumentTouchStart( event ) { function onDocumentTouchStart( event ) {
touch.startX = event.touches[0].clientX; touch.startX = event.touches[0].clientX;
touch.startY = event.touches[0].clientY; touch.startY = event.touches[0].clientY;
touch.startCount = event.touches.length; touch.startCount = event.touches.length;
@ -1443,12 +1520,14 @@ var Reveal = (function(){
y: touch.startY y: touch.startY
} ); } );
} }
} }
/** /**
* Handler for the document level 'touchmove' event. * Handler for the document level 'touchmove' event.
*/ */
function onDocumentTouchMove( event ) { function onDocumentTouchMove( event ) {
// Each touch should only trigger one action // Each touch should only trigger one action
if( !touch.handled ) { if( !touch.handled ) {
var currentX = event.touches[0].clientX; var currentX = event.touches[0].clientX;
@ -1515,20 +1594,24 @@ var Reveal = (function(){
else if( navigator.userAgent.match( /android/gi ) ) { else if( navigator.userAgent.match( /android/gi ) ) {
event.preventDefault(); event.preventDefault();
} }
} }
/** /**
* Handler for the document level 'touchend' event. * Handler for the document level 'touchend' event.
*/ */
function onDocumentTouchEnd( event ) { function onDocumentTouchEnd( event ) {
touch.handled = false; touch.handled = false;
} }
/** /**
* Handles mouse wheel scrolling, throttled to avoid skipping * Handles mouse wheel scrolling, throttled to avoid skipping
* multiple slides. * multiple slides.
*/ */
function onDocumentMouseScroll( event ){ function onDocumentMouseScroll( event ) {
clearTimeout( mouseWheelTimeout ); clearTimeout( mouseWheelTimeout );
mouseWheelTimeout = setTimeout( function() { mouseWheelTimeout = setTimeout( function() {
@ -1540,6 +1623,7 @@ var Reveal = (function(){
navigatePrev(); navigatePrev();
} }
}, 100 ); }, 100 );
} }
/** /**
@ -1549,30 +1633,37 @@ var Reveal = (function(){
* ( clickX / presentationWidth ) * numberOfSlides * ( clickX / presentationWidth ) * numberOfSlides
*/ */
function onProgressClick( event ) { function onProgressClick( event ) {
var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length; var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal ); var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
slide( slideIndex ); slide( slideIndex );
} }
/** /**
* Handler for the window level 'hashchange' event. * Handler for the window level 'hashchange' event.
*/ */
function onWindowHashChange( event ) { function onWindowHashChange( event ) {
readURL(); readURL();
} }
/** /**
* Handler for the window level 'resize' event. * Handler for the window level 'resize' event.
*/ */
function onWindowResize( event ) { function onWindowResize( event ) {
layout(); layout();
} }
/** /**
* Invoked when a slide is and we're in the overview. * Invoked when a slide is and we're in the overview.
*/ */
function onOverviewSlideClicked( event ) { function onOverviewSlideClicked( event ) {
// TODO There's a bug here where the event listeners are not // TODO There's a bug here where the event listeners are not
// removed after deactivating the overview. // removed after deactivating the overview.
if( isOverviewActive() ) { if( isOverviewActive() ) {
@ -1593,6 +1684,7 @@ var Reveal = (function(){
slide( h, v ); slide( h, v );
} }
} }
} }
@ -1624,6 +1716,9 @@ var Reveal = (function(){
navigatePrev: navigatePrev, navigatePrev: navigatePrev,
navigateNext: navigateNext, navigateNext: navigateNext,
// Forces an update in slide layout
layout: layout,
// Toggles the overview mode on/off // Toggles the overview mode on/off
toggleOverview: toggleOverview, toggleOverview: toggleOverview,

2
js/reveal.min.js vendored

File diff suppressed because one or more lines are too long