reveal.js 41 KB

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