reveal.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229
  1. /*!
  2. * reveal.js
  3. * http://lab.hakim.se/reveal-js
  4. * MIT licensed
  5. *
  6. * Copyright (C) 2013 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. HOME_SLIDE_SELECTOR = '.reveal .slides>section:first-child',
  14. // Configurations defaults, can be overridden at initialization time
  15. config = {
  16. // The "normal" size of the presentation, aspect ratio will be preserved
  17. // when the presentation is scaled to fit different resolutions
  18. width: 960,
  19. height: 700,
  20. // Factor of the display size that should remain empty around the content
  21. margin: 0.1,
  22. // Bounds for smallest/largest possible scale to apply to content
  23. minScale: 0.2,
  24. maxScale: 1.0,
  25. // Display controls in the bottom right corner
  26. controls: true,
  27. // Display a presentation progress bar
  28. progress: true,
  29. // Push each slide change to the browser history
  30. history: false,
  31. // Enable keyboard shortcuts for navigation
  32. keyboard: true,
  33. // Enable the slide overview mode
  34. overview: true,
  35. // Vertical centring of slides
  36. center: true,
  37. // Enables touch navigation on devices with touch input
  38. touch: true,
  39. // Loop the presentation
  40. loop: false,
  41. // Change the presentation direction to be RTL
  42. rtl: false,
  43. // Turns fragments on and off globally
  44. fragments: true,
  45. // Number of milliseconds between automatically proceeding to the
  46. // next slide, disabled when set to 0, this value can be overwritten
  47. // by using a data-autoslide attribute on your slides
  48. autoSlide: 0,
  49. // Enable slide navigation via mouse wheel
  50. mouseWheel: false,
  51. // Apply a 3D roll to links on hover
  52. rollingLinks: true,
  53. // Theme (see /css/theme)
  54. theme: null,
  55. // Transition style
  56. transition: 'default', // default/cube/page/concave/zoom/linear/fade/none
  57. // Transition speed
  58. transitionSpeed: 'default', // default/fast/slow
  59. // Script dependencies to load
  60. dependencies: []
  61. },
  62. // The current auto-slide duration
  63. autoSlide = 0,
  64. // The horizontal and vertical index of the currently active slide
  65. indexh = 0,
  66. indexv = 0,
  67. // The previous and current slide HTML elements
  68. previousSlide,
  69. currentSlide,
  70. // Slides may hold a data-state attribute which we pick up and apply
  71. // as a class to the body. This list contains the combined state of
  72. // all current slides.
  73. state = [],
  74. // The current scale of the presentation (see width/height config)
  75. scale = 1,
  76. // Cached references to DOM elements
  77. dom = {},
  78. // Detect support for CSS 3D transforms
  79. supports3DTransforms = 'WebkitPerspective' in document.body.style ||
  80. 'MozPerspective' in document.body.style ||
  81. 'msPerspective' in document.body.style ||
  82. 'OPerspective' in document.body.style ||
  83. 'perspective' in document.body.style,
  84. // Detect support for CSS 2D transforms
  85. supports2DTransforms = 'WebkitTransform' in document.body.style ||
  86. 'MozTransform' in document.body.style ||
  87. 'msTransform' in document.body.style ||
  88. 'OTransform' in document.body.style ||
  89. 'transform' in document.body.style,
  90. // Throttles mouse wheel navigation
  91. mouseWheelTimeout = 0,
  92. // An interval used to automatically move on to the next slide
  93. autoSlideTimeout = 0,
  94. // Delays updates to the URL due to a Chrome thumbnailer bug
  95. writeURLTimeout = 0,
  96. // A delay used to activate the overview mode
  97. activateOverviewTimeout = 0,
  98. // A delay used to deactivate the overview mode
  99. deactivateOverviewTimeout = 0,
  100. // Flags if the interaction event listeners are bound
  101. eventsAreBound = false,
  102. // Holds information about the currently ongoing touch input
  103. touch = {
  104. startX: 0,
  105. startY: 0,
  106. startSpan: 0,
  107. startCount: 0,
  108. handled: false,
  109. threshold: 80
  110. };
  111. /**
  112. * Starts up the presentation if the client is capable.
  113. */
  114. function initialize( options ) {
  115. if( !supports2DTransforms && !supports3DTransforms ) {
  116. document.body.setAttribute( 'class', 'no-transforms' );
  117. // If the browser doesn't support core features we won't be
  118. // using JavaScript to control the presentation
  119. return;
  120. }
  121. // Force a layout when the whole page, incl fonts, has loaded
  122. window.addEventListener( 'load', layout, false );
  123. // Copy options over to our config object
  124. extend( config, options );
  125. // Hide the address bar in mobile browsers
  126. hideAddressBar();
  127. // Loads the dependencies and continues to #start() once done
  128. load();
  129. }
  130. /**
  131. * Finds and stores references to DOM elements which are
  132. * required by the presentation. If a required element is
  133. * not found, it is created.
  134. */
  135. function setupDOM() {
  136. // Cache references to key DOM elements
  137. dom.theme = document.querySelector( '#theme' );
  138. dom.wrapper = document.querySelector( '.reveal' );
  139. dom.slides = document.querySelector( '.reveal .slides' );
  140. // Progress bar
  141. if( !dom.wrapper.querySelector( '.progress' ) ) {
  142. var progressElement = document.createElement( 'div' );
  143. progressElement.classList.add( 'progress' );
  144. progressElement.innerHTML = '<span></span>';
  145. dom.wrapper.appendChild( progressElement );
  146. }
  147. // Arrow controls
  148. if( !dom.wrapper.querySelector( '.controls' ) ) {
  149. var controlsElement = document.createElement( 'aside' );
  150. controlsElement.classList.add( 'controls' );
  151. controlsElement.innerHTML = '<div class="navigate-left"></div>' +
  152. '<div class="navigate-right"></div>' +
  153. '<div class="navigate-up"></div>' +
  154. '<div class="navigate-down"></div>';
  155. dom.wrapper.appendChild( controlsElement );
  156. }
  157. // Presentation background element
  158. if( !dom.wrapper.querySelector( '.state-background' ) ) {
  159. var backgroundElement = document.createElement( 'div' );
  160. backgroundElement.classList.add( 'state-background' );
  161. dom.wrapper.appendChild( backgroundElement );
  162. }
  163. // Overlay graphic which is displayed during the paused mode
  164. if( !dom.wrapper.querySelector( '.pause-overlay' ) ) {
  165. var pausedElement = document.createElement( 'div' );
  166. pausedElement.classList.add( 'pause-overlay' );
  167. dom.wrapper.appendChild( pausedElement );
  168. }
  169. // Cache references to elements
  170. dom.progress = document.querySelector( '.reveal .progress' );
  171. dom.progressbar = document.querySelector( '.reveal .progress span' );
  172. if ( config.controls ) {
  173. dom.controls = document.querySelector( '.reveal .controls' );
  174. // There can be multiple instances of controls throughout the page
  175. dom.controlsLeft = toArray( document.querySelectorAll( '.navigate-left' ) );
  176. dom.controlsRight = toArray( document.querySelectorAll( '.navigate-right' ) );
  177. dom.controlsUp = toArray( document.querySelectorAll( '.navigate-up' ) );
  178. dom.controlsDown = toArray( document.querySelectorAll( '.navigate-down' ) );
  179. dom.controlsPrev = toArray( document.querySelectorAll( '.navigate-prev' ) );
  180. dom.controlsNext = toArray( document.querySelectorAll( '.navigate-next' ) );
  181. }
  182. }
  183. /**
  184. * Hides the address bar if we're on a mobile device.
  185. */
  186. function hideAddressBar() {
  187. if( /iphone|ipod|android/gi.test( navigator.userAgent ) && !/crios/gi.test( navigator.userAgent ) ) {
  188. // Events that should trigger the address bar to hide
  189. window.addEventListener( 'load', removeAddressBar, false );
  190. window.addEventListener( 'orientationchange', removeAddressBar, false );
  191. }
  192. }
  193. /**
  194. * Loads the dependencies of reveal.js. Dependencies are
  195. * defined via the configuration option 'dependencies'
  196. * and will be loaded prior to starting/binding reveal.js.
  197. * Some dependencies may have an 'async' flag, if so they
  198. * will load after reveal.js has been started up.
  199. */
  200. function load() {
  201. var scripts = [],
  202. scriptsAsync = [];
  203. for( var i = 0, len = config.dependencies.length; i < len; i++ ) {
  204. var s = config.dependencies[i];
  205. // Load if there's no condition or the condition is truthy
  206. if( !s.condition || s.condition() ) {
  207. if( s.async ) {
  208. scriptsAsync.push( s.src );
  209. }
  210. else {
  211. scripts.push( s.src );
  212. }
  213. // Extension may contain callback functions
  214. if( typeof s.callback === 'function' ) {
  215. head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], s.callback );
  216. }
  217. }
  218. }
  219. // Called once synchronous scripts finish loading
  220. function proceed() {
  221. if( scriptsAsync.length ) {
  222. // Load asynchronous scripts
  223. head.js.apply( null, scriptsAsync );
  224. }
  225. start();
  226. }
  227. if( scripts.length ) {
  228. head.ready( proceed );
  229. // Load synchronous scripts
  230. head.js.apply( null, scripts );
  231. }
  232. else {
  233. proceed();
  234. }
  235. }
  236. /**
  237. * Starts up reveal.js by binding input events and navigating
  238. * to the current URL deeplink if there is one.
  239. */
  240. function start() {
  241. // Make sure we've got all the DOM elements we need
  242. setupDOM();
  243. // Updates the presentation to match the current configuration values
  244. configure();
  245. // Read the initial hash
  246. readURL();
  247. // Notify listeners that the presentation is ready but use a 1ms
  248. // timeout to ensure it's not fired synchronously after #initialize()
  249. setTimeout( function() {
  250. dispatchEvent( 'ready', {
  251. 'indexh': indexh,
  252. 'indexv': indexv,
  253. 'currentSlide': currentSlide
  254. } );
  255. }, 1 );
  256. }
  257. /**
  258. * Applies the configuration settings from the config
  259. * object. May be called multiple times.
  260. */
  261. function configure( options ) {
  262. dom.wrapper.classList.remove( config.transition );
  263. // New config options may be passed when this method
  264. // is invoked through the API after initialization
  265. if( typeof options === 'object' ) extend( config, options );
  266. // Force linear transition based on browser capabilities
  267. if( supports3DTransforms === false ) config.transition = 'linear';
  268. dom.wrapper.classList.add( config.transition );
  269. dom.wrapper.setAttribute( 'data-transition-speed', config.transitionSpeed );
  270. if( dom.controls ) {
  271. dom.controls.style.display = ( config.controls && dom.controls ) ? 'block' : 'none';
  272. }
  273. if( dom.progress ) {
  274. dom.progress.style.display = ( config.progress && dom.progress ) ? 'block' : 'none';
  275. }
  276. if( config.rtl ) {
  277. dom.wrapper.classList.add( 'rtl' );
  278. }
  279. else {
  280. dom.wrapper.classList.remove( 'rtl' );
  281. }
  282. if( config.center ) {
  283. dom.wrapper.classList.add( 'center' );
  284. }
  285. else {
  286. dom.wrapper.classList.remove( 'center' );
  287. }
  288. if( config.mouseWheel ) {
  289. document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  290. document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
  291. }
  292. else {
  293. document.removeEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  294. document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
  295. }
  296. // 3D links
  297. if( config.rollingLinks ) {
  298. enable3DLinks();
  299. }
  300. else {
  301. disable3DLinks();
  302. }
  303. // Load the theme in the config, if it's not already loaded
  304. if( config.theme && dom.theme ) {
  305. var themeURL = dom.theme.getAttribute( 'href' );
  306. var themeFinder = /[^\/]*?(?=\.css)/;
  307. var themeName = themeURL.match(themeFinder)[0];
  308. if( config.theme !== themeName ) {
  309. themeURL = themeURL.replace(themeFinder, config.theme);
  310. dom.theme.setAttribute( 'href', themeURL );
  311. }
  312. }
  313. sync();
  314. }
  315. /**
  316. * Binds all event listeners.
  317. */
  318. function addEventListeners() {
  319. eventsAreBound = true;
  320. window.addEventListener( 'hashchange', onWindowHashChange, false );
  321. window.addEventListener( 'resize', onWindowResize, false );
  322. if( config.touch ) {
  323. dom.wrapper.addEventListener( 'touchstart', onTouchStart, false );
  324. dom.wrapper.addEventListener( 'touchmove', onTouchMove, false );
  325. dom.wrapper.addEventListener( 'touchend', onTouchEnd, false );
  326. // Support pointer-style touch interaction as well
  327. if( window.navigator.msPointerEnabled ) {
  328. dom.wrapper.addEventListener( 'MSPointerDown', onPointerDown, false );
  329. dom.wrapper.addEventListener( 'MSPointerMove', onPointerMove, false );
  330. dom.wrapper.addEventListener( 'MSPointerUp', onPointerUp, false );
  331. }
  332. }
  333. if( config.keyboard ) {
  334. document.addEventListener( 'keydown', onDocumentKeyDown, false );
  335. }
  336. if ( config.progress && dom.progress ) {
  337. dom.progress.addEventListener( 'click', onProgressClicked, false );
  338. }
  339. if ( config.controls && dom.controls ) {
  340. [ 'touchstart', 'click' ].forEach( function( eventName ) {
  341. dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } );
  342. dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } );
  343. dom.controlsUp.forEach( function( el ) { el.addEventListener( eventName, onNavigateUpClicked, false ); } );
  344. dom.controlsDown.forEach( function( el ) { el.addEventListener( eventName, onNavigateDownClicked, false ); } );
  345. dom.controlsPrev.forEach( function( el ) { el.addEventListener( eventName, onNavigatePrevClicked, false ); } );
  346. dom.controlsNext.forEach( function( el ) { el.addEventListener( eventName, onNavigateNextClicked, false ); } );
  347. } );
  348. }
  349. }
  350. /**
  351. * Unbinds all event listeners.
  352. */
  353. function removeEventListeners() {
  354. eventsAreBound = false;
  355. document.removeEventListener( 'keydown', onDocumentKeyDown, false );
  356. window.removeEventListener( 'hashchange', onWindowHashChange, false );
  357. window.removeEventListener( 'resize', onWindowResize, false );
  358. dom.wrapper.removeEventListener( 'touchstart', onTouchStart, false );
  359. dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false );
  360. dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false );
  361. if( window.navigator.msPointerEnabled ) {
  362. dom.wrapper.removeEventListener( 'MSPointerDown', onPointerDown, false );
  363. dom.wrapper.removeEventListener( 'MSPointerMove', onPointerMove, false );
  364. dom.wrapper.removeEventListener( 'MSPointerUp', onPointerUp, false );
  365. }
  366. if ( config.progress && dom.progress ) {
  367. dom.progress.removeEventListener( 'click', onProgressClicked, false );
  368. }
  369. if ( config.controls && dom.controls ) {
  370. [ 'touchstart', 'click' ].forEach( function( eventName ) {
  371. dom.controlsLeft.forEach( function( el ) { el.removeEventListener( eventName, onNavigateLeftClicked, false ); } );
  372. dom.controlsRight.forEach( function( el ) { el.removeEventListener( eventName, onNavigateRightClicked, false ); } );
  373. dom.controlsUp.forEach( function( el ) { el.removeEventListener( eventName, onNavigateUpClicked, false ); } );
  374. dom.controlsDown.forEach( function( el ) { el.removeEventListener( eventName, onNavigateDownClicked, false ); } );
  375. dom.controlsPrev.forEach( function( el ) { el.removeEventListener( eventName, onNavigatePrevClicked, false ); } );
  376. dom.controlsNext.forEach( function( el ) { el.removeEventListener( eventName, onNavigateNextClicked, false ); } );
  377. } );
  378. }
  379. }
  380. /**
  381. * Extend object a with the properties of object b.
  382. * If there's a conflict, object b takes precedence.
  383. */
  384. function extend( a, b ) {
  385. for( var i in b ) {
  386. a[ i ] = b[ i ];
  387. }
  388. }
  389. /**
  390. * Converts the target object to an array.
  391. */
  392. function toArray( o ) {
  393. return Array.prototype.slice.call( o );
  394. }
  395. /**
  396. * Measures the distance in pixels between point a
  397. * and point b.
  398. *
  399. * @param {Object} a point with x/y properties
  400. * @param {Object} b point with x/y properties
  401. */
  402. function distanceBetween( a, b ) {
  403. var dx = a.x - b.x,
  404. dy = a.y - b.y;
  405. return Math.sqrt( dx*dx + dy*dy );
  406. }
  407. /**
  408. * Causes the address bar to hide on mobile devices,
  409. * more vertical space ftw.
  410. */
  411. function removeAddressBar() {
  412. if( window.orientation === 0 ) {
  413. document.documentElement.style.overflow = 'scroll';
  414. document.body.style.height = '120%';
  415. }
  416. else {
  417. document.documentElement.style.overflow = '';
  418. document.body.style.height = '100%';
  419. }
  420. setTimeout( function() {
  421. window.scrollTo( 0, 1 );
  422. }, 10 );
  423. }
  424. /**
  425. * Dispatches an event of the specified type from the
  426. * reveal DOM element.
  427. */
  428. function dispatchEvent( type, properties ) {
  429. var event = document.createEvent( "HTMLEvents", 1, 2 );
  430. event.initEvent( type, true, true );
  431. extend( event, properties );
  432. dom.wrapper.dispatchEvent( event );
  433. }
  434. /**
  435. * Wrap all links in 3D goodness.
  436. */
  437. function enable3DLinks() {
  438. if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) {
  439. var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
  440. for( var i = 0, len = anchors.length; i < len; i++ ) {
  441. var anchor = anchors[i];
  442. if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
  443. var span = document.createElement('span');
  444. span.setAttribute('data-title', anchor.text);
  445. span.innerHTML = anchor.innerHTML;
  446. anchor.classList.add( 'roll' );
  447. anchor.innerHTML = '';
  448. anchor.appendChild(span);
  449. }
  450. }
  451. }
  452. }
  453. /**
  454. * Unwrap all 3D links.
  455. */
  456. function disable3DLinks() {
  457. var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
  458. for( var i = 0, len = anchors.length; i < len; i++ ) {
  459. var anchor = anchors[i];
  460. var span = anchor.querySelector( 'span' );
  461. if( span ) {
  462. anchor.classList.remove( 'roll' );
  463. anchor.innerHTML = span.innerHTML;
  464. }
  465. }
  466. }
  467. /**
  468. * Return a sorted fragments list, ordered by an increasing
  469. * "data-fragment-index" attribute.
  470. *
  471. * Fragments will be revealed in the order that they are returned by
  472. * this function, so you can use the index attributes to control the
  473. * order of fragment appearance.
  474. *
  475. * To maintain a sensible default fragment order, fragments are presumed
  476. * to be passed in document order. This function adds a "fragment-index"
  477. * attribute to each node if such an attribute is not already present,
  478. * and sets that attribute to an integer value which is the position of
  479. * the fragment within the fragments list.
  480. */
  481. function sortFragments( fragments ) {
  482. var a = toArray( fragments );
  483. a.forEach( function( el, idx ) {
  484. if( !el.hasAttribute( 'data-fragment-index' ) ) {
  485. el.setAttribute( 'data-fragment-index', idx );
  486. }
  487. } );
  488. a.sort( function( l, r ) {
  489. return l.getAttribute( 'data-fragment-index' ) - r.getAttribute( 'data-fragment-index');
  490. } );
  491. return a;
  492. }
  493. /**
  494. * Applies JavaScript-controlled layout rules to the
  495. * presentation.
  496. */
  497. function layout() {
  498. if( dom.wrapper ) {
  499. // Available space to scale within
  500. var availableWidth = dom.wrapper.offsetWidth,
  501. availableHeight = dom.wrapper.offsetHeight;
  502. // Reduce available space by margin
  503. availableWidth -= ( availableHeight * config.margin );
  504. availableHeight -= ( availableHeight * config.margin );
  505. // Dimensions of the content
  506. var slideWidth = config.width,
  507. slideHeight = config.height;
  508. // Slide width may be a percentage of available width
  509. if( typeof slideWidth === 'string' && /%$/.test( slideWidth ) ) {
  510. slideWidth = parseInt( slideWidth, 10 ) / 100 * availableWidth;
  511. }
  512. // Slide height may be a percentage of available height
  513. if( typeof slideHeight === 'string' && /%$/.test( slideHeight ) ) {
  514. slideHeight = parseInt( slideHeight, 10 ) / 100 * availableHeight;
  515. }
  516. dom.slides.style.width = slideWidth + 'px';
  517. dom.slides.style.height = slideHeight + 'px';
  518. // Determine scale of content to fit within available space
  519. scale = Math.min( availableWidth / slideWidth, availableHeight / slideHeight );
  520. // Respect max/min scale settings
  521. scale = Math.max( scale, config.minScale );
  522. scale = Math.min( scale, config.maxScale );
  523. // Prefer applying scale via zoom since Chrome blurs scaled content
  524. // with nested transforms
  525. if( typeof dom.slides.style.zoom !== 'undefined' && !navigator.userAgent.match( /(iphone|ipod|ipad|android)/gi ) ) {
  526. dom.slides.style.zoom = scale;
  527. }
  528. // Apply scale transform as a fallback
  529. else {
  530. var transform = 'translate(-50%, -50%) scale('+ scale +') translate(50%, 50%)';
  531. dom.slides.style.WebkitTransform = transform;
  532. dom.slides.style.MozTransform = transform;
  533. dom.slides.style.msTransform = transform;
  534. dom.slides.style.OTransform = transform;
  535. dom.slides.style.transform = transform;
  536. }
  537. // Select all slides, vertical and horizontal
  538. var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
  539. for( var i = 0, len = slides.length; i < len; i++ ) {
  540. var slide = slides[ i ];
  541. // Don't bother updating invisible slides
  542. if( slide.style.display === 'none' ) {
  543. continue;
  544. }
  545. if( config.center ) {
  546. // Vertical stacks are not centred since their section
  547. // children will be
  548. if( slide.classList.contains( 'stack' ) ) {
  549. slide.style.top = 0;
  550. }
  551. else {
  552. slide.style.top = Math.max( - ( slide.offsetHeight / 2 ) - 20, -slideHeight / 2 ) + 'px';
  553. }
  554. }
  555. else {
  556. slide.style.top = '';
  557. }
  558. }
  559. updateProgress();
  560. }
  561. }
  562. /**
  563. * Stores the vertical index of a stack so that the same
  564. * vertical slide can be selected when navigating to and
  565. * from the stack.
  566. *
  567. * @param {HTMLElement} stack The vertical stack element
  568. * @param {int} v Index to memorize
  569. */
  570. function setPreviousVerticalIndex( stack, v ) {
  571. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
  572. stack.setAttribute( 'data-previous-indexv', v || 0 );
  573. }
  574. }
  575. /**
  576. * Retrieves the vertical index which was stored using
  577. * #setPreviousVerticalIndex() or 0 if no previous index
  578. * exists.
  579. *
  580. * @param {HTMLElement} stack The vertical stack element
  581. */
  582. function getPreviousVerticalIndex( stack ) {
  583. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
  584. return parseInt( stack.getAttribute( 'data-previous-indexv' ) || 0, 10 );
  585. }
  586. return 0;
  587. }
  588. /**
  589. * Displays the overview of slides (quick nav) by
  590. * scaling down and arranging all slide elements.
  591. *
  592. * Experimental feature, might be dropped if perf
  593. * can't be improved.
  594. */
  595. function activateOverview() {
  596. // Only proceed if enabled in config
  597. if( config.overview ) {
  598. // Don't auto-slide while in overview mode
  599. cancelAutoSlide();
  600. var wasActive = dom.wrapper.classList.contains( 'overview' );
  601. dom.wrapper.classList.add( 'overview' );
  602. dom.wrapper.classList.remove( 'exit-overview' );
  603. clearTimeout( activateOverviewTimeout );
  604. clearTimeout( deactivateOverviewTimeout );
  605. // Not the pretties solution, but need to let the overview
  606. // class apply first so that slides are measured accurately
  607. // before we can position them
  608. activateOverviewTimeout = setTimeout( function(){
  609. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  610. for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
  611. var hslide = horizontalSlides[i],
  612. hoffset = config.rtl ? -105 : 105,
  613. htransform = 'translateZ(-2500px) translate(' + ( ( i - indexh ) * hoffset ) + '%, 0%)';
  614. hslide.setAttribute( 'data-index-h', i );
  615. hslide.style.display = 'block';
  616. hslide.style.WebkitTransform = htransform;
  617. hslide.style.MozTransform = htransform;
  618. hslide.style.msTransform = htransform;
  619. hslide.style.OTransform = htransform;
  620. hslide.style.transform = htransform;
  621. if( hslide.classList.contains( 'stack' ) ) {
  622. var verticalSlides = hslide.querySelectorAll( 'section' );
  623. for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
  624. var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
  625. var vslide = verticalSlides[j],
  626. vtransform = 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)';
  627. vslide.setAttribute( 'data-index-h', i );
  628. vslide.setAttribute( 'data-index-v', j );
  629. vslide.style.display = 'block';
  630. vslide.style.WebkitTransform = vtransform;
  631. vslide.style.MozTransform = vtransform;
  632. vslide.style.msTransform = vtransform;
  633. vslide.style.OTransform = vtransform;
  634. vslide.style.transform = vtransform;
  635. // Navigate to this slide on click
  636. vslide.addEventListener( 'click', onOverviewSlideClicked, true );
  637. }
  638. }
  639. else {
  640. // Navigate to this slide on click
  641. hslide.addEventListener( 'click', onOverviewSlideClicked, true );
  642. }
  643. }
  644. layout();
  645. if( !wasActive ) {
  646. // Notify observers of the overview showing
  647. dispatchEvent( 'overviewshown', {
  648. 'indexh': indexh,
  649. 'indexv': indexv,
  650. 'currentSlide': currentSlide
  651. } );
  652. }
  653. }, 10 );
  654. }
  655. }
  656. /**
  657. * Exits the slide overview and enters the currently
  658. * active slide.
  659. */
  660. function deactivateOverview() {
  661. // Only proceed if enabled in config
  662. if( config.overview ) {
  663. clearTimeout( activateOverviewTimeout );
  664. clearTimeout( deactivateOverviewTimeout );
  665. dom.wrapper.classList.remove( 'overview' );
  666. // Temporarily add a class so that transitions can do different things
  667. // depending on whether they are exiting/entering overview, or just
  668. // moving from slide to slide
  669. dom.wrapper.classList.add( 'exit-overview' );
  670. deactivateOverviewTimeout = setTimeout( function () {
  671. dom.wrapper.classList.remove( 'exit-overview' );
  672. }, 10);
  673. // Select all slides
  674. var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
  675. for( var i = 0, len = slides.length; i < len; i++ ) {
  676. var element = slides[i];
  677. element.style.display = '';
  678. // Resets all transforms to use the external styles
  679. element.style.WebkitTransform = '';
  680. element.style.MozTransform = '';
  681. element.style.msTransform = '';
  682. element.style.OTransform = '';
  683. element.style.transform = '';
  684. element.removeEventListener( 'click', onOverviewSlideClicked, true );
  685. }
  686. slide( indexh, indexv );
  687. cueAutoSlide();
  688. // Notify observers of the overview hiding
  689. dispatchEvent( 'overviewhidden', {
  690. 'indexh': indexh,
  691. 'indexv': indexv,
  692. 'currentSlide': currentSlide
  693. } );
  694. }
  695. }
  696. /**
  697. * Toggles the slide overview mode on and off.
  698. *
  699. * @param {Boolean} override Optional flag which overrides the
  700. * toggle logic and forcibly sets the desired state. True means
  701. * overview is open, false means it's closed.
  702. */
  703. function toggleOverview( override ) {
  704. if( typeof override === 'boolean' ) {
  705. override ? activateOverview() : deactivateOverview();
  706. }
  707. else {
  708. isOverview() ? deactivateOverview() : activateOverview();
  709. }
  710. }
  711. /**
  712. * Checks if the overview is currently active.
  713. *
  714. * @return {Boolean} true if the overview is active,
  715. * false otherwise
  716. */
  717. function isOverview() {
  718. return dom.wrapper.classList.contains( 'overview' );
  719. }
  720. /**
  721. * Checks if the current or specified slide is vertical
  722. * (nested within another slide).
  723. *
  724. * @param {HTMLElement} slide [optional] The slide to check
  725. * orientation of
  726. */
  727. function isVerticalSlide( slide ) {
  728. // Prefer slide argument, otherwise use current slide
  729. slide = slide ? slide : currentSlide;
  730. return slide && !!slide.parentNode.nodeName.match( /section/i );
  731. }
  732. /**
  733. * Handling the fullscreen functionality via the fullscreen API
  734. *
  735. * @see http://fullscreen.spec.whatwg.org/
  736. * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
  737. */
  738. function enterFullscreen() {
  739. var element = document.body;
  740. // Check which implementation is available
  741. var requestMethod = element.requestFullScreen ||
  742. element.webkitRequestFullscreen ||
  743. element.webkitRequestFullScreen ||
  744. element.mozRequestFullScreen ||
  745. element.msRequestFullScreen;
  746. if( requestMethod ) {
  747. requestMethod.apply( element );
  748. }
  749. }
  750. /**
  751. * Enters the paused mode which fades everything on screen to
  752. * black.
  753. */
  754. function pause() {
  755. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  756. cancelAutoSlide();
  757. dom.wrapper.classList.add( 'paused' );
  758. if( wasPaused === false ) {
  759. dispatchEvent( 'paused' );
  760. }
  761. }
  762. /**
  763. * Exits from the paused mode.
  764. */
  765. function resume() {
  766. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  767. dom.wrapper.classList.remove( 'paused' );
  768. cueAutoSlide();
  769. if( wasPaused ) {
  770. dispatchEvent( 'resumed' );
  771. }
  772. }
  773. /**
  774. * Toggles the paused mode on and off.
  775. */
  776. function togglePause() {
  777. if( isPaused() ) {
  778. resume();
  779. }
  780. else {
  781. pause();
  782. }
  783. }
  784. /**
  785. * Checks if we are currently in the paused mode.
  786. */
  787. function isPaused() {
  788. return dom.wrapper.classList.contains( 'paused' );
  789. }
  790. /**
  791. * Steps from the current point in the presentation to the
  792. * slide which matches the specified horizontal and vertical
  793. * indices.
  794. *
  795. * @param {int} h Horizontal index of the target slide
  796. * @param {int} v Vertical index of the target slide
  797. * @param {int} f Optional index of a fragment within the
  798. * target slide to activate
  799. * @param {int} o Optional origin for use in multimaster environments
  800. */
  801. function slide( h, v, f, o ) {
  802. // Remember where we were at before
  803. previousSlide = currentSlide;
  804. // Query all horizontal slides in the deck
  805. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  806. // If no vertical index is specified and the upcoming slide is a
  807. // stack, resume at its previous vertical index
  808. if( v === undefined ) {
  809. v = getPreviousVerticalIndex( horizontalSlides[ h ] );
  810. }
  811. // If we were on a vertical stack, remember what vertical index
  812. // it was on so we can resume at the same position when returning
  813. if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
  814. setPreviousVerticalIndex( previousSlide.parentNode, indexv );
  815. }
  816. // Remember the state before this slide
  817. var stateBefore = state.concat();
  818. // Reset the state array
  819. state.length = 0;
  820. var indexhBefore = indexh,
  821. indexvBefore = indexv;
  822. // Activate and transition to the new slide
  823. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
  824. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
  825. layout();
  826. // Apply the new state
  827. stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
  828. // Check if this state existed on the previous slide. If it
  829. // did, we will avoid adding it repeatedly
  830. for( var j = 0; j < stateBefore.length; j++ ) {
  831. if( stateBefore[j] === state[i] ) {
  832. stateBefore.splice( j, 1 );
  833. continue stateLoop;
  834. }
  835. }
  836. document.documentElement.classList.add( state[i] );
  837. // Dispatch custom event matching the state's name
  838. dispatchEvent( state[i] );
  839. }
  840. // Clean up the remains of the previous state
  841. while( stateBefore.length ) {
  842. document.documentElement.classList.remove( stateBefore.pop() );
  843. }
  844. // If the overview is active, re-activate it to update positions
  845. if( isOverview() ) {
  846. activateOverview();
  847. }
  848. // Update the URL hash after a delay since updating it mid-transition
  849. // is likely to cause visual lag
  850. writeURL( 1500 );
  851. // Find the current horizontal slide and any possible vertical slides
  852. // within it
  853. var currentHorizontalSlide = horizontalSlides[ indexh ],
  854. currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
  855. // Store references to the previous and current slides
  856. currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
  857. // Show fragment, if specified
  858. if( typeof f !== 'undefined' ) {
  859. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
  860. toArray( fragments ).forEach( function( fragment, indexf ) {
  861. if( indexf < f ) {
  862. fragment.classList.add( 'visible' );
  863. }
  864. else {
  865. fragment.classList.remove( 'visible' );
  866. }
  867. } );
  868. }
  869. // Dispatch an event if the slide changed
  870. if( indexh !== indexhBefore || indexv !== indexvBefore ) {
  871. dispatchEvent( 'slidechanged', {
  872. 'indexh': indexh,
  873. 'indexv': indexv,
  874. 'previousSlide': previousSlide,
  875. 'currentSlide': currentSlide,
  876. 'origin': o
  877. } );
  878. }
  879. else {
  880. // Ensure that the previous slide is never the same as the current
  881. previousSlide = null;
  882. }
  883. // Solves an edge case where the previous slide maintains the
  884. // 'present' class when navigating between adjacent vertical
  885. // stacks
  886. if( previousSlide ) {
  887. previousSlide.classList.remove( 'present' );
  888. // Reset all slides upon navigate to home
  889. // Issue: #285
  890. if ( document.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
  891. // Launch async task
  892. setTimeout( function () {
  893. var slides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
  894. for( i in slides ) {
  895. if( slides[i] ) {
  896. // Reset stack
  897. setPreviousVerticalIndex( slides[i], 0 );
  898. }
  899. }
  900. }, 0 );
  901. }
  902. }
  903. // Handle embedded content
  904. stopEmbeddedContent( previousSlide );
  905. startEmbeddedContent( currentSlide );
  906. updateControls();
  907. updateProgress();
  908. }
  909. /**
  910. * Syncs the presentation with the current DOM. Useful
  911. * when new slides or control elements are added or when
  912. * the configuration has changed.
  913. */
  914. function sync() {
  915. // Subscribe to input
  916. removeEventListeners();
  917. addEventListeners();
  918. // Force a layout to make sure the current config is accounted for
  919. layout();
  920. // Reflect the current autoSlide value
  921. autoSlide = config.autoSlide;
  922. // Start auto-sliding if it's enabled
  923. cueAutoSlide();
  924. updateControls();
  925. updateProgress();
  926. }
  927. /**
  928. * Updates one dimension of slides by showing the slide
  929. * with the specified index.
  930. *
  931. * @param {String} selector A CSS selector that will fetch
  932. * the group of slides we are working with
  933. * @param {Number} index The index of the slide that should be
  934. * shown
  935. *
  936. * @return {Number} The index of the slide that is now shown,
  937. * might differ from the passed in index if it was out of
  938. * bounds.
  939. */
  940. function updateSlides( selector, index ) {
  941. // Select all slides and convert the NodeList result to
  942. // an array
  943. var slides = toArray( document.querySelectorAll( selector ) ),
  944. slidesLength = slides.length;
  945. if( slidesLength ) {
  946. // Should the index loop?
  947. if( config.loop ) {
  948. index %= slidesLength;
  949. if( index < 0 ) {
  950. index = slidesLength + index;
  951. }
  952. }
  953. // Enforce max and minimum index bounds
  954. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  955. for( var i = 0; i < slidesLength; i++ ) {
  956. var element = slides[i];
  957. // Optimization; hide all slides that are three or more steps
  958. // away from the present slide
  959. if( isOverview() === false ) {
  960. // The distance loops so that it measures 1 between the first
  961. // and last slides
  962. var distance = Math.abs( ( index - i ) % ( slidesLength - 3 ) ) || 0;
  963. element.style.display = distance > 3 ? 'none' : 'block';
  964. }
  965. var reverse = config.rtl && !isVerticalSlide( element );
  966. element.classList.remove( 'past' );
  967. element.classList.remove( 'present' );
  968. element.classList.remove( 'future' );
  969. if( i < index ) {
  970. // Any element previous to index is given the 'past' class
  971. element.classList.add( reverse ? 'future' : 'past' );
  972. }
  973. else if( i > index ) {
  974. // Any element subsequent to index is given the 'future' class
  975. element.classList.add( reverse ? 'past' : 'future' );
  976. }
  977. // If this element contains vertical slides
  978. if( element.querySelector( 'section' ) ) {
  979. element.classList.add( 'stack' );
  980. }
  981. }
  982. // Mark the current slide as present
  983. slides[index].classList.add( 'present' );
  984. // If this slide has a state associated with it, add it
  985. // onto the current state of the deck
  986. var slideState = slides[index].getAttribute( 'data-state' );
  987. if( slideState ) {
  988. state = state.concat( slideState.split( ' ' ) );
  989. }
  990. // If this slide has a data-autoslide attribtue associated use this as
  991. // autoSlide value otherwise use the global configured time
  992. var slideAutoSlide = slides[index].getAttribute( 'data-autoslide' );
  993. if( slideAutoSlide ) {
  994. autoSlide = parseInt( slideAutoSlide, 10 );
  995. }
  996. else {
  997. autoSlide = config.autoSlide;
  998. }
  999. }
  1000. else {
  1001. // Since there are no slides we can't be anywhere beyond the
  1002. // zeroth index
  1003. index = 0;
  1004. }
  1005. return index;
  1006. }
  1007. /**
  1008. * Updates the progress bar to reflect the current slide.
  1009. */
  1010. function updateProgress() {
  1011. // Update progress if enabled
  1012. if( config.progress && dom.progress ) {
  1013. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1014. // The number of past and total slides
  1015. var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  1016. var pastCount = 0;
  1017. // Step through all slides and count the past ones
  1018. mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
  1019. var horizontalSlide = horizontalSlides[i];
  1020. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1021. for( var j = 0; j < verticalSlides.length; j++ ) {
  1022. // Stop as soon as we arrive at the present
  1023. if( verticalSlides[j].classList.contains( 'present' ) ) {
  1024. break mainLoop;
  1025. }
  1026. pastCount++;
  1027. }
  1028. // Stop as soon as we arrive at the present
  1029. if( horizontalSlide.classList.contains( 'present' ) ) {
  1030. break;
  1031. }
  1032. // Don't count the wrapping section for vertical slides
  1033. if( horizontalSlide.classList.contains( 'stack' ) === false ) {
  1034. pastCount++;
  1035. }
  1036. }
  1037. dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px';
  1038. }
  1039. }
  1040. /**
  1041. * Updates the state of all control/navigation arrows.
  1042. */
  1043. function updateControls() {
  1044. if ( config.controls && dom.controls ) {
  1045. var routes = availableRoutes();
  1046. var fragments = availableFragments();
  1047. // Remove the 'enabled' class from all directions
  1048. dom.controlsLeft.concat( dom.controlsRight )
  1049. .concat( dom.controlsUp )
  1050. .concat( dom.controlsDown )
  1051. .concat( dom.controlsPrev )
  1052. .concat( dom.controlsNext ).forEach( function( node ) {
  1053. node.classList.remove( 'enabled' );
  1054. node.classList.remove( 'fragmented' );
  1055. } );
  1056. // Add the 'enabled' class to the available routes
  1057. if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1058. if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1059. if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1060. if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1061. // Prev/next buttons
  1062. if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1063. if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1064. // Highlight fragment directions
  1065. if( currentSlide ) {
  1066. // Always apply fragment decorator to prev/next buttons
  1067. if( fragments.prev ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1068. if( fragments.next ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1069. // Apply fragment decorators to directional buttons based on
  1070. // what slide axis they are in
  1071. if( isVerticalSlide( currentSlide ) ) {
  1072. if( fragments.prev ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1073. if( fragments.next ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1074. }
  1075. else {
  1076. if( fragments.prev ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1077. if( fragments.next ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1078. }
  1079. }
  1080. }
  1081. }
  1082. /**
  1083. * Determine what available routes there are for navigation.
  1084. *
  1085. * @return {Object} containing four booleans: left/right/up/down
  1086. */
  1087. function availableRoutes() {
  1088. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1089. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1090. var routes = {
  1091. left: indexh > 0 || config.loop,
  1092. right: indexh < horizontalSlides.length - 1 || config.loop,
  1093. up: indexv > 0,
  1094. down: indexv < verticalSlides.length - 1
  1095. };
  1096. // reverse horizontal controls for rtl
  1097. if( config.rtl ) {
  1098. var left = routes.left;
  1099. routes.left = routes.right;
  1100. routes.right = left;
  1101. }
  1102. return routes;
  1103. }
  1104. /**
  1105. * Returns an object describing the available fragment
  1106. * directions.
  1107. *
  1108. * @return {Object} two boolean properties: prev/next
  1109. */
  1110. function availableFragments() {
  1111. if( currentSlide && config.fragments ) {
  1112. var fragments = currentSlide.querySelectorAll( '.fragment' );
  1113. var hiddenFragments = currentSlide.querySelectorAll( '.fragment:not(.visible)' );
  1114. return {
  1115. prev: fragments.length - hiddenFragments.length > 0,
  1116. next: !!hiddenFragments.length
  1117. };
  1118. }
  1119. else {
  1120. return { prev: false, next: false };
  1121. }
  1122. }
  1123. /**
  1124. * Start playback of any embedded content inside of
  1125. * the targeted slide.
  1126. */
  1127. function startEmbeddedContent( slide ) {
  1128. if( slide ) {
  1129. // HTML5 media elements
  1130. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1131. if( el.hasAttribute( 'data-autoplay' ) ) {
  1132. el.play();
  1133. }
  1134. } );
  1135. // YouTube embeds
  1136. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  1137. if( el.hasAttribute( 'data-autoplay' ) ) {
  1138. el.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
  1139. }
  1140. });
  1141. }
  1142. }
  1143. /**
  1144. * Stop playback of any embedded content inside of
  1145. * the targeted slide.
  1146. */
  1147. function stopEmbeddedContent( slide ) {
  1148. if( slide ) {
  1149. // HTML5 media elements
  1150. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1151. if( !el.hasAttribute( 'data-ignore' ) ) {
  1152. el.pause();
  1153. }
  1154. } );
  1155. // YouTube embeds
  1156. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  1157. if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
  1158. el.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
  1159. }
  1160. });
  1161. }
  1162. }
  1163. /**
  1164. * Reads the current URL (hash) and navigates accordingly.
  1165. */
  1166. function readURL() {
  1167. var hash = window.location.hash;
  1168. // Attempt to parse the hash as either an index or name
  1169. var bits = hash.slice( 2 ).split( '/' ),
  1170. name = hash.replace( /#|\//gi, '' );
  1171. // If the first bit is invalid and there is a name we can
  1172. // assume that this is a named link
  1173. if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
  1174. // Find the slide with the specified name
  1175. var element = document.querySelector( '#' + name );
  1176. if( element ) {
  1177. // Find the position of the named slide and navigate to it
  1178. var indices = Reveal.getIndices( element );
  1179. slide( indices.h, indices.v );
  1180. }
  1181. // If the slide doesn't exist, navigate to the current slide
  1182. else {
  1183. slide( indexh, indexv );
  1184. }
  1185. }
  1186. else {
  1187. // Read the index components of the hash
  1188. var h = parseInt( bits[0], 10 ) || 0,
  1189. v = parseInt( bits[1], 10 ) || 0;
  1190. slide( h, v );
  1191. }
  1192. }
  1193. /**
  1194. * Updates the page URL (hash) to reflect the current
  1195. * state.
  1196. *
  1197. * @param {Number} delay The time in ms to wait before
  1198. * writing the hash
  1199. */
  1200. function writeURL( delay ) {
  1201. if( config.history ) {
  1202. // Make sure there's never more than one timeout running
  1203. clearTimeout( writeURLTimeout );
  1204. // If a delay is specified, timeout this call
  1205. if( typeof delay === 'number' ) {
  1206. writeURLTimeout = setTimeout( writeURL, delay );
  1207. }
  1208. else {
  1209. var url = '/';
  1210. // If the current slide has an ID, use that as a named link
  1211. if( currentSlide && typeof currentSlide.getAttribute( 'id' ) === 'string' ) {
  1212. url = '/' + currentSlide.getAttribute( 'id' );
  1213. }
  1214. // Otherwise use the /h/v index
  1215. else {
  1216. if( indexh > 0 || indexv > 0 ) url += indexh;
  1217. if( indexv > 0 ) url += '/' + indexv;
  1218. }
  1219. window.location.hash = url;
  1220. }
  1221. }
  1222. }
  1223. /**
  1224. * Retrieves the h/v location of the current, or specified,
  1225. * slide.
  1226. *
  1227. * @param {HTMLElement} slide If specified, the returned
  1228. * index will be for this slide rather than the currently
  1229. * active one
  1230. *
  1231. * @return {Object} { h: <int>, v: <int>, f: <int> }
  1232. */
  1233. function getIndices( slide ) {
  1234. // By default, return the current indices
  1235. var h = indexh,
  1236. v = indexv,
  1237. f;
  1238. // If a slide is specified, return the indices of that slide
  1239. if( slide ) {
  1240. var isVertical = isVerticalSlide( slide );
  1241. var slideh = isVertical ? slide.parentNode : slide;
  1242. // Select all horizontal slides
  1243. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1244. // Now that we know which the horizontal slide is, get its index
  1245. h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
  1246. // If this is a vertical slide, grab the vertical index
  1247. if( isVertical ) {
  1248. v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
  1249. }
  1250. }
  1251. if( !slide && currentSlide ) {
  1252. var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
  1253. if( visibleFragments.length ) {
  1254. f = visibleFragments.length;
  1255. }
  1256. }
  1257. return { h: h, v: v, f: f };
  1258. }
  1259. /**
  1260. * Navigate to the next slide fragment.
  1261. *
  1262. * @return {Boolean} true if there was a next fragment,
  1263. * false otherwise
  1264. */
  1265. function nextFragment() {
  1266. if( currentSlide && config.fragments ) {
  1267. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment:not(.visible)' ) );
  1268. if( fragments.length ) {
  1269. fragments[0].classList.add( 'visible' );
  1270. // Notify subscribers of the change
  1271. dispatchEvent( 'fragmentshown', { fragment: fragments[0] } );
  1272. updateControls();
  1273. return true;
  1274. }
  1275. }
  1276. return false;
  1277. }
  1278. /**
  1279. * Navigate to the previous slide fragment.
  1280. *
  1281. * @return {Boolean} true if there was a previous fragment,
  1282. * false otherwise
  1283. */
  1284. function previousFragment() {
  1285. if( currentSlide && config.fragments ) {
  1286. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) );
  1287. if( fragments.length ) {
  1288. fragments[ fragments.length - 1 ].classList.remove( 'visible' );
  1289. // Notify subscribers of the change
  1290. dispatchEvent( 'fragmenthidden', { fragment: fragments[ fragments.length - 1 ] } );
  1291. updateControls();
  1292. return true;
  1293. }
  1294. }
  1295. return false;
  1296. }
  1297. /**
  1298. * Cues a new automated slide if enabled in the config.
  1299. */
  1300. function cueAutoSlide() {
  1301. clearTimeout( autoSlideTimeout );
  1302. // Cue the next auto-slide if enabled
  1303. if( autoSlide && !isPaused() && !isOverview() ) {
  1304. autoSlideTimeout = setTimeout( navigateNext, autoSlide );
  1305. }
  1306. }
  1307. /**
  1308. * Cancels any ongoing request to auto-slide.
  1309. */
  1310. function cancelAutoSlide() {
  1311. clearTimeout( autoSlideTimeout );
  1312. }
  1313. function navigateLeft() {
  1314. // Reverse for RTL
  1315. if( config.rtl ) {
  1316. if( ( isOverview() || nextFragment() === false ) && availableRoutes().left ) {
  1317. slide( indexh + 1 );
  1318. }
  1319. }
  1320. // Normal navigation
  1321. else if( ( isOverview() || previousFragment() === false ) && availableRoutes().left ) {
  1322. slide( indexh - 1 );
  1323. }
  1324. }
  1325. function navigateRight() {
  1326. // Reverse for RTL
  1327. if( config.rtl ) {
  1328. if( ( isOverview() || previousFragment() === false ) && availableRoutes().right ) {
  1329. slide( indexh - 1 );
  1330. }
  1331. }
  1332. // Normal navigation
  1333. else if( ( isOverview() || nextFragment() === false ) && availableRoutes().right ) {
  1334. slide( indexh + 1 );
  1335. }
  1336. }
  1337. function navigateUp() {
  1338. // Prioritize hiding fragments
  1339. if( ( isOverview() || previousFragment() === false ) && availableRoutes().up ) {
  1340. slide( indexh, indexv - 1 );
  1341. }
  1342. }
  1343. function navigateDown() {
  1344. // Prioritize revealing fragments
  1345. if( ( isOverview() || nextFragment() === false ) && availableRoutes().down ) {
  1346. slide( indexh, indexv + 1 );
  1347. }
  1348. }
  1349. /**
  1350. * Navigates backwards, prioritized in the following order:
  1351. * 1) Previous fragment
  1352. * 2) Previous vertical slide
  1353. * 3) Previous horizontal slide
  1354. */
  1355. function navigatePrev() {
  1356. // Prioritize revealing fragments
  1357. if( previousFragment() === false ) {
  1358. if( availableRoutes().up ) {
  1359. navigateUp();
  1360. }
  1361. else {
  1362. // Fetch the previous horizontal slide, if there is one
  1363. var previousSlide = document.querySelector( HORIZONTAL_SLIDES_SELECTOR + '.past:nth-child(' + indexh + ')' );
  1364. if( previousSlide ) {
  1365. indexv = ( previousSlide.querySelectorAll( 'section' ).length + 1 ) || undefined;
  1366. indexh --;
  1367. slide( indexh, indexv );
  1368. }
  1369. }
  1370. }
  1371. }
  1372. /**
  1373. * Same as #navigatePrev() but navigates forwards.
  1374. */
  1375. function navigateNext() {
  1376. // Prioritize revealing fragments
  1377. if( nextFragment() === false ) {
  1378. availableRoutes().down ? navigateDown() : navigateRight();
  1379. }
  1380. // If auto-sliding is enabled we need to cue up
  1381. // another timeout
  1382. cueAutoSlide();
  1383. }
  1384. // --------------------------------------------------------------------//
  1385. // ----------------------------- EVENTS -------------------------------//
  1386. // --------------------------------------------------------------------//
  1387. /**
  1388. * Handler for the document level 'keydown' event.
  1389. *
  1390. * @param {Object} event
  1391. */
  1392. function onDocumentKeyDown( event ) {
  1393. // Check if there's a focused element that could be using
  1394. // the keyboard
  1395. var activeElement = document.activeElement;
  1396. var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) );
  1397. // Disregard the event if there's a focused element or a
  1398. // keyboard modifier key is present
  1399. if( hasFocus || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
  1400. var triggered = true;
  1401. // while paused only allow "unpausing" keyboard events (b and .)
  1402. if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) {
  1403. return false;
  1404. }
  1405. switch( event.keyCode ) {
  1406. // p, page up
  1407. case 80: case 33: navigatePrev(); break;
  1408. // n, page down
  1409. case 78: case 34: navigateNext(); break;
  1410. // h, left
  1411. case 72: case 37: navigateLeft(); break;
  1412. // l, right
  1413. case 76: case 39: navigateRight(); break;
  1414. // k, up
  1415. case 75: case 38: navigateUp(); break;
  1416. // j, down
  1417. case 74: case 40: navigateDown(); break;
  1418. // home
  1419. case 36: slide( 0 ); break;
  1420. // end
  1421. case 35: slide( Number.MAX_VALUE ); break;
  1422. // space
  1423. case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
  1424. // return
  1425. case 13: isOverview() ? deactivateOverview() : triggered = false; break;
  1426. // b, period, Logitech presenter tools "black screen" button
  1427. case 66: case 190: case 191: togglePause(); break;
  1428. // f
  1429. case 70: enterFullscreen(); break;
  1430. default:
  1431. triggered = false;
  1432. }
  1433. // If the input resulted in a triggered action we should prevent
  1434. // the browsers default behavior
  1435. if( triggered ) {
  1436. event.preventDefault();
  1437. }
  1438. else if ( event.keyCode === 27 && supports3DTransforms ) {
  1439. toggleOverview();
  1440. event.preventDefault();
  1441. }
  1442. // If auto-sliding is enabled we need to cue up
  1443. // another timeout
  1444. cueAutoSlide();
  1445. }
  1446. /**
  1447. * Handler for the 'touchstart' event, enables support for
  1448. * swipe and pinch gestures.
  1449. */
  1450. function onTouchStart( event ) {
  1451. touch.startX = event.touches[0].clientX;
  1452. touch.startY = event.touches[0].clientY;
  1453. touch.startCount = event.touches.length;
  1454. // If there's two touches we need to memorize the distance
  1455. // between those two points to detect pinching
  1456. if( event.touches.length === 2 && config.overview ) {
  1457. touch.startSpan = distanceBetween( {
  1458. x: event.touches[1].clientX,
  1459. y: event.touches[1].clientY
  1460. }, {
  1461. x: touch.startX,
  1462. y: touch.startY
  1463. } );
  1464. }
  1465. }
  1466. /**
  1467. * Handler for the 'touchmove' event.
  1468. */
  1469. function onTouchMove( event ) {
  1470. // Each touch should only trigger one action
  1471. if( !touch.handled ) {
  1472. var currentX = event.touches[0].clientX;
  1473. var currentY = event.touches[0].clientY;
  1474. // If the touch started off with two points and still has
  1475. // two active touches; test for the pinch gesture
  1476. if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
  1477. // The current distance in pixels between the two touch points
  1478. var currentSpan = distanceBetween( {
  1479. x: event.touches[1].clientX,
  1480. y: event.touches[1].clientY
  1481. }, {
  1482. x: touch.startX,
  1483. y: touch.startY
  1484. } );
  1485. // If the span is larger than the desire amount we've got
  1486. // ourselves a pinch
  1487. if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
  1488. touch.handled = true;
  1489. if( currentSpan < touch.startSpan ) {
  1490. activateOverview();
  1491. }
  1492. else {
  1493. deactivateOverview();
  1494. }
  1495. }
  1496. event.preventDefault();
  1497. }
  1498. // There was only one touch point, look for a swipe
  1499. else if( event.touches.length === 1 && touch.startCount !== 2 ) {
  1500. var deltaX = currentX - touch.startX,
  1501. deltaY = currentY - touch.startY;
  1502. if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  1503. touch.handled = true;
  1504. navigateLeft();
  1505. }
  1506. else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  1507. touch.handled = true;
  1508. navigateRight();
  1509. }
  1510. else if( deltaY > touch.threshold ) {
  1511. touch.handled = true;
  1512. navigateUp();
  1513. }
  1514. else if( deltaY < -touch.threshold ) {
  1515. touch.handled = true;
  1516. navigateDown();
  1517. }
  1518. event.preventDefault();
  1519. }
  1520. }
  1521. // There's a bug with swiping on some Android devices unless
  1522. // the default action is always prevented
  1523. else if( navigator.userAgent.match( /android/gi ) ) {
  1524. event.preventDefault();
  1525. }
  1526. }
  1527. /**
  1528. * Handler for the 'touchend' event.
  1529. */
  1530. function onTouchEnd( event ) {
  1531. touch.handled = false;
  1532. }
  1533. /**
  1534. * Convert pointer down to touch start.
  1535. */
  1536. function onPointerDown( event ) {
  1537. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  1538. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  1539. onTouchStart( event );
  1540. }
  1541. }
  1542. /**
  1543. * Convert pointer move to touch move.
  1544. */
  1545. function onPointerMove( event ) {
  1546. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  1547. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  1548. onTouchMove( event );
  1549. }
  1550. }
  1551. /**
  1552. * Convert pointer up to touch end.
  1553. */
  1554. function onPointerUp( event ) {
  1555. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  1556. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  1557. onTouchEnd( event );
  1558. }
  1559. }
  1560. /**
  1561. * Handles mouse wheel scrolling, throttled to avoid skipping
  1562. * multiple slides.
  1563. */
  1564. function onDocumentMouseScroll( event ) {
  1565. clearTimeout( mouseWheelTimeout );
  1566. mouseWheelTimeout = setTimeout( function() {
  1567. var delta = event.detail || -event.wheelDelta;
  1568. if( delta > 0 ) {
  1569. navigateNext();
  1570. }
  1571. else {
  1572. navigatePrev();
  1573. }
  1574. }, 100 );
  1575. }
  1576. /**
  1577. * Clicking on the progress bar results in a navigation to the
  1578. * closest approximate horizontal slide using this equation:
  1579. *
  1580. * ( clickX / presentationWidth ) * numberOfSlides
  1581. */
  1582. function onProgressClicked( event ) {
  1583. event.preventDefault();
  1584. var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
  1585. var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
  1586. slide( slideIndex );
  1587. }
  1588. /**
  1589. * Event handler for navigation control buttons.
  1590. */
  1591. function onNavigateLeftClicked( event ) { event.preventDefault(); navigateLeft(); }
  1592. function onNavigateRightClicked( event ) { event.preventDefault(); navigateRight(); }
  1593. function onNavigateUpClicked( event ) { event.preventDefault(); navigateUp(); }
  1594. function onNavigateDownClicked( event ) { event.preventDefault(); navigateDown(); }
  1595. function onNavigatePrevClicked( event ) { event.preventDefault(); navigatePrev(); }
  1596. function onNavigateNextClicked( event ) { event.preventDefault(); navigateNext(); }
  1597. /**
  1598. * Handler for the window level 'hashchange' event.
  1599. */
  1600. function onWindowHashChange( event ) {
  1601. readURL();
  1602. }
  1603. /**
  1604. * Handler for the window level 'resize' event.
  1605. */
  1606. function onWindowResize( event ) {
  1607. layout();
  1608. }
  1609. /**
  1610. * Invoked when a slide is and we're in the overview.
  1611. */
  1612. function onOverviewSlideClicked( event ) {
  1613. // TODO There's a bug here where the event listeners are not
  1614. // removed after deactivating the overview.
  1615. if( eventsAreBound && isOverview() ) {
  1616. event.preventDefault();
  1617. var element = event.target;
  1618. while( element && !element.nodeName.match( /section/gi ) ) {
  1619. element = element.parentNode;
  1620. }
  1621. if( element && !element.classList.contains( 'disabled' ) ) {
  1622. deactivateOverview();
  1623. if( element.nodeName.match( /section/gi ) ) {
  1624. var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
  1625. v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
  1626. slide( h, v );
  1627. }
  1628. }
  1629. }
  1630. }
  1631. // --------------------------------------------------------------------//
  1632. // ------------------------------- API --------------------------------//
  1633. // --------------------------------------------------------------------//
  1634. return {
  1635. initialize: initialize,
  1636. configure: configure,
  1637. sync: sync,
  1638. // Navigation methods
  1639. slide: slide,
  1640. left: navigateLeft,
  1641. right: navigateRight,
  1642. up: navigateUp,
  1643. down: navigateDown,
  1644. prev: navigatePrev,
  1645. next: navigateNext,
  1646. prevFragment: previousFragment,
  1647. nextFragment: nextFragment,
  1648. // Deprecated aliases
  1649. navigateTo: slide,
  1650. navigateLeft: navigateLeft,
  1651. navigateRight: navigateRight,
  1652. navigateUp: navigateUp,
  1653. navigateDown: navigateDown,
  1654. navigatePrev: navigatePrev,
  1655. navigateNext: navigateNext,
  1656. // Forces an update in slide layout
  1657. layout: layout,
  1658. // Returns an object with the available routes as booleans (left/right/top/bottom)
  1659. availableRoutes: availableRoutes,
  1660. // Returns an object with the available fragments as booleans (prev/next)
  1661. availableFragments: availableFragments,
  1662. // Toggles the overview mode on/off
  1663. toggleOverview: toggleOverview,
  1664. // Toggles the "black screen" mode on/off
  1665. togglePause: togglePause,
  1666. // State checks
  1667. isOverview: isOverview,
  1668. isPaused: isPaused,
  1669. // Adds or removes all internal event listeners (such as keyboard)
  1670. addEventListeners: addEventListeners,
  1671. removeEventListeners: removeEventListeners,
  1672. // Returns the indices of the current, or specified, slide
  1673. getIndices: getIndices,
  1674. // Returns the slide at the specified index, y is optional
  1675. getSlide: function( x, y ) {
  1676. var horizontalSlide = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
  1677. var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
  1678. if( typeof y !== 'undefined' ) {
  1679. return verticalSlides ? verticalSlides[ y ] : undefined;
  1680. }
  1681. return horizontalSlide;
  1682. },
  1683. // Returns the previous slide element, may be null
  1684. getPreviousSlide: function() {
  1685. return previousSlide;
  1686. },
  1687. // Returns the current slide element
  1688. getCurrentSlide: function() {
  1689. return currentSlide;
  1690. },
  1691. // Returns the current scale of the presentation content
  1692. getScale: function() {
  1693. return scale;
  1694. },
  1695. // Returns the current configuration object
  1696. getConfig: function() {
  1697. return config;
  1698. },
  1699. // Helper method, retrieves query string as a key/value hash
  1700. getQueryHash: function() {
  1701. var query = {};
  1702. location.search.replace( /[A-Z0-9]+?=(\w*)/gi, function(a) {
  1703. query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
  1704. } );
  1705. return query;
  1706. },
  1707. // Returns true if we're currently on the first slide
  1708. isFirstSlide: function() {
  1709. return document.querySelector( SLIDES_SELECTOR + '.past' ) == null ? true : false;
  1710. },
  1711. // Returns true if we're currently on the last slide
  1712. isLastSlide: function() {
  1713. if( currentSlide && currentSlide.classList.contains( '.stack' ) ) {
  1714. return currentSlide.querySelector( SLIDES_SELECTOR + '.future' ) == null ? true : false;
  1715. }
  1716. else {
  1717. return document.querySelector( SLIDES_SELECTOR + '.future' ) == null ? true : false;
  1718. }
  1719. },
  1720. // Forward event binding to the reveal DOM element
  1721. addEventListener: function( type, listener, useCapture ) {
  1722. if( 'addEventListener' in window ) {
  1723. ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
  1724. }
  1725. },
  1726. removeEventListener: function( type, listener, useCapture ) {
  1727. if( 'addEventListener' in window ) {
  1728. ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
  1729. }
  1730. }
  1731. };
  1732. })();