reveal.js 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174
  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. htransform = 'translateZ(-2500px) translate(' + ( ( i - indexh ) * 105 ) + '%, 0%)';
  613. hslide.setAttribute( 'data-index-h', i );
  614. hslide.style.display = 'block';
  615. hslide.style.WebkitTransform = htransform;
  616. hslide.style.MozTransform = htransform;
  617. hslide.style.msTransform = htransform;
  618. hslide.style.OTransform = htransform;
  619. hslide.style.transform = htransform;
  620. if( hslide.classList.contains( 'stack' ) ) {
  621. var verticalSlides = hslide.querySelectorAll( 'section' );
  622. for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
  623. var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
  624. var vslide = verticalSlides[j],
  625. vtransform = 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)';
  626. vslide.setAttribute( 'data-index-h', i );
  627. vslide.setAttribute( 'data-index-v', j );
  628. vslide.style.display = 'block';
  629. vslide.style.WebkitTransform = vtransform;
  630. vslide.style.MozTransform = vtransform;
  631. vslide.style.msTransform = vtransform;
  632. vslide.style.OTransform = vtransform;
  633. vslide.style.transform = vtransform;
  634. // Navigate to this slide on click
  635. vslide.addEventListener( 'click', onOverviewSlideClicked, true );
  636. }
  637. }
  638. else {
  639. // Navigate to this slide on click
  640. hslide.addEventListener( 'click', onOverviewSlideClicked, true );
  641. }
  642. }
  643. layout();
  644. if( !wasActive ) {
  645. // Notify observers of the overview showing
  646. dispatchEvent( 'overviewshown', {
  647. 'indexh': indexh,
  648. 'indexv': indexv,
  649. 'currentSlide': currentSlide
  650. } );
  651. }
  652. }, 10 );
  653. }
  654. }
  655. /**
  656. * Exits the slide overview and enters the currently
  657. * active slide.
  658. */
  659. function deactivateOverview() {
  660. // Only proceed if enabled in config
  661. if( config.overview ) {
  662. clearTimeout( activateOverviewTimeout );
  663. clearTimeout( deactivateOverviewTimeout );
  664. dom.wrapper.classList.remove( 'overview' );
  665. // Temporarily add a class so that transitions can do different things
  666. // depending on whether they are exiting/entering overview, or just
  667. // moving from slide to slide
  668. dom.wrapper.classList.add( 'exit-overview' );
  669. deactivateOverviewTimeout = setTimeout( function () {
  670. dom.wrapper.classList.remove( 'exit-overview' );
  671. }, 10);
  672. // Select all slides
  673. var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
  674. for( var i = 0, len = slides.length; i < len; i++ ) {
  675. var element = slides[i];
  676. element.style.display = '';
  677. // Resets all transforms to use the external styles
  678. element.style.WebkitTransform = '';
  679. element.style.MozTransform = '';
  680. element.style.msTransform = '';
  681. element.style.OTransform = '';
  682. element.style.transform = '';
  683. element.removeEventListener( 'click', onOverviewSlideClicked, true );
  684. }
  685. slide( indexh, indexv );
  686. cueAutoSlide();
  687. // Notify observers of the overview hiding
  688. dispatchEvent( 'overviewhidden', {
  689. 'indexh': indexh,
  690. 'indexv': indexv,
  691. 'currentSlide': currentSlide
  692. } );
  693. }
  694. }
  695. /**
  696. * Toggles the slide overview mode on and off.
  697. *
  698. * @param {Boolean} override Optional flag which overrides the
  699. * toggle logic and forcibly sets the desired state. True means
  700. * overview is open, false means it's closed.
  701. */
  702. function toggleOverview( override ) {
  703. if( typeof override === 'boolean' ) {
  704. override ? activateOverview() : deactivateOverview();
  705. }
  706. else {
  707. isOverview() ? deactivateOverview() : activateOverview();
  708. }
  709. }
  710. /**
  711. * Checks if the overview is currently active.
  712. *
  713. * @return {Boolean} true if the overview is active,
  714. * false otherwise
  715. */
  716. function isOverview() {
  717. return dom.wrapper.classList.contains( 'overview' );
  718. }
  719. /**
  720. * Handling the fullscreen functionality via the fullscreen API
  721. *
  722. * @see http://fullscreen.spec.whatwg.org/
  723. * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
  724. */
  725. function enterFullscreen() {
  726. var element = document.body;
  727. // Check which implementation is available
  728. var requestMethod = element.requestFullScreen ||
  729. element.webkitRequestFullscreen ||
  730. element.webkitRequestFullScreen ||
  731. element.mozRequestFullScreen ||
  732. element.msRequestFullScreen;
  733. if( requestMethod ) {
  734. requestMethod.apply( element );
  735. }
  736. }
  737. /**
  738. * Enters the paused mode which fades everything on screen to
  739. * black.
  740. */
  741. function pause() {
  742. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  743. cancelAutoSlide();
  744. dom.wrapper.classList.add( 'paused' );
  745. if( wasPaused === false ) {
  746. dispatchEvent( 'paused' );
  747. }
  748. }
  749. /**
  750. * Exits from the paused mode.
  751. */
  752. function resume() {
  753. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  754. dom.wrapper.classList.remove( 'paused' );
  755. cueAutoSlide();
  756. if( wasPaused ) {
  757. dispatchEvent( 'resumed' );
  758. }
  759. }
  760. /**
  761. * Toggles the paused mode on and off.
  762. */
  763. function togglePause() {
  764. if( isPaused() ) {
  765. resume();
  766. }
  767. else {
  768. pause();
  769. }
  770. }
  771. /**
  772. * Checks if we are currently in the paused mode.
  773. */
  774. function isPaused() {
  775. return dom.wrapper.classList.contains( 'paused' );
  776. }
  777. /**
  778. * Steps from the current point in the presentation to the
  779. * slide which matches the specified horizontal and vertical
  780. * indices.
  781. *
  782. * @param {int} h Horizontal index of the target slide
  783. * @param {int} v Vertical index of the target slide
  784. * @param {int} f Optional index of a fragment within the
  785. * target slide to activate
  786. * @param {int} o Optional origin for use in multimaster environments
  787. */
  788. function slide( h, v, f, o ) {
  789. // Remember where we were at before
  790. previousSlide = currentSlide;
  791. // Query all horizontal slides in the deck
  792. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  793. // If no vertical index is specified and the upcoming slide is a
  794. // stack, resume at its previous vertical index
  795. if( v === undefined ) {
  796. v = getPreviousVerticalIndex( horizontalSlides[ h ] );
  797. }
  798. // If we were on a vertical stack, remember what vertical index
  799. // it was on so we can resume at the same position when returning
  800. if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
  801. setPreviousVerticalIndex( previousSlide.parentNode, indexv );
  802. }
  803. // Remember the state before this slide
  804. var stateBefore = state.concat();
  805. // Reset the state array
  806. state.length = 0;
  807. var indexhBefore = indexh,
  808. indexvBefore = indexv;
  809. // Activate and transition to the new slide
  810. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
  811. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
  812. layout();
  813. // Apply the new state
  814. stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
  815. // Check if this state existed on the previous slide. If it
  816. // did, we will avoid adding it repeatedly
  817. for( var j = 0; j < stateBefore.length; j++ ) {
  818. if( stateBefore[j] === state[i] ) {
  819. stateBefore.splice( j, 1 );
  820. continue stateLoop;
  821. }
  822. }
  823. document.documentElement.classList.add( state[i] );
  824. // Dispatch custom event matching the state's name
  825. dispatchEvent( state[i] );
  826. }
  827. // Clean up the remains of the previous state
  828. while( stateBefore.length ) {
  829. document.documentElement.classList.remove( stateBefore.pop() );
  830. }
  831. // If the overview is active, re-activate it to update positions
  832. if( isOverview() ) {
  833. activateOverview();
  834. }
  835. // Update the URL hash after a delay since updating it mid-transition
  836. // is likely to cause visual lag
  837. writeURL( 1500 );
  838. // Find the current horizontal slide and any possible vertical slides
  839. // within it
  840. var currentHorizontalSlide = horizontalSlides[ indexh ],
  841. currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
  842. // Store references to the previous and current slides
  843. currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
  844. // Show fragment, if specified
  845. if( typeof f !== 'undefined' ) {
  846. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
  847. toArray( fragments ).forEach( function( fragment, indexf ) {
  848. if( indexf < f ) {
  849. fragment.classList.add( 'visible' );
  850. }
  851. else {
  852. fragment.classList.remove( 'visible' );
  853. }
  854. } );
  855. }
  856. // Dispatch an event if the slide changed
  857. if( indexh !== indexhBefore || indexv !== indexvBefore ) {
  858. dispatchEvent( 'slidechanged', {
  859. 'indexh': indexh,
  860. 'indexv': indexv,
  861. 'previousSlide': previousSlide,
  862. 'currentSlide': currentSlide,
  863. 'origin': o
  864. } );
  865. }
  866. else {
  867. // Ensure that the previous slide is never the same as the current
  868. previousSlide = null;
  869. }
  870. // Solves an edge case where the previous slide maintains the
  871. // 'present' class when navigating between adjacent vertical
  872. // stacks
  873. if( previousSlide ) {
  874. previousSlide.classList.remove( 'present' );
  875. // Reset all slides upon navigate to home
  876. // Issue: #285
  877. if ( document.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
  878. // Launch async task
  879. setTimeout( function () {
  880. var slides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
  881. for( i in slides ) {
  882. if( slides[i] ) {
  883. // Reset stack
  884. setPreviousVerticalIndex( slides[i], 0 );
  885. }
  886. }
  887. }, 0 );
  888. }
  889. }
  890. // Handle embedded content
  891. stopEmbeddedContent( previousSlide );
  892. startEmbeddedContent( currentSlide );
  893. updateControls();
  894. updateProgress();
  895. }
  896. /**
  897. * Syncs the presentation with the current DOM. Useful
  898. * when new slides or control elements are added or when
  899. * the configuration has changed.
  900. */
  901. function sync() {
  902. // Subscribe to input
  903. removeEventListeners();
  904. addEventListeners();
  905. // Force a layout to make sure the current config is accounted for
  906. layout();
  907. // Reflect the current autoSlide value
  908. autoSlide = config.autoSlide;
  909. // Start auto-sliding if it's enabled
  910. cueAutoSlide();
  911. updateControls();
  912. updateProgress();
  913. }
  914. /**
  915. * Updates one dimension of slides by showing the slide
  916. * with the specified index.
  917. *
  918. * @param {String} selector A CSS selector that will fetch
  919. * the group of slides we are working with
  920. * @param {Number} index The index of the slide that should be
  921. * shown
  922. *
  923. * @return {Number} The index of the slide that is now shown,
  924. * might differ from the passed in index if it was out of
  925. * bounds.
  926. */
  927. function updateSlides( selector, index ) {
  928. // Select all slides and convert the NodeList result to
  929. // an array
  930. var slides = toArray( document.querySelectorAll( selector ) ),
  931. slidesLength = slides.length;
  932. if( slidesLength ) {
  933. // Should the index loop?
  934. if( config.loop ) {
  935. index %= slidesLength;
  936. if( index < 0 ) {
  937. index = slidesLength + index;
  938. }
  939. }
  940. // Enforce max and minimum index bounds
  941. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  942. for( var i = 0; i < slidesLength; i++ ) {
  943. var element = slides[i];
  944. // Optimization; hide all slides that are three or more steps
  945. // away from the present slide
  946. if( isOverview() === false ) {
  947. // The distance loops so that it measures 1 between the first
  948. // and last slides
  949. var distance = Math.abs( ( index - i ) % ( slidesLength - 3 ) ) || 0;
  950. element.style.display = distance > 3 ? 'none' : 'block';
  951. }
  952. slides[i].classList.remove( 'past' );
  953. slides[i].classList.remove( 'present' );
  954. slides[i].classList.remove( 'future' );
  955. if( i < index ) {
  956. // Any element previous to index is given the 'past' class
  957. slides[i].classList.add( 'past' );
  958. }
  959. else if( i > index ) {
  960. // Any element subsequent to index is given the 'future' class
  961. slides[i].classList.add( 'future' );
  962. }
  963. // If this element contains vertical slides
  964. if( element.querySelector( 'section' ) ) {
  965. slides[i].classList.add( 'stack' );
  966. }
  967. }
  968. // Mark the current slide as present
  969. slides[index].classList.add( 'present' );
  970. // If this slide has a state associated with it, add it
  971. // onto the current state of the deck
  972. var slideState = slides[index].getAttribute( 'data-state' );
  973. if( slideState ) {
  974. state = state.concat( slideState.split( ' ' ) );
  975. }
  976. // If this slide has a data-autoslide attribtue associated use this as
  977. // autoSlide value otherwise use the global configured time
  978. var slideAutoSlide = slides[index].getAttribute( 'data-autoslide' );
  979. if( slideAutoSlide ) {
  980. autoSlide = parseInt( slideAutoSlide, 10 );
  981. }
  982. else {
  983. autoSlide = config.autoSlide;
  984. }
  985. }
  986. else {
  987. // Since there are no slides we can't be anywhere beyond the
  988. // zeroth index
  989. index = 0;
  990. }
  991. return index;
  992. }
  993. /**
  994. * Updates the progress bar to reflect the current slide.
  995. */
  996. function updateProgress() {
  997. // Update progress if enabled
  998. if( config.progress && dom.progress ) {
  999. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1000. // The number of past and total slides
  1001. var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  1002. var pastCount = 0;
  1003. // Step through all slides and count the past ones
  1004. mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
  1005. var horizontalSlide = horizontalSlides[i];
  1006. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1007. for( var j = 0; j < verticalSlides.length; j++ ) {
  1008. // Stop as soon as we arrive at the present
  1009. if( verticalSlides[j].classList.contains( 'present' ) ) {
  1010. break mainLoop;
  1011. }
  1012. pastCount++;
  1013. }
  1014. // Stop as soon as we arrive at the present
  1015. if( horizontalSlide.classList.contains( 'present' ) ) {
  1016. break;
  1017. }
  1018. // Don't count the wrapping section for vertical slides
  1019. if( horizontalSlide.classList.contains( 'stack' ) === false ) {
  1020. pastCount++;
  1021. }
  1022. }
  1023. dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px';
  1024. }
  1025. }
  1026. /**
  1027. * Updates the state of all control/navigation arrows.
  1028. */
  1029. function updateControls() {
  1030. if ( config.controls && dom.controls ) {
  1031. var routes = availableRoutes();
  1032. var fragments = availableFragments();
  1033. // Remove the 'enabled' class from all directions
  1034. dom.controlsLeft.concat( dom.controlsRight )
  1035. .concat( dom.controlsUp )
  1036. .concat( dom.controlsDown )
  1037. .concat( dom.controlsPrev )
  1038. .concat( dom.controlsNext ).forEach( function( node ) {
  1039. node.classList.remove( 'enabled' );
  1040. node.classList.remove( 'fragmented' );
  1041. } );
  1042. // Add the 'enabled' class to the available routes
  1043. if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1044. if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1045. if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1046. if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1047. // Prev/next buttons
  1048. if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1049. if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1050. // Highlight fragment directions
  1051. if( currentSlide ) {
  1052. var isVertical = !!currentSlide.parentNode.nodeName.match( /section/gi );
  1053. // Always apply fragment decorator to prev/next buttons
  1054. if( fragments.prev ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1055. if( fragments.next ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1056. // Apply fragment decorators to directional buttons based on
  1057. // what slide axis they are in
  1058. if( isVertical ) {
  1059. if( fragments.prev ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1060. if( fragments.next ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1061. }
  1062. else {
  1063. if( fragments.prev ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1064. if( fragments.next ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1065. }
  1066. }
  1067. }
  1068. }
  1069. /**
  1070. * Determine what available routes there are for navigation.
  1071. *
  1072. * @return {Object} containing four booleans: left/right/up/down
  1073. */
  1074. function availableRoutes() {
  1075. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1076. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1077. return {
  1078. left: indexh > 0 || config.loop,
  1079. right: indexh < horizontalSlides.length - 1 || config.loop,
  1080. up: indexv > 0,
  1081. down: indexv < verticalSlides.length - 1
  1082. };
  1083. }
  1084. /**
  1085. * Returns an object describing the available fragment
  1086. * directions.
  1087. *
  1088. * @return {Object} two boolean properties: prev/next
  1089. */
  1090. function availableFragments() {
  1091. if( currentSlide && config.fragments ) {
  1092. var fragments = currentSlide.querySelectorAll( '.fragment' );
  1093. var hiddenFragments = currentSlide.querySelectorAll( '.fragment:not(.visible)' );
  1094. return {
  1095. prev: fragments.length - hiddenFragments.length > 0,
  1096. next: !!hiddenFragments.length
  1097. };
  1098. }
  1099. else {
  1100. return { prev: false, next: false };
  1101. }
  1102. }
  1103. /**
  1104. * Start playback of any embedded content inside of
  1105. * the targeted slide.
  1106. */
  1107. function startEmbeddedContent( slide ) {
  1108. if( slide ) {
  1109. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1110. if( !el.hasAttribute( 'data-ignore' ) ) {
  1111. el.play();
  1112. }
  1113. } );
  1114. }
  1115. }
  1116. /**
  1117. * Stop playback of any embedded content inside of
  1118. * the targeted slide.
  1119. */
  1120. function stopEmbeddedContent( slide ) {
  1121. if( slide ) {
  1122. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1123. if( !el.hasAttribute( 'data-ignore' ) ) {
  1124. el.pause();
  1125. }
  1126. } );
  1127. }
  1128. }
  1129. /**
  1130. * Reads the current URL (hash) and navigates accordingly.
  1131. */
  1132. function readURL() {
  1133. var hash = window.location.hash;
  1134. // Attempt to parse the hash as either an index or name
  1135. var bits = hash.slice( 2 ).split( '/' ),
  1136. name = hash.replace( /#|\//gi, '' );
  1137. // If the first bit is invalid and there is a name we can
  1138. // assume that this is a named link
  1139. if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
  1140. // Find the slide with the specified name
  1141. var element = document.querySelector( '#' + name );
  1142. if( element ) {
  1143. // Find the position of the named slide and navigate to it
  1144. var indices = Reveal.getIndices( element );
  1145. slide( indices.h, indices.v );
  1146. }
  1147. // If the slide doesn't exist, navigate to the current slide
  1148. else {
  1149. slide( indexh, indexv );
  1150. }
  1151. }
  1152. else {
  1153. // Read the index components of the hash
  1154. var h = parseInt( bits[0], 10 ) || 0,
  1155. v = parseInt( bits[1], 10 ) || 0;
  1156. slide( h, v );
  1157. }
  1158. }
  1159. /**
  1160. * Updates the page URL (hash) to reflect the current
  1161. * state.
  1162. *
  1163. * @param {Number} delay The time in ms to wait before
  1164. * writing the hash
  1165. */
  1166. function writeURL( delay ) {
  1167. if( config.history ) {
  1168. // Make sure there's never more than one timeout running
  1169. clearTimeout( writeURLTimeout );
  1170. // If a delay is specified, timeout this call
  1171. if( typeof delay === 'number' ) {
  1172. writeURLTimeout = setTimeout( writeURL, delay );
  1173. }
  1174. else {
  1175. var url = '/';
  1176. // If the current slide has an ID, use that as a named link
  1177. if( currentSlide && typeof currentSlide.getAttribute( 'id' ) === 'string' ) {
  1178. url = '/' + currentSlide.getAttribute( 'id' );
  1179. }
  1180. // Otherwise use the /h/v index
  1181. else {
  1182. if( indexh > 0 || indexv > 0 ) url += indexh;
  1183. if( indexv > 0 ) url += '/' + indexv;
  1184. }
  1185. window.location.hash = url;
  1186. }
  1187. }
  1188. }
  1189. /**
  1190. * Retrieves the h/v location of the current, or specified,
  1191. * slide.
  1192. *
  1193. * @param {HTMLElement} slide If specified, the returned
  1194. * index will be for this slide rather than the currently
  1195. * active one
  1196. *
  1197. * @return {Object} { h: <int>, v: <int>, f: <int> }
  1198. */
  1199. function getIndices( slide ) {
  1200. // By default, return the current indices
  1201. var h = indexh,
  1202. v = indexv,
  1203. f;
  1204. // If a slide is specified, return the indices of that slide
  1205. if( slide ) {
  1206. var isVertical = !!slide.parentNode.nodeName.match( /section/gi );
  1207. var slideh = isVertical ? slide.parentNode : slide;
  1208. // Select all horizontal slides
  1209. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1210. // Now that we know which the horizontal slide is, get its index
  1211. h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
  1212. // If this is a vertical slide, grab the vertical index
  1213. if( isVertical ) {
  1214. v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
  1215. }
  1216. }
  1217. if( !slide && currentSlide ) {
  1218. var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
  1219. if( visibleFragments.length ) {
  1220. f = visibleFragments.length;
  1221. }
  1222. }
  1223. return { h: h, v: v, f: f };
  1224. }
  1225. /**
  1226. * Navigate to the next slide fragment.
  1227. *
  1228. * @return {Boolean} true if there was a next fragment,
  1229. * false otherwise
  1230. */
  1231. function nextFragment() {
  1232. if( currentSlide && config.fragments ) {
  1233. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment:not(.visible)' ) );
  1234. if( fragments.length ) {
  1235. fragments[0].classList.add( 'visible' );
  1236. // Notify subscribers of the change
  1237. dispatchEvent( 'fragmentshown', { fragment: fragments[0] } );
  1238. updateControls();
  1239. return true;
  1240. }
  1241. }
  1242. return false;
  1243. }
  1244. /**
  1245. * Navigate to the previous slide fragment.
  1246. *
  1247. * @return {Boolean} true if there was a previous fragment,
  1248. * false otherwise
  1249. */
  1250. function previousFragment() {
  1251. if( currentSlide && config.fragments ) {
  1252. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) );
  1253. if( fragments.length ) {
  1254. fragments[ fragments.length - 1 ].classList.remove( 'visible' );
  1255. // Notify subscribers of the change
  1256. dispatchEvent( 'fragmenthidden', { fragment: fragments[ fragments.length - 1 ] } );
  1257. updateControls();
  1258. return true;
  1259. }
  1260. }
  1261. return false;
  1262. }
  1263. /**
  1264. * Cues a new automated slide if enabled in the config.
  1265. */
  1266. function cueAutoSlide() {
  1267. clearTimeout( autoSlideTimeout );
  1268. // Cue the next auto-slide if enabled
  1269. if( autoSlide && !isPaused() && !isOverview() ) {
  1270. autoSlideTimeout = setTimeout( navigateNext, autoSlide );
  1271. }
  1272. }
  1273. /**
  1274. * Cancels any ongoing request to auto-slide.
  1275. */
  1276. function cancelAutoSlide() {
  1277. clearTimeout( autoSlideTimeout );
  1278. }
  1279. function navigateLeft() {
  1280. // Prioritize hiding fragments
  1281. if( ( isOverview() || previousFragment() === false ) && availableRoutes().left ) {
  1282. slide( indexh - 1 );
  1283. }
  1284. }
  1285. function navigateRight() {
  1286. // Prioritize revealing fragments
  1287. if( ( isOverview() || nextFragment() === false ) && availableRoutes().right ) {
  1288. slide( indexh + 1 );
  1289. }
  1290. }
  1291. function navigateUp() {
  1292. // Prioritize hiding fragments
  1293. if( ( isOverview() || previousFragment() === false ) && availableRoutes().up ) {
  1294. slide( indexh, indexv - 1 );
  1295. }
  1296. }
  1297. function navigateDown() {
  1298. // Prioritize revealing fragments
  1299. if( ( isOverview() || nextFragment() === false ) && availableRoutes().down ) {
  1300. slide( indexh, indexv + 1 );
  1301. }
  1302. }
  1303. /**
  1304. * Navigates backwards, prioritized in the following order:
  1305. * 1) Previous fragment
  1306. * 2) Previous vertical slide
  1307. * 3) Previous horizontal slide
  1308. */
  1309. function navigatePrev() {
  1310. // Prioritize revealing fragments
  1311. if( previousFragment() === false ) {
  1312. if( availableRoutes().up ) {
  1313. navigateUp();
  1314. }
  1315. else {
  1316. // Fetch the previous horizontal slide, if there is one
  1317. var previousSlide = document.querySelector( HORIZONTAL_SLIDES_SELECTOR + '.past:nth-child(' + indexh + ')' );
  1318. if( previousSlide ) {
  1319. indexv = ( previousSlide.querySelectorAll( 'section' ).length + 1 ) || undefined;
  1320. indexh --;
  1321. slide( indexh, indexv );
  1322. }
  1323. }
  1324. }
  1325. }
  1326. /**
  1327. * Same as #navigatePrev() but navigates forwards.
  1328. */
  1329. function navigateNext() {
  1330. // Prioritize revealing fragments
  1331. if( nextFragment() === false ) {
  1332. availableRoutes().down ? navigateDown() : navigateRight();
  1333. }
  1334. // If auto-sliding is enabled we need to cue up
  1335. // another timeout
  1336. cueAutoSlide();
  1337. }
  1338. // --------------------------------------------------------------------//
  1339. // ----------------------------- EVENTS -------------------------------//
  1340. // --------------------------------------------------------------------//
  1341. /**
  1342. * Handler for the document level 'keydown' event.
  1343. *
  1344. * @param {Object} event
  1345. */
  1346. function onDocumentKeyDown( event ) {
  1347. // Check if there's a focused element that could be using
  1348. // the keyboard
  1349. var activeElement = document.activeElement;
  1350. var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) );
  1351. // Disregard the event if there's a focused element or a
  1352. // keyboard modifier key is present
  1353. if( hasFocus || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
  1354. var triggered = true;
  1355. // while paused only allow "unpausing" keyboard events (b and .)
  1356. if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) {
  1357. return false;
  1358. }
  1359. switch( event.keyCode ) {
  1360. // p, page up
  1361. case 80: case 33: navigatePrev(); break;
  1362. // n, page down
  1363. case 78: case 34: navigateNext(); break;
  1364. // h, left
  1365. case 72: case 37: navigateLeft(); break;
  1366. // l, right
  1367. case 76: case 39: navigateRight(); break;
  1368. // k, up
  1369. case 75: case 38: navigateUp(); break;
  1370. // j, down
  1371. case 74: case 40: navigateDown(); break;
  1372. // home
  1373. case 36: slide( 0 ); break;
  1374. // end
  1375. case 35: slide( Number.MAX_VALUE ); break;
  1376. // space
  1377. case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
  1378. // return
  1379. case 13: isOverview() ? deactivateOverview() : triggered = false; break;
  1380. // b, period, Logitech presenter tools "black screen" button
  1381. case 66: case 190: case 191: togglePause(); break;
  1382. // f
  1383. case 70: enterFullscreen(); break;
  1384. default:
  1385. triggered = false;
  1386. }
  1387. // If the input resulted in a triggered action we should prevent
  1388. // the browsers default behavior
  1389. if( triggered ) {
  1390. event.preventDefault();
  1391. }
  1392. else if ( event.keyCode === 27 && supports3DTransforms ) {
  1393. toggleOverview();
  1394. event.preventDefault();
  1395. }
  1396. // If auto-sliding is enabled we need to cue up
  1397. // another timeout
  1398. cueAutoSlide();
  1399. }
  1400. /**
  1401. * Handler for the 'touchstart' event, enables support for
  1402. * swipe and pinch gestures.
  1403. */
  1404. function onTouchStart( event ) {
  1405. touch.startX = event.touches[0].clientX;
  1406. touch.startY = event.touches[0].clientY;
  1407. touch.startCount = event.touches.length;
  1408. // If there's two touches we need to memorize the distance
  1409. // between those two points to detect pinching
  1410. if( event.touches.length === 2 && config.overview ) {
  1411. touch.startSpan = distanceBetween( {
  1412. x: event.touches[1].clientX,
  1413. y: event.touches[1].clientY
  1414. }, {
  1415. x: touch.startX,
  1416. y: touch.startY
  1417. } );
  1418. }
  1419. }
  1420. /**
  1421. * Handler for the 'touchmove' event.
  1422. */
  1423. function onTouchMove( event ) {
  1424. // Each touch should only trigger one action
  1425. if( !touch.handled ) {
  1426. var currentX = event.touches[0].clientX;
  1427. var currentY = event.touches[0].clientY;
  1428. // If the touch started off with two points and still has
  1429. // two active touches; test for the pinch gesture
  1430. if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
  1431. // The current distance in pixels between the two touch points
  1432. var currentSpan = distanceBetween( {
  1433. x: event.touches[1].clientX,
  1434. y: event.touches[1].clientY
  1435. }, {
  1436. x: touch.startX,
  1437. y: touch.startY
  1438. } );
  1439. // If the span is larger than the desire amount we've got
  1440. // ourselves a pinch
  1441. if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
  1442. touch.handled = true;
  1443. if( currentSpan < touch.startSpan ) {
  1444. activateOverview();
  1445. }
  1446. else {
  1447. deactivateOverview();
  1448. }
  1449. }
  1450. event.preventDefault();
  1451. }
  1452. // There was only one touch point, look for a swipe
  1453. else if( event.touches.length === 1 && touch.startCount !== 2 ) {
  1454. var deltaX = currentX - touch.startX,
  1455. deltaY = currentY - touch.startY;
  1456. if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  1457. touch.handled = true;
  1458. navigateLeft();
  1459. }
  1460. else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  1461. touch.handled = true;
  1462. navigateRight();
  1463. }
  1464. else if( deltaY > touch.threshold ) {
  1465. touch.handled = true;
  1466. navigateUp();
  1467. }
  1468. else if( deltaY < -touch.threshold ) {
  1469. touch.handled = true;
  1470. navigateDown();
  1471. }
  1472. event.preventDefault();
  1473. }
  1474. }
  1475. // There's a bug with swiping on some Android devices unless
  1476. // the default action is always prevented
  1477. else if( navigator.userAgent.match( /android/gi ) ) {
  1478. event.preventDefault();
  1479. }
  1480. }
  1481. /**
  1482. * Handler for the 'touchend' event.
  1483. */
  1484. function onTouchEnd( event ) {
  1485. touch.handled = false;
  1486. }
  1487. /**
  1488. * Convert pointer down to touch start.
  1489. */
  1490. function onPointerDown( event ) {
  1491. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  1492. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  1493. onTouchStart( event );
  1494. }
  1495. }
  1496. /**
  1497. * Convert pointer move to touch move.
  1498. */
  1499. function onPointerMove( event ) {
  1500. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  1501. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  1502. onTouchMove( event );
  1503. }
  1504. }
  1505. /**
  1506. * Convert pointer up to touch end.
  1507. */
  1508. function onPointerUp( event ) {
  1509. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  1510. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  1511. onTouchEnd( event );
  1512. }
  1513. }
  1514. /**
  1515. * Handles mouse wheel scrolling, throttled to avoid skipping
  1516. * multiple slides.
  1517. */
  1518. function onDocumentMouseScroll( event ) {
  1519. clearTimeout( mouseWheelTimeout );
  1520. mouseWheelTimeout = setTimeout( function() {
  1521. var delta = event.detail || -event.wheelDelta;
  1522. if( delta > 0 ) {
  1523. navigateNext();
  1524. }
  1525. else {
  1526. navigatePrev();
  1527. }
  1528. }, 100 );
  1529. }
  1530. /**
  1531. * Clicking on the progress bar results in a navigation to the
  1532. * closest approximate horizontal slide using this equation:
  1533. *
  1534. * ( clickX / presentationWidth ) * numberOfSlides
  1535. */
  1536. function onProgressClicked( event ) {
  1537. event.preventDefault();
  1538. var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
  1539. var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
  1540. slide( slideIndex );
  1541. }
  1542. /**
  1543. * Event handler for navigation control buttons.
  1544. */
  1545. function onNavigateLeftClicked( event ) { event.preventDefault(); navigateLeft(); }
  1546. function onNavigateRightClicked( event ) { event.preventDefault(); navigateRight(); }
  1547. function onNavigateUpClicked( event ) { event.preventDefault(); navigateUp(); }
  1548. function onNavigateDownClicked( event ) { event.preventDefault(); navigateDown(); }
  1549. function onNavigatePrevClicked( event ) { event.preventDefault(); navigatePrev(); }
  1550. function onNavigateNextClicked( event ) { event.preventDefault(); navigateNext(); }
  1551. /**
  1552. * Handler for the window level 'hashchange' event.
  1553. */
  1554. function onWindowHashChange( event ) {
  1555. readURL();
  1556. }
  1557. /**
  1558. * Handler for the window level 'resize' event.
  1559. */
  1560. function onWindowResize( event ) {
  1561. layout();
  1562. }
  1563. /**
  1564. * Invoked when a slide is and we're in the overview.
  1565. */
  1566. function onOverviewSlideClicked( event ) {
  1567. // TODO There's a bug here where the event listeners are not
  1568. // removed after deactivating the overview.
  1569. if( eventsAreBound && isOverview() ) {
  1570. event.preventDefault();
  1571. var element = event.target;
  1572. while( element && !element.nodeName.match( /section/gi ) ) {
  1573. element = element.parentNode;
  1574. }
  1575. if( element && !element.classList.contains( 'disabled' ) ) {
  1576. deactivateOverview();
  1577. if( element.nodeName.match( /section/gi ) ) {
  1578. var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
  1579. v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
  1580. slide( h, v );
  1581. }
  1582. }
  1583. }
  1584. }
  1585. // --------------------------------------------------------------------//
  1586. // ------------------------------- API --------------------------------//
  1587. // --------------------------------------------------------------------//
  1588. return {
  1589. initialize: initialize,
  1590. configure: configure,
  1591. sync: sync,
  1592. // Navigation methods
  1593. slide: slide,
  1594. left: navigateLeft,
  1595. right: navigateRight,
  1596. up: navigateUp,
  1597. down: navigateDown,
  1598. prev: navigatePrev,
  1599. next: navigateNext,
  1600. prevFragment: previousFragment,
  1601. nextFragment: nextFragment,
  1602. // Deprecated aliases
  1603. navigateTo: slide,
  1604. navigateLeft: navigateLeft,
  1605. navigateRight: navigateRight,
  1606. navigateUp: navigateUp,
  1607. navigateDown: navigateDown,
  1608. navigatePrev: navigatePrev,
  1609. navigateNext: navigateNext,
  1610. // Forces an update in slide layout
  1611. layout: layout,
  1612. // Returns an object with the available routes as booleans (left/right/top/bottom)
  1613. availableRoutes: availableRoutes,
  1614. // Returns an object with the available fragments as booleans (prev/next)
  1615. availableFragments: availableFragments,
  1616. // Toggles the overview mode on/off
  1617. toggleOverview: toggleOverview,
  1618. // Toggles the "black screen" mode on/off
  1619. togglePause: togglePause,
  1620. // State checks
  1621. isOverview: isOverview,
  1622. isPaused: isPaused,
  1623. // Adds or removes all internal event listeners (such as keyboard)
  1624. addEventListeners: addEventListeners,
  1625. removeEventListeners: removeEventListeners,
  1626. // Returns the indices of the current, or specified, slide
  1627. getIndices: getIndices,
  1628. // Returns the slide at the specified index, y is optional
  1629. getSlide: function( x, y ) {
  1630. var horizontalSlide = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
  1631. var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
  1632. if( typeof y !== 'undefined' ) {
  1633. return verticalSlides ? verticalSlides[ y ] : undefined;
  1634. }
  1635. return horizontalSlide;
  1636. },
  1637. // Returns the previous slide element, may be null
  1638. getPreviousSlide: function() {
  1639. return previousSlide;
  1640. },
  1641. // Returns the current slide element
  1642. getCurrentSlide: function() {
  1643. return currentSlide;
  1644. },
  1645. // Returns the current scale of the presentation content
  1646. getScale: function() {
  1647. return scale;
  1648. },
  1649. // Returns the current configuration object
  1650. getConfig: function() {
  1651. return config;
  1652. },
  1653. // Helper method, retrieves query string as a key/value hash
  1654. getQueryHash: function() {
  1655. var query = {};
  1656. location.search.replace( /[A-Z0-9]+?=(\w*)/gi, function(a) {
  1657. query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
  1658. } );
  1659. return query;
  1660. },
  1661. // Returns true if we're currently on the first slide
  1662. isFirstSlide: function() {
  1663. return document.querySelector( SLIDES_SELECTOR + '.past' ) == null ? true : false;
  1664. },
  1665. // Returns true if we're currently on the last slide
  1666. isLastSlide: function() {
  1667. if( currentSlide && currentSlide.classList.contains( '.stack' ) ) {
  1668. return currentSlide.querySelector( SLIDES_SELECTOR + '.future' ) == null ? true : false;
  1669. }
  1670. else {
  1671. return document.querySelector( SLIDES_SELECTOR + '.future' ) == null ? true : false;
  1672. }
  1673. },
  1674. // Forward event binding to the reveal DOM element
  1675. addEventListener: function( type, listener, useCapture ) {
  1676. if( 'addEventListener' in window ) {
  1677. ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
  1678. }
  1679. },
  1680. removeEventListener: function( type, listener, useCapture ) {
  1681. if( 'addEventListener' in window ) {
  1682. ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
  1683. }
  1684. }
  1685. };
  1686. })();