reveal.js 60 KB

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