reveal.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  1. /*!
  2. * reveal.js 2.2 r40
  3. * http://lab.hakim.se/reveal-js
  4. * MIT licensed
  5. *
  6. * Copyright (C) 2011-2012 Hakim El Hattab, http://hakim.se
  7. */
  8. var Reveal = (function(){
  9. 'use strict';
  10. var SLIDES_SELECTOR = '.reveal .slides section',
  11. HORIZONTAL_SLIDES_SELECTOR = '.reveal .slides>section',
  12. VERTICAL_SLIDES_SELECTOR = '.reveal .slides>section.present>section',
  13. // Configurations defaults, can be overridden at initialization time
  14. config = {
  15. // Display controls in the bottom right corner
  16. controls: true,
  17. // Display a presentation progress bar
  18. progress: true,
  19. // Push each slide change to the browser history
  20. history: false,
  21. // Enable keyboard shortcuts for navigation
  22. keyboard: true,
  23. // Enable the slide overview mode
  24. overview: true,
  25. // Vertical centering of slides
  26. center: false,
  27. // Loop the presentation
  28. loop: false,
  29. // Number of milliseconds between automatically proceeding to the
  30. // next slide, disabled when set to 0, this value can be overwritten
  31. // by using a data-autoslide attribute on your slides
  32. autoSlide: 0,
  33. // Enable slide navigation via mouse wheel
  34. mouseWheel: true,
  35. // Apply a 3D roll to links on hover
  36. rollingLinks: true,
  37. // Transition style (see /css/theme)
  38. theme: null,
  39. // Transition style
  40. transition: 'default', // default/cube/page/concave/zoom/linear/none
  41. // Script dependencies to load
  42. dependencies: []
  43. },
  44. // Stores if the next slide should be shown automatically
  45. // after n milliseconds
  46. autoSlide = config.autoSlide,
  47. // The horizontal and verical index of the currently active slide
  48. indexh = 0,
  49. indexv = 0,
  50. // The previous and current slide HTML elements
  51. previousSlide,
  52. currentSlide,
  53. // Slides may hold a data-state attribute which we pick up and apply
  54. // as a class to the body. This list contains the combined state of
  55. // all current slides.
  56. state = [],
  57. // Cached references to DOM elements
  58. dom = {},
  59. // Detect support for CSS 3D transforms
  60. supports3DTransforms = 'WebkitPerspective' in document.body.style ||
  61. 'MozPerspective' in document.body.style ||
  62. 'msPerspective' in document.body.style ||
  63. 'OPerspective' in document.body.style ||
  64. 'perspective' in document.body.style,
  65. supports2DTransforms = 'WebkitTransform' in document.body.style ||
  66. 'MozTransform' in document.body.style ||
  67. 'msTransform' in document.body.style ||
  68. 'OTransform' in document.body.style ||
  69. 'transform' in document.body.style,
  70. // Throttles mouse wheel navigation
  71. mouseWheelTimeout = 0,
  72. // An interval used to automatically move on to the next slide
  73. autoSlideTimeout = 0,
  74. // Delays updates to the URL due to a Chrome thumbnailer bug
  75. writeURLTimeout = 0,
  76. // Holds information about the currently ongoing touch input
  77. touch = {
  78. startX: 0,
  79. startY: 0,
  80. startSpan: 0,
  81. startCount: 0,
  82. handled: false,
  83. threshold: 80
  84. };
  85. /**
  86. * Starts up the presentation if the client is capable.
  87. */
  88. function initialize( options ) {
  89. if( ( !supports2DTransforms && !supports3DTransforms ) ) {
  90. document.body.setAttribute( 'class', 'no-transforms' );
  91. // If the browser doesn't support core features we won't be
  92. // using JavaScript to control the presentation
  93. return;
  94. }
  95. // Copy options over to our config object
  96. extend( config, options );
  97. // Hide the address bar in mobile browsers
  98. hideAddressBar();
  99. // Loads the dependencies and continues to #start() once done
  100. load();
  101. }
  102. /**
  103. * Finds and stores references to DOM elements which are
  104. * required by the presentation. If a required element is
  105. * not found, it is created.
  106. */
  107. function setupDOM() {
  108. // Cache references to key DOM elements
  109. dom.theme = document.querySelector( '#theme' );
  110. dom.wrapper = document.querySelector( '.reveal' );
  111. // Progress bar
  112. if( !dom.wrapper.querySelector( '.progress' ) && config.progress ) {
  113. var progressElement = document.createElement( 'div' );
  114. progressElement.classList.add( 'progress' );
  115. progressElement.innerHTML = '<span></span>';
  116. dom.wrapper.appendChild( progressElement );
  117. }
  118. // Arrow controls
  119. if( !dom.wrapper.querySelector( '.controls' ) && config.controls ) {
  120. var controlsElement = document.createElement( 'aside' );
  121. controlsElement.classList.add( 'controls' );
  122. controlsElement.innerHTML = '<div class="navigate-left"></div>' +
  123. '<div class="navigate-right"></div>' +
  124. '<div class="navigate-up"></div>' +
  125. '<div class="navigate-down"></div>';
  126. dom.wrapper.appendChild( controlsElement );
  127. }
  128. // Presentation background element
  129. if( !dom.wrapper.querySelector( '.state-background' ) ) {
  130. var backgroundElement = document.createElement( 'div' );
  131. backgroundElement.classList.add( 'state-background' );
  132. dom.wrapper.appendChild( backgroundElement );
  133. }
  134. // Overlay graphic which is displayed during the paused mode
  135. if( !dom.wrapper.querySelector( '.pause-overlay' ) ) {
  136. var pausedElement = document.createElement( 'div' );
  137. pausedElement.classList.add( 'pause-overlay' );
  138. dom.wrapper.appendChild( pausedElement );
  139. }
  140. // Cache references to elements
  141. dom.progress = document.querySelector( '.reveal .progress' );
  142. dom.progressbar = document.querySelector( '.reveal .progress span' );
  143. if ( config.controls ) {
  144. dom.controls = document.querySelector( '.reveal .controls' );
  145. // There can be multiple instances of controls throughout the page
  146. dom.controlsLeft = toArray( document.querySelectorAll( '.navigate-left' ) );
  147. dom.controlsRight = toArray( document.querySelectorAll( '.navigate-right' ) );
  148. dom.controlsUp = toArray( document.querySelectorAll( '.navigate-up' ) );
  149. dom.controlsDown = toArray( document.querySelectorAll( '.navigate-down' ) );
  150. dom.controlsPrev = toArray( document.querySelectorAll( '.navigate-prev' ) );
  151. dom.controlsNext = toArray( document.querySelectorAll( '.navigate-next' ) );
  152. }
  153. }
  154. /**
  155. * Hides the address bar if we're on a mobile device.
  156. */
  157. function hideAddressBar() {
  158. if( navigator.userAgent.match( /(iphone|ipod|android)/i ) ) {
  159. // Give the page some scrollable overflow
  160. document.documentElement.style.overflow = 'scroll';
  161. document.body.style.height = '120%';
  162. // Events that should trigger the address bar to hide
  163. window.addEventListener( 'load', removeAddressBar, false );
  164. window.addEventListener( 'orientationchange', removeAddressBar, false );
  165. }
  166. }
  167. /**
  168. * Loads the dependencies of reveal.js. Dependencies are
  169. * defined via the configuration option 'dependencies'
  170. * and will be loaded prior to starting/binding reveal.js.
  171. * Some dependencies may have an 'async' flag, if so they
  172. * will load after reveal.js has been started up.
  173. */
  174. function load() {
  175. var scripts = [],
  176. scriptsAsync = [];
  177. for( var i = 0, len = config.dependencies.length; i < len; i++ ) {
  178. var s = config.dependencies[i];
  179. // Load if there's no condition or the condition is truthy
  180. if( !s.condition || s.condition() ) {
  181. if( s.async ) {
  182. scriptsAsync.push( s.src );
  183. }
  184. else {
  185. scripts.push( s.src );
  186. }
  187. // Extension may contain callback functions
  188. if( typeof s.callback === 'function' ) {
  189. head.ready( s.src.match( /([\w\d_\-]*)\.?[^\\\/]*$/i )[0], s.callback );
  190. }
  191. }
  192. }
  193. // Called once synchronous scritps finish loading
  194. function proceed() {
  195. if( scriptsAsync.length ) {
  196. // Load asynchronous scripts
  197. head.js.apply( null, scriptsAsync );
  198. }
  199. start();
  200. }
  201. if( scripts.length ) {
  202. head.ready( proceed );
  203. // Load synchronous scripts
  204. head.js.apply( null, scripts );
  205. }
  206. else {
  207. proceed();
  208. }
  209. }
  210. /**
  211. * Starts up reveal.js by binding input events and navigating
  212. * to the current URL deeplink if there is one.
  213. */
  214. function start() {
  215. // Make sure we've got all the DOM elements we need
  216. setupDOM();
  217. // Subscribe to input
  218. addEventListeners();
  219. // Updates the presentation to match the current configuration values
  220. configure();
  221. // Force an initial layout, will thereafter be invoked as the window
  222. // is resized
  223. layout();
  224. // Read the initial hash
  225. readURL();
  226. // Start auto-sliding if it's enabled
  227. cueAutoSlide();
  228. // Notify listeners that the presentation is ready but use a 1ms
  229. // timeout to ensure it's not fired synchronously after #initialize()
  230. setTimeout( function() {
  231. dispatchEvent( 'ready', {
  232. 'indexh': indexh,
  233. 'indexv': indexv,
  234. 'currentSlide': currentSlide
  235. } );
  236. }, 1 );
  237. }
  238. /**
  239. * Applies the configuration settings from the config object.
  240. */
  241. function configure() {
  242. if( supports3DTransforms === false ) {
  243. config.transition = 'linear';
  244. }
  245. if( config.controls && dom.controls ) {
  246. dom.controls.style.display = 'block';
  247. }
  248. if( config.progress && dom.progress ) {
  249. dom.progress.style.display = 'block';
  250. }
  251. if( config.transition !== 'default' ) {
  252. dom.wrapper.classList.add( config.transition );
  253. }
  254. if( config.center ) {
  255. dom.wrapper.classList.add( 'center' );
  256. }
  257. if( config.mouseWheel ) {
  258. document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  259. document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
  260. }
  261. // 3D links
  262. if( config.rollingLinks ) {
  263. linkify();
  264. }
  265. // Load the theme in the config, if it's not already loaded
  266. if( config.theme && dom.theme ) {
  267. var themeURL = dom.theme.getAttribute( 'href' );
  268. var themeFinder = /[^\/]*?(?=\.css)/;
  269. var themeName = themeURL.match(themeFinder)[0];
  270. if( config.theme !== themeName ) {
  271. themeURL = themeURL.replace(themeFinder, config.theme);
  272. dom.theme.setAttribute( 'href', themeURL );
  273. }
  274. }
  275. }
  276. /**
  277. * Binds all event listeners.
  278. */
  279. function addEventListeners() {
  280. document.addEventListener( 'touchstart', onDocumentTouchStart, false );
  281. document.addEventListener( 'touchmove', onDocumentTouchMove, false );
  282. document.addEventListener( 'touchend', onDocumentTouchEnd, false );
  283. window.addEventListener( 'hashchange', onWindowHashChange, false );
  284. window.addEventListener( 'resize', onWindowResize, false );
  285. if( config.keyboard ) {
  286. document.addEventListener( 'keydown', onDocumentKeyDown, false );
  287. }
  288. if ( config.progress && dom.progress ) {
  289. dom.progress.addEventListener( 'click', preventAndForward( onProgressClick ), false );
  290. }
  291. if ( config.controls && dom.controls ) {
  292. dom.controlsLeft.forEach( function( el ) { el.addEventListener( 'click', preventAndForward( navigateLeft ), false ); } );
  293. dom.controlsRight.forEach( function( el ) { el.addEventListener( 'click', preventAndForward( navigateRight ), false ); } );
  294. dom.controlsUp.forEach( function( el ) { el.addEventListener( 'click', preventAndForward( navigateUp ), false ); } );
  295. dom.controlsDown.forEach( function( el ) { el.addEventListener( 'click', preventAndForward( navigateDown ), false ); } );
  296. dom.controlsPrev.forEach( function( el ) { el.addEventListener( 'click', preventAndForward( navigatePrev ), false ); } );
  297. dom.controlsNext.forEach( function( el ) { el.addEventListener( 'click', preventAndForward( navigateNext ), false ); } );
  298. }
  299. }
  300. /**
  301. * Unbinds all event listeners.
  302. */
  303. function removeEventListeners() {
  304. document.removeEventListener( 'keydown', onDocumentKeyDown, false );
  305. document.removeEventListener( 'touchstart', onDocumentTouchStart, false );
  306. document.removeEventListener( 'touchmove', onDocumentTouchMove, false );
  307. document.removeEventListener( 'touchend', onDocumentTouchEnd, false );
  308. window.removeEventListener( 'hashchange', onWindowHashChange, false );
  309. window.removeEventListener( 'resize', onWindowResize, false );
  310. if ( config.progress && dom.progress ) {
  311. dom.progress.removeEventListener( 'click', preventAndForward( onProgressClick ), false );
  312. }
  313. if ( config.controls && dom.controls ) {
  314. dom.controlsLeft.forEach( function( el ) { el.removeEventListener( 'click', preventAndForward( navigateLeft ), false ); } );
  315. dom.controlsRight.forEach( function( el ) { el.removeEventListener( 'click', preventAndForward( navigateRight ), false ); } );
  316. dom.controlsUp.forEach( function( el ) { el.removeEventListener( 'click', preventAndForward( navigateUp ), false ); } );
  317. dom.controlsDown.forEach( function( el ) { el.removeEventListener( 'click', preventAndForward( navigateDown ), false ); } );
  318. dom.controlsPrev.forEach( function( el ) { el.removeEventListener( 'click', preventAndForward( navigatePrev ), false ); } );
  319. dom.controlsNext.forEach( function( el ) { el.removeEventListener( 'click', preventAndForward( navigateNext ), false ); } );
  320. }
  321. }
  322. /**
  323. * Extend object a with the properties of object b.
  324. * If there's a conflict, object b takes precedence.
  325. */
  326. function extend( a, b ) {
  327. for( var i in b ) {
  328. a[ i ] = b[ i ];
  329. }
  330. }
  331. /**
  332. * Converts the target object to an array.
  333. */
  334. function toArray( o ) {
  335. return Array.prototype.slice.call( o );
  336. }
  337. function each( targets, method, args ) {
  338. targets.forEach( function( el ) {
  339. el[method].apply( el, args );
  340. } );
  341. }
  342. /**
  343. * Measures the distance in pixels between point a
  344. * and point b.
  345. *
  346. * @param {Object} a point with x/y properties
  347. * @param {Object} b point with x/y properties
  348. */
  349. function distanceBetween( a, b ) {
  350. var dx = a.x - b.x,
  351. dy = a.y - b.y;
  352. return Math.sqrt( dx*dx + dy*dy );
  353. }
  354. /**
  355. * Prevents an events defaults behavior calls the
  356. * specified delegate.
  357. *
  358. * @param {Function} delegate The method to call
  359. * after the wrapper has been executed
  360. */
  361. function preventAndForward( delegate ) {
  362. return function( event ) {
  363. event.preventDefault();
  364. delegate.call( null, event );
  365. };
  366. }
  367. /**
  368. * Causes the address bar to hide on mobile devices,
  369. * more vertical space ftw.
  370. */
  371. function removeAddressBar() {
  372. setTimeout( function() {
  373. window.scrollTo( 0, 1 );
  374. }, 0 );
  375. }
  376. /**
  377. * Dispatches an event of the specified type from the
  378. * reveal DOM element.
  379. */
  380. function dispatchEvent( type, properties ) {
  381. var event = document.createEvent( "HTMLEvents", 1, 2 );
  382. event.initEvent( type, true, true );
  383. extend( event, properties );
  384. dom.wrapper.dispatchEvent( event );
  385. }
  386. /**
  387. * Wrap all links in 3D goodness.
  388. */
  389. function linkify() {
  390. if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) {
  391. var nodes = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
  392. for( var i = 0, len = nodes.length; i < len; i++ ) {
  393. var node = nodes[i];
  394. if( node.textContent && !node.querySelector( 'img' ) && ( !node.className || !node.classList.contains( node, 'roll' ) ) ) {
  395. node.classList.add( 'roll' );
  396. node.innerHTML = '<span data-title="'+ node.text +'">' + node.innerHTML + '</span>';
  397. }
  398. }
  399. }
  400. }
  401. /**
  402. * Applies JavaScript-controlled layout rules to the
  403. * presentation.
  404. */
  405. function layout() {
  406. if( config.center ) {
  407. // Select all slides, vertical and horizontal
  408. var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
  409. // Determine the minimum top offset for slides
  410. var minTop = -dom.wrapper.offsetHeight / 2;
  411. for( var i = 0, len = slides.length; i < len; i++ ) {
  412. var slide = slides[ i ];
  413. // Vertical stacks are not centered since their section
  414. // children will be
  415. if( slide.classList.contains( 'stack' ) ) {
  416. slide.style.top = 0;
  417. }
  418. else {
  419. slide.style.top = Math.max( - ( slide.offsetHeight / 2 ) - 20, minTop ) + 'px';
  420. }
  421. }
  422. }
  423. }
  424. /**
  425. * Displays the overview of slides (quick nav) by
  426. * scaling down and arranging all slide elements.
  427. *
  428. * Experimental feature, might be dropped if perf
  429. * can't be improved.
  430. */
  431. function activateOverview() {
  432. // Only proceed if enabled in config
  433. if( config.overview ) {
  434. dom.wrapper.classList.add( 'overview' );
  435. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  436. for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
  437. var hslide = horizontalSlides[i],
  438. htransform = 'translateZ(-2500px) translate(' + ( ( i - indexh ) * 105 ) + '%, 0%)';
  439. hslide.setAttribute( 'data-index-h', i );
  440. hslide.style.display = 'block';
  441. hslide.style.WebkitTransform = htransform;
  442. hslide.style.MozTransform = htransform;
  443. hslide.style.msTransform = htransform;
  444. hslide.style.OTransform = htransform;
  445. hslide.style.transform = htransform;
  446. if( !hslide.classList.contains( 'stack' ) ) {
  447. // Navigate to this slide on click
  448. hslide.addEventListener( 'click', onOverviewSlideClicked, true );
  449. }
  450. var verticalSlides = hslide.querySelectorAll( 'section' );
  451. for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
  452. var vslide = verticalSlides[j],
  453. vtransform = 'translate(0%, ' + ( ( j - ( i === indexh ? indexv : 0 ) ) * 105 ) + '%)';
  454. vslide.setAttribute( 'data-index-h', i );
  455. vslide.setAttribute( 'data-index-v', j );
  456. vslide.style.display = 'block';
  457. vslide.style.WebkitTransform = vtransform;
  458. vslide.style.MozTransform = vtransform;
  459. vslide.style.msTransform = vtransform;
  460. vslide.style.OTransform = vtransform;
  461. vslide.style.transform = vtransform;
  462. // Navigate to this slide on click
  463. vslide.addEventListener( 'click', onOverviewSlideClicked, true );
  464. }
  465. }
  466. }
  467. }
  468. /**
  469. * Exits the slide overview and enters the currently
  470. * active slide.
  471. */
  472. function deactivateOverview() {
  473. // Only proceed if enabled in config
  474. if( config.overview ) {
  475. dom.wrapper.classList.remove( 'overview' );
  476. // Select all slides
  477. var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
  478. for( var i = 0, len = slides.length; i < len; i++ ) {
  479. var element = slides[i];
  480. // Resets all transforms to use the external styles
  481. element.style.WebkitTransform = '';
  482. element.style.MozTransform = '';
  483. element.style.msTransform = '';
  484. element.style.OTransform = '';
  485. element.style.transform = '';
  486. element.removeEventListener( 'click', onOverviewSlideClicked );
  487. }
  488. slide();
  489. }
  490. }
  491. /**
  492. * Toggles the slide overview mode on and off.
  493. *
  494. * @param {Boolean} override Optional flag which overrides the
  495. * toggle logic and forcibly sets the desired state. True means
  496. * overview is open, false means it's closed.
  497. */
  498. function toggleOverview( override ) {
  499. if( typeof override === 'boolean' ) {
  500. override ? activateOverview() : deactivateOverview();
  501. }
  502. else {
  503. isOverviewActive() ? deactivateOverview() : activateOverview();
  504. }
  505. }
  506. /**
  507. * Checks if the overview is currently active.
  508. *
  509. * @return {Boolean} true if the overview is active,
  510. * false otherwise
  511. */
  512. function isOverviewActive() {
  513. return dom.wrapper.classList.contains( 'overview' );
  514. }
  515. /**
  516. * Handling the fullscreen functionality via the fullscreen API
  517. *
  518. * @see http://fullscreen.spec.whatwg.org/
  519. * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
  520. */
  521. function enterFullscreen() {
  522. var element = document.body;
  523. // Check which implementation is available
  524. var requestMethod = element.requestFullScreen ||
  525. element.webkitRequestFullScreen ||
  526. element.mozRequestFullScreen ||
  527. element.msRequestFullScreen;
  528. if( requestMethod ) {
  529. requestMethod.apply( element );
  530. }
  531. }
  532. /**
  533. * Enters the paused mode which fades everything on screen to
  534. * black.
  535. */
  536. function pause() {
  537. dom.wrapper.classList.add( 'paused' );
  538. }
  539. /**
  540. * Exits from the paused mode.
  541. */
  542. function resume() {
  543. dom.wrapper.classList.remove( 'paused' );
  544. }
  545. /**
  546. * Toggles the paused mode on and off.
  547. */
  548. function togglePause() {
  549. if( isPaused() ) {
  550. resume();
  551. }
  552. else {
  553. pause();
  554. }
  555. }
  556. /**
  557. * Checks if we are currently in the paused mode.
  558. */
  559. function isPaused() {
  560. return dom.wrapper.classList.contains( 'paused' );
  561. }
  562. /**
  563. * Steps from the current point in the presentation to the
  564. * slide which matches the specified horizontal and vertical
  565. * indices.
  566. *
  567. * @param {int} h Horizontal index of the target slide
  568. * @param {int} v Vertical index of the target slide
  569. */
  570. function slide( h, v ) {
  571. // Remember where we were at before
  572. previousSlide = currentSlide;
  573. // Remember the state before this slide
  574. var stateBefore = state.concat();
  575. // Reset the state array
  576. state.length = 0;
  577. var indexhBefore = indexh,
  578. indexvBefore = indexv;
  579. // Activate and transition to the new slide
  580. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
  581. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
  582. layout();
  583. // Apply the new state
  584. stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
  585. // Check if this state existed on the previous slide. If it
  586. // did, we will avoid adding it repeatedly.
  587. for( var j = 0; j < stateBefore.length; j++ ) {
  588. if( stateBefore[j] === state[i] ) {
  589. stateBefore.splice( j, 1 );
  590. continue stateLoop;
  591. }
  592. }
  593. document.documentElement.classList.add( state[i] );
  594. // Dispatch custom event matching the state's name
  595. dispatchEvent( state[i] );
  596. }
  597. // Clean up the remaints of the previous state
  598. while( stateBefore.length ) {
  599. document.documentElement.classList.remove( stateBefore.pop() );
  600. }
  601. // If the overview is active, re-activate it to update positions
  602. if( isOverviewActive() ) {
  603. activateOverview();
  604. }
  605. // Update the URL hash after a delay since updating it mid-transition
  606. // is likely to cause visual lag
  607. clearTimeout( writeURLTimeout );
  608. writeURLTimeout = setTimeout( writeURL, 1500 );
  609. // Query all horizontal slides in the deck
  610. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  611. // Find the current horizontal slide and any possible vertical slides
  612. // within it
  613. var currentHorizontalSlide = horizontalSlides[ indexh ],
  614. currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
  615. // Store references to the previous and current slides
  616. currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
  617. // Dispatch an event if the slide changed
  618. if( indexh !== indexhBefore || indexv !== indexvBefore ) {
  619. dispatchEvent( 'slidechanged', {
  620. 'indexh': indexh,
  621. 'indexv': indexv,
  622. 'previousSlide': previousSlide,
  623. 'currentSlide': currentSlide
  624. } );
  625. }
  626. else {
  627. // Ensure that the previous slide is never the same as the current
  628. previousSlide = null;
  629. }
  630. // Solves an edge case where the previous slide maintains the
  631. // 'present' class when navigating between adjacent vertical
  632. // stacks
  633. if( previousSlide ) {
  634. previousSlide.classList.remove( 'present' );
  635. }
  636. updateControls();
  637. updateProgress();
  638. }
  639. /**
  640. * Updates one dimension of slides by showing the slide
  641. * with the specified index.
  642. *
  643. * @param {String} selector A CSS selector that will fetch
  644. * the group of slides we are working with
  645. * @param {Number} index The index of the slide that should be
  646. * shown
  647. *
  648. * @return {Number} The index of the slide that is now shown,
  649. * might differ from the passed in index if it was out of
  650. * bounds.
  651. */
  652. function updateSlides( selector, index ) {
  653. // Select all slides and convert the NodeList result to
  654. // an array
  655. var slides = toArray( document.querySelectorAll( selector ) ),
  656. slidesLength = slides.length;
  657. if( slidesLength ) {
  658. // Should the index loop?
  659. if( config.loop ) {
  660. index %= slidesLength;
  661. if( index < 0 ) {
  662. index = slidesLength + index;
  663. }
  664. }
  665. // Enforce max and minimum index bounds
  666. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  667. for( var i = 0; i < slidesLength; i++ ) {
  668. var element = slides[i];
  669. // Optimization; hide all slides that are three or more steps
  670. // away from the present slide
  671. if( isOverviewActive() === false ) {
  672. // The distance loops so that it measures 1 between the first
  673. // and last slides
  674. var distance = Math.abs( ( index - i ) % ( slidesLength - 3 ) ) || 0;
  675. element.style.display = distance > 3 ? 'none' : 'block';
  676. }
  677. slides[i].classList.remove( 'past' );
  678. slides[i].classList.remove( 'present' );
  679. slides[i].classList.remove( 'future' );
  680. if( i < index ) {
  681. // Any element previous to index is given the 'past' class
  682. slides[i].classList.add( 'past' );
  683. }
  684. else if( i > index ) {
  685. // Any element subsequent to index is given the 'future' class
  686. slides[i].classList.add( 'future' );
  687. }
  688. // If this element contains vertical slides
  689. if( element.querySelector( 'section' ) ) {
  690. slides[i].classList.add( 'stack' );
  691. }
  692. }
  693. // Mark the current slide as present
  694. slides[index].classList.add( 'present' );
  695. // If this slide has a state associated with it, add it
  696. // onto the current state of the deck
  697. var slideState = slides[index].getAttribute( 'data-state' );
  698. if( slideState ) {
  699. state = state.concat( slideState.split( ' ' ) );
  700. }
  701. // If this slide has a data-autoslide attribtue associated use this as
  702. // autoSlide value otherwise use the global configured time
  703. var slideAutoSlide = slides[index].getAttribute( 'data-autoslide' );
  704. if( slideAutoSlide ) {
  705. autoSlide = parseInt( slideAutoSlide );
  706. } else {
  707. autoSlide = config.autoSlide
  708. }
  709. }
  710. else {
  711. // Since there are no slides we can't be anywhere beyond the
  712. // zeroth index
  713. index = 0;
  714. }
  715. return index;
  716. }
  717. /**
  718. * Updates the progress bar to reflect the current slide.
  719. */
  720. function updateProgress() {
  721. // Update progress if enabled
  722. if( config.progress && dom.progress ) {
  723. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  724. // The number of past and total slides
  725. var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  726. var pastCount = 0;
  727. // Step through all slides and count the past ones
  728. mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
  729. var horizontalSlide = horizontalSlides[i];
  730. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  731. for( var j = 0; j < verticalSlides.length; j++ ) {
  732. // Stop as soon as we arrive at the present
  733. if( verticalSlides[j].classList.contains( 'present' ) ) break mainLoop;
  734. pastCount++
  735. }
  736. // Stop as soon as we arrive at the present
  737. if( horizontalSlide.classList.contains( 'present' ) ) break;
  738. // Don't count the wrapping section for vertical slides
  739. if( horizontalSlide.classList.contains( 'stack' ) === false ) pastCount++;
  740. }
  741. dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px';
  742. }
  743. }
  744. /**
  745. * Updates the state of all control/navigation arrows.
  746. */
  747. function updateControls() {
  748. if ( config.controls && dom.controls ) {
  749. var routes = availableRoutes();
  750. // Remove the 'enabled' class from all directions
  751. dom.controlsLeft.concat( dom.controlsRight )
  752. .concat( dom.controlsUp )
  753. .concat( dom.controlsDown )
  754. .concat( dom.controlsPrev )
  755. .concat( dom.controlsNext ).forEach( function( node ) {
  756. node.classList.remove( 'enabled' );
  757. } );
  758. // Add the 'enabled' class to the available routes
  759. if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  760. if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  761. if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  762. if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  763. // Prev/next buttons
  764. if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  765. if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  766. }
  767. }
  768. /**
  769. * Determine what available routes there are for navigation.
  770. *
  771. * @return {Object} containing four booleans: left/right/up/down
  772. */
  773. function availableRoutes() {
  774. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  775. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  776. return {
  777. left: indexh > 0,
  778. right: indexh < horizontalSlides.length - 1,
  779. up: indexv > 0,
  780. down: indexv < verticalSlides.length - 1
  781. };
  782. }
  783. /**
  784. * Reads the current URL (hash) and navigates accordingly.
  785. */
  786. function readURL() {
  787. var hash = window.location.hash;
  788. // Attempt to parse the hash as either an index or name
  789. var bits = hash.slice( 2 ).split( '/' ),
  790. name = hash.replace( /#|\//gi, '' );
  791. // If the first bit is invalid and there is a name we can
  792. // assume that this is a named link
  793. if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
  794. // Find the slide with the specified name
  795. var element = document.querySelector( '#' + name );
  796. if( element ) {
  797. // Find the position of the named slide and navigate to it
  798. var indices = Reveal.getIndices( element );
  799. slide( indices.h, indices.v );
  800. }
  801. // If the slide doesn't exist, navigate to the current slide
  802. else {
  803. slide( indexh, indexv );
  804. }
  805. }
  806. else {
  807. // Read the index components of the hash
  808. var h = parseInt( bits[0], 10 ) || 0,
  809. v = parseInt( bits[1], 10 ) || 0;
  810. slide( h, v );
  811. }
  812. }
  813. /**
  814. * Updates the page URL (hash) to reflect the current
  815. * state.
  816. */
  817. function writeURL() {
  818. if( config.history ) {
  819. var url = '/';
  820. // If the current slide has an ID, use that as a named link
  821. if( currentSlide && typeof currentSlide.getAttribute( 'id' ) === 'string' ) {
  822. url = '/' + currentSlide.getAttribute( 'id' );
  823. }
  824. // Otherwise use the /h/v index
  825. else {
  826. if( indexh > 0 || indexv > 0 ) url += indexh;
  827. if( indexv > 0 ) url += '/' + indexv;
  828. }
  829. window.location.hash = url;
  830. }
  831. }
  832. /**
  833. * Retrieves the h/v location of the current, or specified,
  834. * slide.
  835. *
  836. * @param {HTMLElement} slide If specified, the returned
  837. * index will be for this slide rather than the currently
  838. * active one
  839. *
  840. * @return {Object} { h: <int>, v: <int> }
  841. */
  842. function getIndices( slide ) {
  843. // By default, return the current indices
  844. var h = indexh,
  845. v = indexv;
  846. // If a slide is specified, return the indices of that slide
  847. if( slide ) {
  848. var isVertical = !!slide.parentNode.nodeName.match( /section/gi );
  849. var slideh = isVertical ? slide.parentNode : slide;
  850. // Select all horizontal slides
  851. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  852. // Now that we know which the horizontal slide is, get its index
  853. h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
  854. // If this is a vertical slide, grab the vertical index
  855. if( isVertical ) {
  856. v = Math.max( toArray( slide.parentNode.children ).indexOf( slide ), 0 );
  857. }
  858. }
  859. return { h: h, v: v };
  860. }
  861. /**
  862. * Navigate to the next slide fragment.
  863. *
  864. * @return {Boolean} true if there was a next fragment,
  865. * false otherwise
  866. */
  867. function nextFragment() {
  868. // Vertical slides:
  869. if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
  870. var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' );
  871. if( verticalFragments.length ) {
  872. verticalFragments[0].classList.add( 'visible' );
  873. // Notify subscribers of the change
  874. dispatchEvent( 'fragmentshown', { fragment: verticalFragments[0] } );
  875. return true;
  876. }
  877. }
  878. // Horizontal slides:
  879. else {
  880. var horizontalFragments = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' );
  881. if( horizontalFragments.length ) {
  882. horizontalFragments[0].classList.add( 'visible' );
  883. // Notify subscribers of the change
  884. dispatchEvent( 'fragmentshown', { fragment: horizontalFragments[0] } );
  885. return true;
  886. }
  887. }
  888. return false;
  889. }
  890. /**
  891. * Navigate to the previous slide fragment.
  892. *
  893. * @return {Boolean} true if there was a previous fragment,
  894. * false otherwise
  895. */
  896. function previousFragment() {
  897. // Vertical slides:
  898. if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
  899. var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment.visible' );
  900. if( verticalFragments.length ) {
  901. verticalFragments[ verticalFragments.length - 1 ].classList.remove( 'visible' );
  902. // Notify subscribers of the change
  903. dispatchEvent( 'fragmenthidden', { fragment: verticalFragments[ verticalFragments.length - 1 ] } );
  904. return true;
  905. }
  906. }
  907. // Horizontal slides:
  908. else {
  909. var horizontalFragments = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment.visible' );
  910. if( horizontalFragments.length ) {
  911. horizontalFragments[ horizontalFragments.length - 1 ].classList.remove( 'visible' );
  912. // Notify subscribers of the change
  913. dispatchEvent( 'fragmenthidden', { fragment: horizontalFragments[ horizontalFragments.length - 1 ] } );
  914. return true;
  915. }
  916. }
  917. return false;
  918. }
  919. /**
  920. * Cues a new automated slide if enabled in the config.
  921. */
  922. function cueAutoSlide() {
  923. clearTimeout( autoSlideTimeout );
  924. // Cue the next auto-slide if enabled
  925. if( autoSlide ) {
  926. autoSlideTimeout = setTimeout( navigateNext, autoSlide );
  927. }
  928. }
  929. function navigateLeft() {
  930. // Prioritize hiding fragments
  931. if( availableRoutes().left && ( isOverviewActive() || previousFragment() === false ) ) {
  932. slide( indexh - 1, 0 );
  933. }
  934. }
  935. function navigateRight() {
  936. // Prioritize revealing fragments
  937. if( availableRoutes().right && ( isOverviewActive() || nextFragment() === false ) ) {
  938. slide( indexh + 1, 0 );
  939. }
  940. }
  941. function navigateUp() {
  942. // Prioritize hiding fragments
  943. if( availableRoutes().up && ( isOverviewActive() || previousFragment() === false ) ) {
  944. slide( indexh, indexv - 1 );
  945. }
  946. }
  947. function navigateDown() {
  948. // Prioritize revealing fragments
  949. if( availableRoutes().down && ( isOverviewActive() || nextFragment() === false ) ) {
  950. slide( indexh, indexv + 1 );
  951. }
  952. }
  953. /**
  954. * Navigates backwards, prioritized in the following order:
  955. * 1) Previous fragment
  956. * 2) Previous vertical slide
  957. * 3) Previous horizontal slide
  958. */
  959. function navigatePrev() {
  960. // Prioritize revealing fragments
  961. if( previousFragment() === false ) {
  962. if( availableRoutes().up ) {
  963. navigateUp();
  964. }
  965. else {
  966. // Fetch the previous horizontal slide, if there is one
  967. var previousSlide = document.querySelector( '.reveal .slides>section.past:nth-child(' + indexh + ')' );
  968. if( previousSlide ) {
  969. indexv = ( previousSlide.querySelectorAll( 'section' ).length + 1 ) || 0;
  970. indexh --;
  971. slide();
  972. }
  973. }
  974. }
  975. }
  976. /**
  977. * Same as #navigatePrev() but navigates forwards.
  978. */
  979. function navigateNext() {
  980. // Prioritize revealing fragments
  981. if( nextFragment() === false ) {
  982. availableRoutes().down ? navigateDown() : navigateRight();
  983. }
  984. // If auto-sliding is enabled we need to cue up
  985. // another timeout
  986. cueAutoSlide();
  987. }
  988. // --------------------------------------------------------------------//
  989. // ----------------------------- EVENTS -------------------------------//
  990. // --------------------------------------------------------------------//
  991. /**
  992. * Handler for the document level 'keydown' event.
  993. *
  994. * @param {Object} event
  995. */
  996. function onDocumentKeyDown( event ) {
  997. // Check if there's a focused element that could be using
  998. // the keyboard
  999. var activeElement = document.activeElement;
  1000. var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) );
  1001. // Disregard the event if there's a focused element or a
  1002. // keyboard modifier key is present
  1003. if ( hasFocus || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey ) return;
  1004. var triggered = true;
  1005. switch( event.keyCode ) {
  1006. // p, page up
  1007. case 80: case 33: navigatePrev(); break;
  1008. // n, page down
  1009. case 78: case 34: navigateNext(); break;
  1010. // h, left
  1011. case 72: case 37: navigateLeft(); break;
  1012. // l, right
  1013. case 76: case 39: navigateRight(); break;
  1014. // k, up
  1015. case 75: case 38: navigateUp(); break;
  1016. // j, down
  1017. case 74: case 40: navigateDown(); break;
  1018. // home
  1019. case 36: slide( 0 ); break;
  1020. // end
  1021. case 35: slide( Number.MAX_VALUE ); break;
  1022. // space
  1023. case 32: isOverviewActive() ? deactivateOverview() : navigateNext(); break;
  1024. // return
  1025. case 13: isOverviewActive() ? deactivateOverview() : triggered = false; break;
  1026. // b, period
  1027. case 66: case 190: togglePause(); break;
  1028. // f
  1029. case 70: enterFullscreen(); break;
  1030. default:
  1031. triggered = false;
  1032. }
  1033. // If the input resulted in a triggered action we should prevent
  1034. // the browsers default behavior
  1035. if( triggered ) {
  1036. event.preventDefault();
  1037. }
  1038. else if ( event.keyCode === 27 && supports3DTransforms ) {
  1039. toggleOverview();
  1040. event.preventDefault();
  1041. }
  1042. // If auto-sliding is enabled we need to cue up
  1043. // another timeout
  1044. cueAutoSlide();
  1045. }
  1046. /**
  1047. * Handler for the document level 'touchstart' event,
  1048. * enables support for swipe and pinch gestures.
  1049. */
  1050. function onDocumentTouchStart( event ) {
  1051. touch.startX = event.touches[0].clientX;
  1052. touch.startY = event.touches[0].clientY;
  1053. touch.startCount = event.touches.length;
  1054. // If there's two touches we need to memorize the distance
  1055. // between those two points to detect pinching
  1056. if( event.touches.length === 2 && config.overview ) {
  1057. touch.startSpan = distanceBetween( {
  1058. x: event.touches[1].clientX,
  1059. y: event.touches[1].clientY
  1060. }, {
  1061. x: touch.startX,
  1062. y: touch.startY
  1063. } );
  1064. }
  1065. }
  1066. /**
  1067. * Handler for the document level 'touchmove' event.
  1068. */
  1069. function onDocumentTouchMove( event ) {
  1070. // Each touch should only trigger one action
  1071. if( !touch.handled ) {
  1072. var currentX = event.touches[0].clientX;
  1073. var currentY = event.touches[0].clientY;
  1074. // If the touch started off with two points and still has
  1075. // two active touches; test for the pinch gesture
  1076. if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
  1077. // The current distance in pixels between the two touch points
  1078. var currentSpan = distanceBetween( {
  1079. x: event.touches[1].clientX,
  1080. y: event.touches[1].clientY
  1081. }, {
  1082. x: touch.startX,
  1083. y: touch.startY
  1084. } );
  1085. // If the span is larger than the desire amount we've got
  1086. // ourselves a pinch
  1087. if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
  1088. touch.handled = true;
  1089. if( currentSpan < touch.startSpan ) {
  1090. activateOverview();
  1091. }
  1092. else {
  1093. deactivateOverview();
  1094. }
  1095. }
  1096. event.preventDefault();
  1097. }
  1098. // There was only one touch point, look for a swipe
  1099. else if( event.touches.length === 1 && touch.startCount !== 2 ) {
  1100. var deltaX = currentX - touch.startX,
  1101. deltaY = currentY - touch.startY;
  1102. if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  1103. touch.handled = true;
  1104. navigateLeft();
  1105. }
  1106. else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  1107. touch.handled = true;
  1108. navigateRight();
  1109. }
  1110. else if( deltaY > touch.threshold ) {
  1111. touch.handled = true;
  1112. navigateUp();
  1113. }
  1114. else if( deltaY < -touch.threshold ) {
  1115. touch.handled = true;
  1116. navigateDown();
  1117. }
  1118. event.preventDefault();
  1119. }
  1120. }
  1121. // There's a bug with swiping on some Android devices unless
  1122. // the default action is always prevented
  1123. else if( navigator.userAgent.match( /android/gi ) ) {
  1124. event.preventDefault();
  1125. }
  1126. }
  1127. /**
  1128. * Handler for the document level 'touchend' event.
  1129. */
  1130. function onDocumentTouchEnd( event ) {
  1131. touch.handled = false;
  1132. }
  1133. /**
  1134. * Handles mouse wheel scrolling, throttled to avoid skipping
  1135. * multiple slides.
  1136. */
  1137. function onDocumentMouseScroll( event ){
  1138. clearTimeout( mouseWheelTimeout );
  1139. mouseWheelTimeout = setTimeout( function() {
  1140. var delta = event.detail || -event.wheelDelta;
  1141. if( delta > 0 ) {
  1142. navigateNext();
  1143. }
  1144. else {
  1145. navigatePrev();
  1146. }
  1147. }, 100 );
  1148. }
  1149. /**
  1150. * Clicking on the progress bar results in a navigation to the
  1151. * closest approximate horizontal slide using this equation:
  1152. *
  1153. * ( clickX / presentationWidth ) * numberOfSlides
  1154. */
  1155. function onProgressClick( event ) {
  1156. var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
  1157. var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
  1158. slide( slideIndex );
  1159. }
  1160. /**
  1161. * Handler for the window level 'hashchange' event.
  1162. */
  1163. function onWindowHashChange( event ) {
  1164. readURL();
  1165. }
  1166. /**
  1167. * Handler for the window level 'resize' event.
  1168. */
  1169. function onWindowResize( event ) {
  1170. layout();
  1171. }
  1172. /**
  1173. * Invoked when a slide is and we're in the overview.
  1174. */
  1175. function onOverviewSlideClicked( event ) {
  1176. // TODO There's a bug here where the event listeners are not
  1177. // removed after deactivating the overview.
  1178. if( isOverviewActive() ) {
  1179. event.preventDefault();
  1180. deactivateOverview();
  1181. indexh = this.getAttribute( 'data-index-h' );
  1182. indexv = this.getAttribute( 'data-index-v' );
  1183. slide();
  1184. }
  1185. }
  1186. // --------------------------------------------------------------------//
  1187. // ------------------------------- API --------------------------------//
  1188. // --------------------------------------------------------------------//
  1189. return {
  1190. initialize: initialize,
  1191. // Navigation methods
  1192. slide: slide,
  1193. left: navigateLeft,
  1194. right: navigateRight,
  1195. up: navigateUp,
  1196. down: navigateDown,
  1197. prev: navigatePrev,
  1198. next: navigateNext,
  1199. prevFragment: previousFragment,
  1200. nextFragment: nextFragment,
  1201. // Deprecated aliases
  1202. navigateTo: slide,
  1203. navigateLeft: navigateLeft,
  1204. navigateRight: navigateRight,
  1205. navigateUp: navigateUp,
  1206. navigateDown: navigateDown,
  1207. navigatePrev: navigatePrev,
  1208. navigateNext: navigateNext,
  1209. // Toggles the overview mode on/off
  1210. toggleOverview: toggleOverview,
  1211. // Adds or removes all internal event listeners (such as keyboard)
  1212. addEventListeners: addEventListeners,
  1213. removeEventListeners: removeEventListeners,
  1214. // Returns the indices of the current, or specified, slide
  1215. getIndices: getIndices,
  1216. // Returns the previous slide element, may be null
  1217. getPreviousSlide: function() {
  1218. return previousSlide;
  1219. },
  1220. // Returns the current slide element
  1221. getCurrentSlide: function() {
  1222. return currentSlide;
  1223. },
  1224. // Helper method, retrieves query string as a key/value hash
  1225. getQueryHash: function() {
  1226. var query = {};
  1227. location.search.replace( /[A-Z0-9]+?=(\w*)/gi, function(a) {
  1228. query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
  1229. } );
  1230. return query;
  1231. },
  1232. // Forward event binding to the reveal DOM element
  1233. addEventListener: function( type, listener, useCapture ) {
  1234. if( 'addEventListener' in window ) {
  1235. ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
  1236. }
  1237. },
  1238. removeEventListener: function( type, listener, useCapture ) {
  1239. if( 'addEventListener' in window ) {
  1240. ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
  1241. }
  1242. }
  1243. };
  1244. })();