reveal.js 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843
  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. // Flags if the presentation is running in an embedded mode,
  46. // i.e. contained within a limited portion of the screen
  47. embedded: false,
  48. // Number of milliseconds between automatically proceeding to the
  49. // next slide, disabled when set to 0, this value can be overwritten
  50. // by using a data-autoslide attribute on your slides
  51. autoSlide: 0,
  52. // Enable slide navigation via mouse wheel
  53. mouseWheel: false,
  54. // Apply a 3D roll to links on hover
  55. rollingLinks: false,
  56. // Hides the address bar on mobile devices
  57. hideAddressBar: true,
  58. // Opens links in an iframe preview overlay
  59. previewLinks: false,
  60. // Theme (see /css/theme)
  61. theme: null,
  62. // Transition style
  63. transition: 'default', // default/cube/page/concave/zoom/linear/fade/none
  64. // Transition speed
  65. transitionSpeed: 'default', // default/fast/slow
  66. // Transition style for full page slide backgrounds
  67. backgroundTransition: 'default', // default/linear/none
  68. // Parallax background image
  69. parallaxBackgroundImage: '', // CSS syntax, e.g. "a.jpg"
  70. // Parallax background size
  71. parallaxBackgroundSize: '', // CSS syntax, e.g. "3000px 2000px"
  72. // Number of slides away from the current that are visible
  73. viewDistance: 3,
  74. // Script dependencies to load
  75. dependencies: []
  76. },
  77. // Flags if reveal.js is loaded (has dispatched the 'ready' event)
  78. loaded = false,
  79. // The current auto-slide duration
  80. autoSlide = 0,
  81. // The horizontal and vertical index of the currently active slide
  82. indexh,
  83. indexv,
  84. // The previous and current slide HTML elements
  85. previousSlide,
  86. currentSlide,
  87. // Slides may hold a data-state attribute which we pick up and apply
  88. // as a class to the body. This list contains the combined state of
  89. // all current slides.
  90. state = [],
  91. // The current scale of the presentation (see width/height config)
  92. scale = 1,
  93. // Cached references to DOM elements
  94. dom = {},
  95. // Client support for CSS 3D transforms, see #checkCapabilities()
  96. supports3DTransforms,
  97. // Client support for CSS 2D transforms, see #checkCapabilities()
  98. supports2DTransforms,
  99. // Client is a mobile device, see #checkCapabilities()
  100. isMobileDevice,
  101. // Throttles mouse wheel navigation
  102. lastMouseWheelStep = 0,
  103. // An interval used to automatically move on to the next slide
  104. autoSlideTimeout = 0,
  105. // Delays updates to the URL due to a Chrome thumbnailer bug
  106. writeURLTimeout = 0,
  107. // A delay used to activate the overview mode
  108. activateOverviewTimeout = 0,
  109. // A delay used to deactivate the overview mode
  110. deactivateOverviewTimeout = 0,
  111. // Flags if the interaction event listeners are bound
  112. eventsAreBound = false,
  113. // Holds information about the currently ongoing touch input
  114. touch = {
  115. startX: 0,
  116. startY: 0,
  117. startSpan: 0,
  118. startCount: 0,
  119. captured: false,
  120. threshold: 40
  121. };
  122. /**
  123. * Starts up the presentation if the client is capable.
  124. */
  125. function initialize( options ) {
  126. checkCapabilities();
  127. if( !supports2DTransforms && !supports3DTransforms ) {
  128. document.body.setAttribute( 'class', 'no-transforms' );
  129. // If the browser doesn't support core features we won't be
  130. // using JavaScript to control the presentation
  131. return;
  132. }
  133. // Force a layout when the whole page, incl fonts, has loaded
  134. window.addEventListener( 'load', layout, false );
  135. // Copy options over to our config object
  136. extend( config, options );
  137. // Hide the address bar in mobile browsers
  138. hideAddressBar();
  139. // Loads the dependencies and continues to #start() once done
  140. load();
  141. }
  142. /**
  143. * Inspect the client to see what it's capable of, this
  144. * should only happens once per runtime.
  145. */
  146. function checkCapabilities() {
  147. supports3DTransforms = 'WebkitPerspective' in document.body.style ||
  148. 'MozPerspective' in document.body.style ||
  149. 'msPerspective' in document.body.style ||
  150. 'OPerspective' in document.body.style ||
  151. 'perspective' in document.body.style;
  152. supports2DTransforms = 'WebkitTransform' in document.body.style ||
  153. 'MozTransform' in document.body.style ||
  154. 'msTransform' in document.body.style ||
  155. 'OTransform' in document.body.style ||
  156. 'transform' in document.body.style;
  157. isMobileDevice = navigator.userAgent.match( /(iphone|ipod|android)/gi );
  158. }
  159. /**
  160. * Loads the dependencies of reveal.js. Dependencies are
  161. * defined via the configuration option 'dependencies'
  162. * and will be loaded prior to starting/binding reveal.js.
  163. * Some dependencies may have an 'async' flag, if so they
  164. * will load after reveal.js has been started up.
  165. */
  166. function load() {
  167. var scripts = [],
  168. scriptsAsync = [];
  169. for( var i = 0, len = config.dependencies.length; i < len; i++ ) {
  170. var s = config.dependencies[i];
  171. // Load if there's no condition or the condition is truthy
  172. if( !s.condition || s.condition() ) {
  173. if( s.async ) {
  174. scriptsAsync.push( s.src );
  175. }
  176. else {
  177. scripts.push( s.src );
  178. }
  179. // Extension may contain callback functions
  180. if( typeof s.callback === 'function' ) {
  181. head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], s.callback );
  182. }
  183. }
  184. }
  185. // Called once synchronous scripts finish loading
  186. function proceed() {
  187. if( scriptsAsync.length ) {
  188. // Load asynchronous scripts
  189. head.js.apply( null, scriptsAsync );
  190. }
  191. start();
  192. }
  193. if( scripts.length ) {
  194. head.ready( proceed );
  195. // Load synchronous scripts
  196. head.js.apply( null, scripts );
  197. }
  198. else {
  199. proceed();
  200. }
  201. }
  202. /**
  203. * Starts up reveal.js by binding input events and navigating
  204. * to the current URL deeplink if there is one.
  205. */
  206. function start() {
  207. // Make sure we've got all the DOM elements we need
  208. setupDOM();
  209. // Decorate the slide DOM elements with state classes (past/future)
  210. setupSlides();
  211. // Updates the presentation to match the current configuration values
  212. configure();
  213. // Read the initial hash
  214. readURL();
  215. // Notify listeners that the presentation is ready but use a 1ms
  216. // timeout to ensure it's not fired synchronously after #initialize()
  217. setTimeout( function() {
  218. // Enable transitions now that we're loaded
  219. dom.slides.classList.remove( 'no-transition' );
  220. loaded = true;
  221. dispatchEvent( 'ready', {
  222. 'indexh': indexh,
  223. 'indexv': indexv,
  224. 'currentSlide': currentSlide
  225. } );
  226. }, 1 );
  227. }
  228. /**
  229. * Iterates through and decorates slides DOM elements with
  230. * appropriate classes.
  231. */
  232. function setupSlides() {
  233. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  234. horizontalSlides.forEach( function( horizontalSlide ) {
  235. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  236. verticalSlides.forEach( function( verticalSlide, y ) {
  237. if( y > 0 ) verticalSlide.classList.add( 'future' );
  238. } );
  239. } );
  240. }
  241. /**
  242. * Finds and stores references to DOM elements which are
  243. * required by the presentation. If a required element is
  244. * not found, it is created.
  245. */
  246. function setupDOM() {
  247. // Cache references to key DOM elements
  248. dom.theme = document.querySelector( '#theme' );
  249. dom.wrapper = document.querySelector( '.reveal' );
  250. dom.slides = document.querySelector( '.reveal .slides' );
  251. // Prevent transitions while we're loading
  252. dom.slides.classList.add( 'no-transition' );
  253. // Background element
  254. dom.background = createSingletonNode( dom.wrapper, 'div', 'backgrounds', null );
  255. // Progress bar
  256. dom.progress = createSingletonNode( dom.wrapper, 'div', 'progress', '<span></span>' );
  257. dom.progressbar = dom.progress.querySelector( 'span' );
  258. // Arrow controls
  259. createSingletonNode( dom.wrapper, 'aside', 'controls',
  260. '<div class="navigate-left"></div>' +
  261. '<div class="navigate-right"></div>' +
  262. '<div class="navigate-up"></div>' +
  263. '<div class="navigate-down"></div>' );
  264. // State background element [DEPRECATED]
  265. createSingletonNode( dom.wrapper, 'div', 'state-background', null );
  266. // Overlay graphic which is displayed during the paused mode
  267. createSingletonNode( dom.wrapper, 'div', 'pause-overlay', null );
  268. // Cache references to elements
  269. dom.controls = document.querySelector( '.reveal .controls' );
  270. // There can be multiple instances of controls throughout the page
  271. dom.controlsLeft = toArray( document.querySelectorAll( '.navigate-left' ) );
  272. dom.controlsRight = toArray( document.querySelectorAll( '.navigate-right' ) );
  273. dom.controlsUp = toArray( document.querySelectorAll( '.navigate-up' ) );
  274. dom.controlsDown = toArray( document.querySelectorAll( '.navigate-down' ) );
  275. dom.controlsPrev = toArray( document.querySelectorAll( '.navigate-prev' ) );
  276. dom.controlsNext = toArray( document.querySelectorAll( '.navigate-next' ) );
  277. }
  278. /**
  279. * Creates an HTML element and returns a reference to it.
  280. * If the element already exists the existing instance will
  281. * be returned.
  282. */
  283. function createSingletonNode( container, tagname, classname, innerHTML ) {
  284. var node = container.querySelector( '.' + classname );
  285. if( !node ) {
  286. node = document.createElement( tagname );
  287. node.classList.add( classname );
  288. if( innerHTML !== null ) {
  289. node.innerHTML = innerHTML;
  290. }
  291. container.appendChild( node );
  292. }
  293. return node;
  294. }
  295. /**
  296. * Creates the slide background elements and appends them
  297. * to the background container. One element is created per
  298. * slide no matter if the given slide has visible background.
  299. */
  300. function createBackgrounds() {
  301. if( isPrintingPDF() ) {
  302. document.body.classList.add( 'print-pdf' );
  303. }
  304. // Clear prior backgrounds
  305. dom.background.innerHTML = '';
  306. dom.background.classList.add( 'no-transition' );
  307. // Helper method for creating a background element for the
  308. // given slide
  309. function _createBackground( slide, container ) {
  310. var data = {
  311. background: slide.getAttribute( 'data-background' ),
  312. backgroundSize: slide.getAttribute( 'data-background-size' ),
  313. backgroundImage: slide.getAttribute( 'data-background-image' ),
  314. backgroundColor: slide.getAttribute( 'data-background-color' ),
  315. backgroundRepeat: slide.getAttribute( 'data-background-repeat' ),
  316. backgroundPosition: slide.getAttribute( 'data-background-position' ),
  317. backgroundTransition: slide.getAttribute( 'data-background-transition' )
  318. };
  319. var element = document.createElement( 'div' );
  320. element.className = 'slide-background';
  321. if( data.background ) {
  322. // Auto-wrap image urls in url(...)
  323. if( /^(http|file|\/\/)/gi.test( data.background ) || /\.(png|jpg|jpeg|gif|bmp)$/gi.test( data.background ) ) {
  324. element.style.backgroundImage = 'url('+ data.background +')';
  325. }
  326. else {
  327. element.style.background = data.background;
  328. }
  329. }
  330. // Additional and optional background properties
  331. if( data.backgroundSize ) element.style.backgroundSize = data.backgroundSize;
  332. if( data.backgroundImage ) element.style.backgroundImage = 'url("' + data.backgroundImage + '")';
  333. if( data.backgroundColor ) element.style.backgroundColor = data.backgroundColor;
  334. if( data.backgroundRepeat ) element.style.backgroundRepeat = data.backgroundRepeat;
  335. if( data.backgroundPosition ) element.style.backgroundPosition = data.backgroundPosition;
  336. if( data.backgroundTransition ) element.setAttribute( 'data-background-transition', data.backgroundTransition );
  337. container.appendChild( element );
  338. return element;
  339. }
  340. // Iterate over all horizontal slides
  341. toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).forEach( function( slideh ) {
  342. var backgroundStack;
  343. if( isPrintingPDF() ) {
  344. backgroundStack = _createBackground( slideh, slideh );
  345. }
  346. else {
  347. backgroundStack = _createBackground( slideh, dom.background );
  348. }
  349. // Iterate over all vertical slides
  350. toArray( slideh.querySelectorAll( 'section' ) ).forEach( function( slidev ) {
  351. if( isPrintingPDF() ) {
  352. _createBackground( slidev, slidev );
  353. }
  354. else {
  355. _createBackground( slidev, backgroundStack );
  356. }
  357. } );
  358. } );
  359. // Add parallax background if specified
  360. if( config.parallaxBackgroundImage ) {
  361. dom.background.style.backgroundImage = 'url("' + config.parallaxBackgroundImage + '")';
  362. dom.background.style.backgroundSize = config.parallaxBackgroundSize;
  363. // Make sure the below properties are set on the element - these properties are
  364. // needed for proper transitions to be set on the element via CSS. To remove
  365. // annoying background slide-in effect when the presentation starts, apply
  366. // these properties after short time delay
  367. setTimeout( function() {
  368. dom.wrapper.classList.add( 'has-parallax-background' );
  369. }, 1 );
  370. }
  371. else {
  372. dom.background.style.backgroundImage = '';
  373. dom.wrapper.classList.remove( 'has-parallax-background' );
  374. }
  375. }
  376. /**
  377. * Applies the configuration settings from the config
  378. * object. May be called multiple times.
  379. */
  380. function configure( options ) {
  381. dom.wrapper.classList.remove( config.transition );
  382. // New config options may be passed when this method
  383. // is invoked through the API after initialization
  384. if( typeof options === 'object' ) extend( config, options );
  385. // Force linear transition based on browser capabilities
  386. if( supports3DTransforms === false ) config.transition = 'linear';
  387. dom.wrapper.classList.add( config.transition );
  388. dom.wrapper.setAttribute( 'data-transition-speed', config.transitionSpeed );
  389. dom.wrapper.setAttribute( 'data-background-transition', config.backgroundTransition );
  390. dom.controls.style.display = config.controls ? 'block' : 'none';
  391. dom.progress.style.display = config.progress ? 'block' : 'none';
  392. if( config.rtl ) {
  393. dom.wrapper.classList.add( 'rtl' );
  394. }
  395. else {
  396. dom.wrapper.classList.remove( 'rtl' );
  397. }
  398. if( config.center ) {
  399. dom.wrapper.classList.add( 'center' );
  400. }
  401. else {
  402. dom.wrapper.classList.remove( 'center' );
  403. }
  404. if( config.mouseWheel ) {
  405. document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  406. document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
  407. }
  408. else {
  409. document.removeEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  410. document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
  411. }
  412. // Rolling 3D links
  413. if( config.rollingLinks ) {
  414. enableRollingLinks();
  415. }
  416. else {
  417. disableRollingLinks();
  418. }
  419. // Iframe link previews
  420. if( config.previewLinks ) {
  421. enablePreviewLinks();
  422. }
  423. else {
  424. disablePreviewLinks();
  425. enablePreviewLinks( '[data-preview-link]' );
  426. }
  427. // Load the theme in the config, if it's not already loaded
  428. if( config.theme && dom.theme ) {
  429. var themeURL = dom.theme.getAttribute( 'href' );
  430. var themeFinder = /[^\/]*?(?=\.css)/;
  431. var themeName = themeURL.match(themeFinder)[0];
  432. if( config.theme !== themeName ) {
  433. themeURL = themeURL.replace(themeFinder, config.theme);
  434. dom.theme.setAttribute( 'href', themeURL );
  435. }
  436. }
  437. sync();
  438. }
  439. /**
  440. * Binds all event listeners.
  441. */
  442. function addEventListeners() {
  443. eventsAreBound = true;
  444. window.addEventListener( 'hashchange', onWindowHashChange, false );
  445. window.addEventListener( 'resize', onWindowResize, false );
  446. if( config.touch ) {
  447. dom.wrapper.addEventListener( 'touchstart', onTouchStart, false );
  448. dom.wrapper.addEventListener( 'touchmove', onTouchMove, false );
  449. dom.wrapper.addEventListener( 'touchend', onTouchEnd, false );
  450. // Support pointer-style touch interaction as well
  451. if( window.navigator.msPointerEnabled ) {
  452. dom.wrapper.addEventListener( 'MSPointerDown', onPointerDown, false );
  453. dom.wrapper.addEventListener( 'MSPointerMove', onPointerMove, false );
  454. dom.wrapper.addEventListener( 'MSPointerUp', onPointerUp, false );
  455. }
  456. }
  457. if( config.keyboard ) {
  458. document.addEventListener( 'keydown', onDocumentKeyDown, false );
  459. }
  460. if ( config.progress && dom.progress ) {
  461. dom.progress.addEventListener( 'click', onProgressClicked, false );
  462. }
  463. [ 'touchstart', 'click' ].forEach( function( eventName ) {
  464. dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } );
  465. dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } );
  466. dom.controlsUp.forEach( function( el ) { el.addEventListener( eventName, onNavigateUpClicked, false ); } );
  467. dom.controlsDown.forEach( function( el ) { el.addEventListener( eventName, onNavigateDownClicked, false ); } );
  468. dom.controlsPrev.forEach( function( el ) { el.addEventListener( eventName, onNavigatePrevClicked, false ); } );
  469. dom.controlsNext.forEach( function( el ) { el.addEventListener( eventName, onNavigateNextClicked, false ); } );
  470. } );
  471. }
  472. /**
  473. * Unbinds all event listeners.
  474. */
  475. function removeEventListeners() {
  476. eventsAreBound = false;
  477. document.removeEventListener( 'keydown', onDocumentKeyDown, false );
  478. window.removeEventListener( 'hashchange', onWindowHashChange, false );
  479. window.removeEventListener( 'resize', onWindowResize, false );
  480. dom.wrapper.removeEventListener( 'touchstart', onTouchStart, false );
  481. dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false );
  482. dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false );
  483. if( window.navigator.msPointerEnabled ) {
  484. dom.wrapper.removeEventListener( 'MSPointerDown', onPointerDown, false );
  485. dom.wrapper.removeEventListener( 'MSPointerMove', onPointerMove, false );
  486. dom.wrapper.removeEventListener( 'MSPointerUp', onPointerUp, false );
  487. }
  488. if ( config.progress && dom.progress ) {
  489. dom.progress.removeEventListener( 'click', onProgressClicked, false );
  490. }
  491. [ 'touchstart', 'click' ].forEach( function( eventName ) {
  492. dom.controlsLeft.forEach( function( el ) { el.removeEventListener( eventName, onNavigateLeftClicked, false ); } );
  493. dom.controlsRight.forEach( function( el ) { el.removeEventListener( eventName, onNavigateRightClicked, false ); } );
  494. dom.controlsUp.forEach( function( el ) { el.removeEventListener( eventName, onNavigateUpClicked, false ); } );
  495. dom.controlsDown.forEach( function( el ) { el.removeEventListener( eventName, onNavigateDownClicked, false ); } );
  496. dom.controlsPrev.forEach( function( el ) { el.removeEventListener( eventName, onNavigatePrevClicked, false ); } );
  497. dom.controlsNext.forEach( function( el ) { el.removeEventListener( eventName, onNavigateNextClicked, false ); } );
  498. } );
  499. }
  500. /**
  501. * Extend object a with the properties of object b.
  502. * If there's a conflict, object b takes precedence.
  503. */
  504. function extend( a, b ) {
  505. for( var i in b ) {
  506. a[ i ] = b[ i ];
  507. }
  508. }
  509. /**
  510. * Converts the target object to an array.
  511. */
  512. function toArray( o ) {
  513. return Array.prototype.slice.call( o );
  514. }
  515. /**
  516. * Measures the distance in pixels between point a
  517. * and point b.
  518. *
  519. * @param {Object} a point with x/y properties
  520. * @param {Object} b point with x/y properties
  521. */
  522. function distanceBetween( a, b ) {
  523. var dx = a.x - b.x,
  524. dy = a.y - b.y;
  525. return Math.sqrt( dx*dx + dy*dy );
  526. }
  527. /**
  528. * Applies a CSS transform to the target element.
  529. */
  530. function transformElement( element, transform ) {
  531. element.style.WebkitTransform = transform;
  532. element.style.MozTransform = transform;
  533. element.style.msTransform = transform;
  534. element.style.OTransform = transform;
  535. element.style.transform = transform;
  536. }
  537. /**
  538. * Retrieves the height of the given element by looking
  539. * at the position and height of its immediate children.
  540. */
  541. function getAbsoluteHeight( element ) {
  542. var height = 0;
  543. if( element ) {
  544. var absoluteChildren = 0;
  545. toArray( element.childNodes ).forEach( function( child ) {
  546. if( typeof child.offsetTop === 'number' && child.style ) {
  547. // Count # of abs children
  548. if( child.style.position === 'absolute' ) {
  549. absoluteChildren += 1;
  550. }
  551. height = Math.max( height, child.offsetTop + child.offsetHeight );
  552. }
  553. } );
  554. // If there are no absolute children, use offsetHeight
  555. if( absoluteChildren === 0 ) {
  556. height = element.offsetHeight;
  557. }
  558. }
  559. return height;
  560. }
  561. /**
  562. * Returns the remaining height within the parent of the
  563. * target element after subtracting the height of all
  564. * siblings.
  565. *
  566. * remaining height = [parent height] - [ siblings height]
  567. */
  568. function getRemainingHeight( element, height ) {
  569. height = height || 0;
  570. if( element ) {
  571. var parent = element.parentNode;
  572. var siblings = parent.childNodes;
  573. // Subtract the height of each sibling
  574. toArray( siblings ).forEach( function( sibling ) {
  575. if( typeof sibling.offsetHeight === 'number' && sibling !== element ) {
  576. var styles = window.getComputedStyle( sibling ),
  577. marginTop = parseInt( styles.marginTop, 10 ),
  578. marginBottom = parseInt( styles.marginBottom, 10 );
  579. height -= sibling.offsetHeight + marginTop + marginBottom;
  580. }
  581. } );
  582. var elementStyles = window.getComputedStyle( element );
  583. // Subtract the margins of the target element
  584. height -= parseInt( elementStyles.marginTop, 10 ) +
  585. parseInt( elementStyles.marginBottom, 10 );
  586. }
  587. return height;
  588. }
  589. /**
  590. * Checks if this instance is being used to print a PDF.
  591. */
  592. function isPrintingPDF() {
  593. return ( /print-pdf/gi ).test( window.location.search );
  594. }
  595. /**
  596. * Hides the address bar if we're on a mobile device.
  597. */
  598. function hideAddressBar() {
  599. if( config.hideAddressBar && isMobileDevice ) {
  600. // Events that should trigger the address bar to hide
  601. window.addEventListener( 'load', removeAddressBar, false );
  602. window.addEventListener( 'orientationchange', removeAddressBar, false );
  603. }
  604. }
  605. /**
  606. * Causes the address bar to hide on mobile devices,
  607. * more vertical space ftw.
  608. */
  609. function removeAddressBar() {
  610. // Portrait and not Chrome for iOS
  611. if( window.orientation === 0 && !/crios/gi.test( navigator.userAgent ) ) {
  612. document.documentElement.style.overflow = 'scroll';
  613. document.body.style.height = '120%';
  614. }
  615. else {
  616. document.documentElement.style.overflow = '';
  617. document.body.style.height = '100%';
  618. }
  619. setTimeout( function() {
  620. window.scrollTo( 0, 1 );
  621. }, 10 );
  622. }
  623. /**
  624. * Dispatches an event of the specified type from the
  625. * reveal DOM element.
  626. */
  627. function dispatchEvent( type, properties ) {
  628. var event = document.createEvent( "HTMLEvents", 1, 2 );
  629. event.initEvent( type, true, true );
  630. extend( event, properties );
  631. dom.wrapper.dispatchEvent( event );
  632. }
  633. /**
  634. * Wrap all links in 3D goodness.
  635. */
  636. function enableRollingLinks() {
  637. if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) {
  638. var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
  639. for( var i = 0, len = anchors.length; i < len; i++ ) {
  640. var anchor = anchors[i];
  641. if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
  642. var span = document.createElement('span');
  643. span.setAttribute('data-title', anchor.text);
  644. span.innerHTML = anchor.innerHTML;
  645. anchor.classList.add( 'roll' );
  646. anchor.innerHTML = '';
  647. anchor.appendChild(span);
  648. }
  649. }
  650. }
  651. }
  652. /**
  653. * Unwrap all 3D links.
  654. */
  655. function disableRollingLinks() {
  656. var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
  657. for( var i = 0, len = anchors.length; i < len; i++ ) {
  658. var anchor = anchors[i];
  659. var span = anchor.querySelector( 'span' );
  660. if( span ) {
  661. anchor.classList.remove( 'roll' );
  662. anchor.innerHTML = span.innerHTML;
  663. }
  664. }
  665. }
  666. /**
  667. * Bind preview frame links.
  668. */
  669. function enablePreviewLinks( selector ) {
  670. var anchors = toArray( document.querySelectorAll( selector ? selector : 'a' ) );
  671. anchors.forEach( function( element ) {
  672. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  673. element.addEventListener( 'click', onPreviewLinkClicked, false );
  674. }
  675. } );
  676. }
  677. /**
  678. * Unbind preview frame links.
  679. */
  680. function disablePreviewLinks() {
  681. var anchors = toArray( document.querySelectorAll( 'a' ) );
  682. anchors.forEach( function( element ) {
  683. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  684. element.removeEventListener( 'click', onPreviewLinkClicked, false );
  685. }
  686. } );
  687. }
  688. /**
  689. * Opens a preview window for the target URL.
  690. */
  691. function openPreview( url ) {
  692. closePreview();
  693. dom.preview = document.createElement( 'div' );
  694. dom.preview.classList.add( 'preview-link-overlay' );
  695. dom.wrapper.appendChild( dom.preview );
  696. dom.preview.innerHTML = [
  697. '<header>',
  698. '<a class="close" href="#"><span class="icon"></span></a>',
  699. '<a class="external" href="'+ url +'" target="_blank"><span class="icon"></span></a>',
  700. '</header>',
  701. '<div class="spinner"></div>',
  702. '<div class="viewport">',
  703. '<iframe src="'+ url +'"></iframe>',
  704. '</div>'
  705. ].join('');
  706. dom.preview.querySelector( 'iframe' ).addEventListener( 'load', function( event ) {
  707. dom.preview.classList.add( 'loaded' );
  708. }, false );
  709. dom.preview.querySelector( '.close' ).addEventListener( 'click', function( event ) {
  710. closePreview();
  711. event.preventDefault();
  712. }, false );
  713. dom.preview.querySelector( '.external' ).addEventListener( 'click', function( event ) {
  714. closePreview();
  715. }, false );
  716. setTimeout( function() {
  717. dom.preview.classList.add( 'visible' );
  718. }, 1 );
  719. }
  720. /**
  721. * Closes the iframe preview window.
  722. */
  723. function closePreview() {
  724. if( dom.preview ) {
  725. dom.preview.setAttribute( 'src', '' );
  726. dom.preview.parentNode.removeChild( dom.preview );
  727. dom.preview = null;
  728. }
  729. }
  730. /**
  731. * Return a sorted fragments list, ordered by an increasing
  732. * "data-fragment-index" attribute.
  733. *
  734. * Fragments will be revealed in the order that they are returned by
  735. * this function, so you can use the index attributes to control the
  736. * order of fragment appearance.
  737. *
  738. * To maintain a sensible default fragment order, fragments are presumed
  739. * to be passed in document order. This function adds a "fragment-index"
  740. * attribute to each node if such an attribute is not already present,
  741. * and sets that attribute to an integer value which is the position of
  742. * the fragment within the fragments list.
  743. */
  744. function sortFragments( fragments ) {
  745. var a = toArray( fragments );
  746. a.forEach( function( el, idx ) {
  747. if( !el.hasAttribute( 'data-fragment-index' ) ) {
  748. el.setAttribute( 'data-fragment-index', idx );
  749. }
  750. } );
  751. a.sort( function( l, r ) {
  752. return l.getAttribute( 'data-fragment-index' ) - r.getAttribute( 'data-fragment-index');
  753. } );
  754. return a;
  755. }
  756. /**
  757. * Applies JavaScript-controlled layout rules to the
  758. * presentation.
  759. */
  760. function layout() {
  761. if( dom.wrapper && !isPrintingPDF() ) {
  762. // Available space to scale within
  763. var availableWidth = dom.wrapper.offsetWidth,
  764. availableHeight = dom.wrapper.offsetHeight;
  765. // Reduce available space by margin
  766. availableWidth -= ( availableHeight * config.margin );
  767. availableHeight -= ( availableHeight * config.margin );
  768. // Dimensions of the content
  769. var slideWidth = config.width,
  770. slideHeight = config.height,
  771. slidePadding = 20; // TODO Dig this out of DOM
  772. // Layout the contents of the slides
  773. layoutSlideContents( config.width, config.height, slidePadding );
  774. // Slide width may be a percentage of available width
  775. if( typeof slideWidth === 'string' && /%$/.test( slideWidth ) ) {
  776. slideWidth = parseInt( slideWidth, 10 ) / 100 * availableWidth;
  777. }
  778. // Slide height may be a percentage of available height
  779. if( typeof slideHeight === 'string' && /%$/.test( slideHeight ) ) {
  780. slideHeight = parseInt( slideHeight, 10 ) / 100 * availableHeight;
  781. }
  782. dom.slides.style.width = slideWidth + 'px';
  783. dom.slides.style.height = slideHeight + 'px';
  784. // Determine scale of content to fit within available space
  785. scale = Math.min( availableWidth / slideWidth, availableHeight / slideHeight );
  786. // Respect max/min scale settings
  787. scale = Math.max( scale, config.minScale );
  788. scale = Math.min( scale, config.maxScale );
  789. // Prefer applying scale via zoom since Chrome blurs scaled content
  790. // with nested transforms
  791. if( typeof dom.slides.style.zoom !== 'undefined' && !navigator.userAgent.match( /(iphone|ipod|ipad|android)/gi ) ) {
  792. dom.slides.style.zoom = scale;
  793. }
  794. // Apply scale transform as a fallback
  795. else {
  796. transformElement( dom.slides, 'translate(-50%, -50%) scale('+ scale +') translate(50%, 50%)' );
  797. }
  798. // Select all slides, vertical and horizontal
  799. var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
  800. for( var i = 0, len = slides.length; i < len; i++ ) {
  801. var slide = slides[ i ];
  802. // Don't bother updating invisible slides
  803. if( slide.style.display === 'none' ) {
  804. continue;
  805. }
  806. if( config.center ) {
  807. // Vertical stacks are not centred since their section
  808. // children will be
  809. if( slide.classList.contains( 'stack' ) ) {
  810. slide.style.top = 0;
  811. }
  812. else {
  813. slide.style.top = Math.max( - ( getAbsoluteHeight( slide ) / 2 ) - slidePadding, -slideHeight / 2 ) + 'px';
  814. }
  815. }
  816. else {
  817. slide.style.top = '';
  818. }
  819. }
  820. updateProgress();
  821. updateParallax();
  822. }
  823. }
  824. /**
  825. * Applies layout logic to the contents of all slides in
  826. * the presentation.
  827. */
  828. function layoutSlideContents( width, height, padding ) {
  829. // Handle sizing of elements with the 'stretch' class
  830. toArray( dom.slides.querySelectorAll( 'section > .stretch' ) ).forEach( function( element ) {
  831. // Determine how much vertical space we can use
  832. var remainingHeight = getRemainingHeight( element, ( height - ( padding * 2 ) ) );
  833. // Consider the aspect ratio of media elements
  834. if( /(img|video)/gi.test( element.nodeName ) ) {
  835. var nw = element.naturalWidth || element.videoWidth,
  836. nh = element.naturalHeight || element.videoHeight;
  837. var es = Math.min( width / nw, remainingHeight / nh );
  838. element.style.width = ( nw * es ) + 'px';
  839. element.style.height = ( nh * es ) + 'px';
  840. }
  841. else {
  842. element.style.width = width + 'px';
  843. element.style.height = remainingHeight + 'px';
  844. }
  845. } );
  846. }
  847. /**
  848. * Stores the vertical index of a stack so that the same
  849. * vertical slide can be selected when navigating to and
  850. * from the stack.
  851. *
  852. * @param {HTMLElement} stack The vertical stack element
  853. * @param {int} v Index to memorize
  854. */
  855. function setPreviousVerticalIndex( stack, v ) {
  856. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
  857. stack.setAttribute( 'data-previous-indexv', v || 0 );
  858. }
  859. }
  860. /**
  861. * Retrieves the vertical index which was stored using
  862. * #setPreviousVerticalIndex() or 0 if no previous index
  863. * exists.
  864. *
  865. * @param {HTMLElement} stack The vertical stack element
  866. */
  867. function getPreviousVerticalIndex( stack ) {
  868. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
  869. // Prefer manually defined start-indexv
  870. var attributeName = stack.hasAttribute( 'data-start-indexv' ) ? 'data-start-indexv' : 'data-previous-indexv';
  871. return parseInt( stack.getAttribute( attributeName ) || 0, 10 );
  872. }
  873. return 0;
  874. }
  875. /**
  876. * Displays the overview of slides (quick nav) by
  877. * scaling down and arranging all slide elements.
  878. *
  879. * Experimental feature, might be dropped if perf
  880. * can't be improved.
  881. */
  882. function activateOverview() {
  883. // Only proceed if enabled in config
  884. if( config.overview ) {
  885. // Don't auto-slide while in overview mode
  886. cancelAutoSlide();
  887. var wasActive = dom.wrapper.classList.contains( 'overview' );
  888. // Vary the depth of the overview based on screen size
  889. var depth = window.innerWidth < 400 ? 1000 : 2500;
  890. dom.wrapper.classList.add( 'overview' );
  891. dom.wrapper.classList.remove( 'overview-deactivating' );
  892. clearTimeout( activateOverviewTimeout );
  893. clearTimeout( deactivateOverviewTimeout );
  894. // Not the pretties solution, but need to let the overview
  895. // class apply first so that slides are measured accurately
  896. // before we can position them
  897. activateOverviewTimeout = setTimeout( function() {
  898. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  899. for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
  900. var hslide = horizontalSlides[i],
  901. hoffset = config.rtl ? -105 : 105;
  902. hslide.setAttribute( 'data-index-h', i );
  903. // Apply CSS transform
  904. transformElement( hslide, 'translateZ(-'+ depth +'px) translate(' + ( ( i - indexh ) * hoffset ) + '%, 0%)' );
  905. if( hslide.classList.contains( 'stack' ) ) {
  906. var verticalSlides = hslide.querySelectorAll( 'section' );
  907. for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
  908. var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
  909. var vslide = verticalSlides[j];
  910. vslide.setAttribute( 'data-index-h', i );
  911. vslide.setAttribute( 'data-index-v', j );
  912. // Apply CSS transform
  913. transformElement( vslide, 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)' );
  914. // Navigate to this slide on click
  915. vslide.addEventListener( 'click', onOverviewSlideClicked, true );
  916. }
  917. }
  918. else {
  919. // Navigate to this slide on click
  920. hslide.addEventListener( 'click', onOverviewSlideClicked, true );
  921. }
  922. }
  923. updateSlidesVisibility();
  924. layout();
  925. if( !wasActive ) {
  926. // Notify observers of the overview showing
  927. dispatchEvent( 'overviewshown', {
  928. 'indexh': indexh,
  929. 'indexv': indexv,
  930. 'currentSlide': currentSlide
  931. } );
  932. }
  933. }, 10 );
  934. }
  935. }
  936. /**
  937. * Exits the slide overview and enters the currently
  938. * active slide.
  939. */
  940. function deactivateOverview() {
  941. // Only proceed if enabled in config
  942. if( config.overview ) {
  943. clearTimeout( activateOverviewTimeout );
  944. clearTimeout( deactivateOverviewTimeout );
  945. dom.wrapper.classList.remove( 'overview' );
  946. // Temporarily add a class so that transitions can do different things
  947. // depending on whether they are exiting/entering overview, or just
  948. // moving from slide to slide
  949. dom.wrapper.classList.add( 'overview-deactivating' );
  950. deactivateOverviewTimeout = setTimeout( function () {
  951. dom.wrapper.classList.remove( 'overview-deactivating' );
  952. }, 1 );
  953. // Select all slides
  954. toArray( document.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
  955. // Resets all transforms to use the external styles
  956. transformElement( slide, '' );
  957. slide.removeEventListener( 'click', onOverviewSlideClicked, true );
  958. } );
  959. slide( indexh, indexv );
  960. cueAutoSlide();
  961. // Notify observers of the overview hiding
  962. dispatchEvent( 'overviewhidden', {
  963. 'indexh': indexh,
  964. 'indexv': indexv,
  965. 'currentSlide': currentSlide
  966. } );
  967. }
  968. }
  969. /**
  970. * Toggles the slide overview mode on and off.
  971. *
  972. * @param {Boolean} override Optional flag which overrides the
  973. * toggle logic and forcibly sets the desired state. True means
  974. * overview is open, false means it's closed.
  975. */
  976. function toggleOverview( override ) {
  977. if( typeof override === 'boolean' ) {
  978. override ? activateOverview() : deactivateOverview();
  979. }
  980. else {
  981. isOverview() ? deactivateOverview() : activateOverview();
  982. }
  983. }
  984. /**
  985. * Checks if the overview is currently active.
  986. *
  987. * @return {Boolean} true if the overview is active,
  988. * false otherwise
  989. */
  990. function isOverview() {
  991. return dom.wrapper.classList.contains( 'overview' );
  992. }
  993. /**
  994. * Checks if the current or specified slide is vertical
  995. * (nested within another slide).
  996. *
  997. * @param {HTMLElement} slide [optional] The slide to check
  998. * orientation of
  999. */
  1000. function isVerticalSlide( slide ) {
  1001. // Prefer slide argument, otherwise use current slide
  1002. slide = slide ? slide : currentSlide;
  1003. return slide && slide.parentNode && !!slide.parentNode.nodeName.match( /section/i );
  1004. }
  1005. /**
  1006. * Handling the fullscreen functionality via the fullscreen API
  1007. *
  1008. * @see http://fullscreen.spec.whatwg.org/
  1009. * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
  1010. */
  1011. function enterFullscreen() {
  1012. var element = document.body;
  1013. // Check which implementation is available
  1014. var requestMethod = element.requestFullScreen ||
  1015. element.webkitRequestFullscreen ||
  1016. element.webkitRequestFullScreen ||
  1017. element.mozRequestFullScreen ||
  1018. element.msRequestFullScreen;
  1019. if( requestMethod ) {
  1020. requestMethod.apply( element );
  1021. }
  1022. }
  1023. /**
  1024. * Enters the paused mode which fades everything on screen to
  1025. * black.
  1026. */
  1027. function pause() {
  1028. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1029. cancelAutoSlide();
  1030. dom.wrapper.classList.add( 'paused' );
  1031. if( wasPaused === false ) {
  1032. dispatchEvent( 'paused' );
  1033. }
  1034. }
  1035. /**
  1036. * Exits from the paused mode.
  1037. */
  1038. function resume() {
  1039. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1040. dom.wrapper.classList.remove( 'paused' );
  1041. cueAutoSlide();
  1042. if( wasPaused ) {
  1043. dispatchEvent( 'resumed' );
  1044. }
  1045. }
  1046. /**
  1047. * Toggles the paused mode on and off.
  1048. */
  1049. function togglePause() {
  1050. if( isPaused() ) {
  1051. resume();
  1052. }
  1053. else {
  1054. pause();
  1055. }
  1056. }
  1057. /**
  1058. * Checks if we are currently in the paused mode.
  1059. */
  1060. function isPaused() {
  1061. return dom.wrapper.classList.contains( 'paused' );
  1062. }
  1063. /**
  1064. * Steps from the current point in the presentation to the
  1065. * slide which matches the specified horizontal and vertical
  1066. * indices.
  1067. *
  1068. * @param {int} h Horizontal index of the target slide
  1069. * @param {int} v Vertical index of the target slide
  1070. * @param {int} f Optional index of a fragment within the
  1071. * target slide to activate
  1072. * @param {int} o Optional origin for use in multimaster environments
  1073. */
  1074. function slide( h, v, f, o ) {
  1075. // Remember where we were at before
  1076. previousSlide = currentSlide;
  1077. // Query all horizontal slides in the deck
  1078. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  1079. // If no vertical index is specified and the upcoming slide is a
  1080. // stack, resume at its previous vertical index
  1081. if( v === undefined ) {
  1082. v = getPreviousVerticalIndex( horizontalSlides[ h ] );
  1083. }
  1084. // If we were on a vertical stack, remember what vertical index
  1085. // it was on so we can resume at the same position when returning
  1086. if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
  1087. setPreviousVerticalIndex( previousSlide.parentNode, indexv );
  1088. }
  1089. // Remember the state before this slide
  1090. var stateBefore = state.concat();
  1091. // Reset the state array
  1092. state.length = 0;
  1093. var indexhBefore = indexh || 0,
  1094. indexvBefore = indexv || 0;
  1095. // Activate and transition to the new slide
  1096. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
  1097. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
  1098. // Update the visibility of slides now that the indices have changed
  1099. updateSlidesVisibility();
  1100. layout();
  1101. // Apply the new state
  1102. stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
  1103. // Check if this state existed on the previous slide. If it
  1104. // did, we will avoid adding it repeatedly
  1105. for( var j = 0; j < stateBefore.length; j++ ) {
  1106. if( stateBefore[j] === state[i] ) {
  1107. stateBefore.splice( j, 1 );
  1108. continue stateLoop;
  1109. }
  1110. }
  1111. document.documentElement.classList.add( state[i] );
  1112. // Dispatch custom event matching the state's name
  1113. dispatchEvent( state[i] );
  1114. }
  1115. // Clean up the remains of the previous state
  1116. while( stateBefore.length ) {
  1117. document.documentElement.classList.remove( stateBefore.pop() );
  1118. }
  1119. // If the overview is active, re-activate it to update positions
  1120. if( isOverview() ) {
  1121. activateOverview();
  1122. }
  1123. // Find the current horizontal slide and any possible vertical slides
  1124. // within it
  1125. var currentHorizontalSlide = horizontalSlides[ indexh ],
  1126. currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
  1127. // Store references to the previous and current slides
  1128. currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
  1129. ////////////////////////////////////
  1130. // Show fragment, if specified
  1131. if( typeof f !== 'undefined' ) {
  1132. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
  1133. toArray( fragments ).forEach( function( fragment, indexf ) {
  1134. if( indexf < f ) {
  1135. fragment.classList.add( 'visible' );
  1136. }
  1137. else {
  1138. fragment.classList.remove( 'visible' );
  1139. }
  1140. } );
  1141. }
  1142. // Dispatch an event if the slide changed
  1143. var slideChanged = ( indexh !== indexhBefore || indexv !== indexvBefore );
  1144. if( slideChanged ) {
  1145. dispatchEvent( 'slidechanged', {
  1146. 'indexh': indexh,
  1147. 'indexv': indexv,
  1148. 'previousSlide': previousSlide,
  1149. 'currentSlide': currentSlide,
  1150. 'origin': o
  1151. } );
  1152. }
  1153. else {
  1154. // Ensure that the previous slide is never the same as the current
  1155. previousSlide = null;
  1156. }
  1157. // Solves an edge case where the previous slide maintains the
  1158. // 'present' class when navigating between adjacent vertical
  1159. // stacks
  1160. if( previousSlide ) {
  1161. previousSlide.classList.remove( 'present' );
  1162. // Reset all slides upon navigate to home
  1163. // Issue: #285
  1164. if ( document.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
  1165. // Launch async task
  1166. setTimeout( function () {
  1167. var slides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
  1168. for( i in slides ) {
  1169. if( slides[i] ) {
  1170. // Reset stack
  1171. setPreviousVerticalIndex( slides[i], 0 );
  1172. }
  1173. }
  1174. }, 0 );
  1175. }
  1176. }
  1177. // Handle embedded content
  1178. if( slideChanged ) {
  1179. stopEmbeddedContent( previousSlide );
  1180. startEmbeddedContent( currentSlide );
  1181. }
  1182. updateControls();
  1183. updateProgress();
  1184. updateBackground();
  1185. updateParallax();
  1186. // Update the URL hash
  1187. writeURL();
  1188. }
  1189. /**
  1190. * Syncs the presentation with the current DOM. Useful
  1191. * when new slides or control elements are added or when
  1192. * the configuration has changed.
  1193. */
  1194. function sync() {
  1195. // Subscribe to input
  1196. removeEventListeners();
  1197. addEventListeners();
  1198. // Force a layout to make sure the current config is accounted for
  1199. layout();
  1200. // Reflect the current autoSlide value
  1201. autoSlide = config.autoSlide;
  1202. // Start auto-sliding if it's enabled
  1203. cueAutoSlide();
  1204. // Re-create the slide backgrounds
  1205. createBackgrounds();
  1206. updateControls();
  1207. updateProgress();
  1208. updateBackground();
  1209. }
  1210. /**
  1211. * Updates one dimension of slides by showing the slide
  1212. * with the specified index.
  1213. *
  1214. * @param {String} selector A CSS selector that will fetch
  1215. * the group of slides we are working with
  1216. * @param {Number} index The index of the slide that should be
  1217. * shown
  1218. *
  1219. * @return {Number} The index of the slide that is now shown,
  1220. * might differ from the passed in index if it was out of
  1221. * bounds.
  1222. */
  1223. function updateSlides( selector, index ) {
  1224. // Select all slides and convert the NodeList result to
  1225. // an array
  1226. var slides = toArray( document.querySelectorAll( selector ) ),
  1227. slidesLength = slides.length;
  1228. if( slidesLength ) {
  1229. // Should the index loop?
  1230. if( config.loop ) {
  1231. index %= slidesLength;
  1232. if( index < 0 ) {
  1233. index = slidesLength + index;
  1234. }
  1235. }
  1236. // Enforce max and minimum index bounds
  1237. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  1238. for( var i = 0; i < slidesLength; i++ ) {
  1239. var element = slides[i];
  1240. var reverse = config.rtl && !isVerticalSlide( element );
  1241. element.classList.remove( 'past' );
  1242. element.classList.remove( 'present' );
  1243. element.classList.remove( 'future' );
  1244. // http://www.w3.org/html/wg/drafts/html/master/editing.html#the-hidden-attribute
  1245. element.setAttribute( 'hidden', '' );
  1246. if( i < index ) {
  1247. // Any element previous to index is given the 'past' class
  1248. element.classList.add( reverse ? 'future' : 'past' );
  1249. }
  1250. else if( i > index ) {
  1251. // Any element subsequent to index is given the 'future' class
  1252. element.classList.add( reverse ? 'past' : 'future' );
  1253. var fragments = toArray( element.querySelectorAll( '.fragment.visible' ) );
  1254. // No fragments in future slides should be visible ahead of time
  1255. while( fragments.length ) {
  1256. fragments.pop().classList.remove( 'visible' );
  1257. }
  1258. }
  1259. // If this element contains vertical slides
  1260. if( element.querySelector( 'section' ) ) {
  1261. element.classList.add( 'stack' );
  1262. }
  1263. }
  1264. // Mark the current slide as present
  1265. slides[index].classList.add( 'present' );
  1266. slides[index].removeAttribute( 'hidden' );
  1267. // If this slide has a state associated with it, add it
  1268. // onto the current state of the deck
  1269. var slideState = slides[index].getAttribute( 'data-state' );
  1270. if( slideState ) {
  1271. state = state.concat( slideState.split( ' ' ) );
  1272. }
  1273. // If this slide has a data-autoslide attribute associated use this as
  1274. // autoSlide value otherwise use the global configured time
  1275. var slideAutoSlide = slides[index].getAttribute( 'data-autoslide' );
  1276. if( slideAutoSlide ) {
  1277. autoSlide = parseInt( slideAutoSlide, 10 );
  1278. }
  1279. else {
  1280. autoSlide = config.autoSlide;
  1281. }
  1282. cueAutoSlide();
  1283. }
  1284. else {
  1285. // Since there are no slides we can't be anywhere beyond the
  1286. // zeroth index
  1287. index = 0;
  1288. }
  1289. return index;
  1290. }
  1291. /**
  1292. * Optimization method; hide all slides that are far away
  1293. * from the present slide.
  1294. */
  1295. function updateSlidesVisibility() {
  1296. // Select all slides and convert the NodeList result to
  1297. // an array
  1298. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ),
  1299. horizontalSlidesLength = horizontalSlides.length,
  1300. distanceX,
  1301. distanceY;
  1302. if( horizontalSlidesLength ) {
  1303. // The number of steps away from the present slide that will
  1304. // be visible
  1305. var viewDistance = isOverview() ? 10 : config.viewDistance;
  1306. // Limit view distance on weaker devices
  1307. if( isMobileDevice ) {
  1308. viewDistance = isOverview() ? 6 : 1;
  1309. }
  1310. for( var x = 0; x < horizontalSlidesLength; x++ ) {
  1311. var horizontalSlide = horizontalSlides[x];
  1312. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) ),
  1313. verticalSlidesLength = verticalSlides.length;
  1314. // Loops so that it measures 1 between the first and last slides
  1315. distanceX = Math.abs( ( indexh - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0;
  1316. // Show the horizontal slide if it's within the view distance
  1317. horizontalSlide.style.display = distanceX > viewDistance ? 'none' : 'block';
  1318. if( verticalSlidesLength ) {
  1319. var oy = getPreviousVerticalIndex( horizontalSlide );
  1320. for( var y = 0; y < verticalSlidesLength; y++ ) {
  1321. var verticalSlide = verticalSlides[y];
  1322. distanceY = x === indexh ? Math.abs( indexv - y ) : Math.abs( y - oy );
  1323. verticalSlide.style.display = ( distanceX + distanceY ) > viewDistance ? 'none' : 'block';
  1324. }
  1325. }
  1326. }
  1327. }
  1328. }
  1329. /**
  1330. * Updates the progress bar to reflect the current slide.
  1331. */
  1332. function updateProgress() {
  1333. // Update progress if enabled
  1334. if( config.progress && dom.progress ) {
  1335. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1336. // The number of past and total slides
  1337. var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  1338. var pastCount = 0;
  1339. // Step through all slides and count the past ones
  1340. mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
  1341. var horizontalSlide = horizontalSlides[i];
  1342. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1343. for( var j = 0; j < verticalSlides.length; j++ ) {
  1344. // Stop as soon as we arrive at the present
  1345. if( verticalSlides[j].classList.contains( 'present' ) ) {
  1346. break mainLoop;
  1347. }
  1348. pastCount++;
  1349. }
  1350. // Stop as soon as we arrive at the present
  1351. if( horizontalSlide.classList.contains( 'present' ) ) {
  1352. break;
  1353. }
  1354. // Don't count the wrapping section for vertical slides
  1355. if( horizontalSlide.classList.contains( 'stack' ) === false ) {
  1356. pastCount++;
  1357. }
  1358. }
  1359. dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px';
  1360. }
  1361. }
  1362. /**
  1363. * Updates the state of all control/navigation arrows.
  1364. */
  1365. function updateControls() {
  1366. var routes = availableRoutes();
  1367. var fragments = availableFragments();
  1368. // Remove the 'enabled' class from all directions
  1369. dom.controlsLeft.concat( dom.controlsRight )
  1370. .concat( dom.controlsUp )
  1371. .concat( dom.controlsDown )
  1372. .concat( dom.controlsPrev )
  1373. .concat( dom.controlsNext ).forEach( function( node ) {
  1374. node.classList.remove( 'enabled' );
  1375. node.classList.remove( 'fragmented' );
  1376. } );
  1377. // Add the 'enabled' class to the available routes
  1378. if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1379. if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1380. if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1381. if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1382. // Prev/next buttons
  1383. if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1384. if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1385. // Highlight fragment directions
  1386. if( currentSlide ) {
  1387. // Always apply fragment decorator to prev/next buttons
  1388. if( fragments.prev ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1389. if( fragments.next ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1390. // Apply fragment decorators to directional buttons based on
  1391. // what slide axis they are in
  1392. if( isVerticalSlide( currentSlide ) ) {
  1393. if( fragments.prev ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1394. if( fragments.next ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1395. }
  1396. else {
  1397. if( fragments.prev ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1398. if( fragments.next ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1399. }
  1400. }
  1401. }
  1402. /**
  1403. * Updates the background elements to reflect the current
  1404. * slide.
  1405. */
  1406. function updateBackground() {
  1407. // Update the classes of all backgrounds to match the
  1408. // states of their slides (past/present/future)
  1409. toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) {
  1410. // Reverse past/future classes when in RTL mode
  1411. var horizontalPast = config.rtl ? 'future' : 'past',
  1412. horizontalFuture = config.rtl ? 'past' : 'future';
  1413. backgroundh.className = 'slide-background ' + ( h < indexh ? horizontalPast : h > indexh ? horizontalFuture : 'present' );
  1414. toArray( backgroundh.childNodes ).forEach( function( backgroundv, v ) {
  1415. backgroundv.className = 'slide-background ' + ( v < indexv ? 'past' : v > indexv ? 'future' : 'present' );
  1416. } );
  1417. } );
  1418. // Allow the first background to apply without transition
  1419. setTimeout( function() {
  1420. dom.background.classList.remove( 'no-transition' );
  1421. }, 1 );
  1422. }
  1423. /**
  1424. * Updates the position of the parallax background based
  1425. * on the current slide index.
  1426. */
  1427. function updateParallax() {
  1428. if( config.parallaxBackgroundImage ) {
  1429. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1430. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1431. var backgroundSize = dom.background.style.backgroundSize.split( ' ' ),
  1432. backgroundWidth, backgroundHeight;
  1433. if( backgroundSize.length === 1 ) {
  1434. backgroundWidth = backgroundHeight = parseInt( backgroundSize[0], 10 );
  1435. }
  1436. else {
  1437. backgroundWidth = parseInt( backgroundSize[0], 10 );
  1438. backgroundHeight = parseInt( backgroundSize[1], 10 );
  1439. }
  1440. var slideWidth = dom.background.offsetWidth;
  1441. var horizontalSlideCount = horizontalSlides.length;
  1442. var horizontalOffset = -( backgroundWidth - slideWidth ) / ( horizontalSlideCount-1 ) * indexh;
  1443. var slideHeight = dom.background.offsetHeight;
  1444. var verticalSlideCount = verticalSlides.length;
  1445. var verticalOffset = verticalSlideCount > 0 ? -( backgroundHeight - slideHeight ) / ( verticalSlideCount-1 ) * indexv : 0;
  1446. dom.background.style.backgroundPosition = horizontalOffset + 'px ' + verticalOffset + 'px';
  1447. }
  1448. }
  1449. /**
  1450. * Determine what available routes there are for navigation.
  1451. *
  1452. * @return {Object} containing four booleans: left/right/up/down
  1453. */
  1454. function availableRoutes() {
  1455. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1456. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1457. var routes = {
  1458. left: indexh > 0 || config.loop,
  1459. right: indexh < horizontalSlides.length - 1 || config.loop,
  1460. up: indexv > 0,
  1461. down: indexv < verticalSlides.length - 1
  1462. };
  1463. // reverse horizontal controls for rtl
  1464. if( config.rtl ) {
  1465. var left = routes.left;
  1466. routes.left = routes.right;
  1467. routes.right = left;
  1468. }
  1469. return routes;
  1470. }
  1471. /**
  1472. * Returns an object describing the available fragment
  1473. * directions.
  1474. *
  1475. * @return {Object} two boolean properties: prev/next
  1476. */
  1477. function availableFragments() {
  1478. if( currentSlide && config.fragments ) {
  1479. var fragments = currentSlide.querySelectorAll( '.fragment' );
  1480. var hiddenFragments = currentSlide.querySelectorAll( '.fragment:not(.visible)' );
  1481. return {
  1482. prev: fragments.length - hiddenFragments.length > 0,
  1483. next: !!hiddenFragments.length
  1484. };
  1485. }
  1486. else {
  1487. return { prev: false, next: false };
  1488. }
  1489. }
  1490. /**
  1491. * Start playback of any embedded content inside of
  1492. * the targeted slide.
  1493. */
  1494. function startEmbeddedContent( slide ) {
  1495. if( slide ) {
  1496. // HTML5 media elements
  1497. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1498. if( el.hasAttribute( 'data-autoplay' ) ) {
  1499. el.play();
  1500. }
  1501. } );
  1502. // YouTube embeds
  1503. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  1504. if( el.hasAttribute( 'data-autoplay' ) ) {
  1505. el.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
  1506. }
  1507. });
  1508. }
  1509. }
  1510. /**
  1511. * Stop playback of any embedded content inside of
  1512. * the targeted slide.
  1513. */
  1514. function stopEmbeddedContent( slide ) {
  1515. if( slide ) {
  1516. // HTML5 media elements
  1517. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1518. if( !el.hasAttribute( 'data-ignore' ) ) {
  1519. el.pause();
  1520. }
  1521. } );
  1522. // YouTube embeds
  1523. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  1524. if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
  1525. el.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
  1526. }
  1527. });
  1528. }
  1529. }
  1530. /**
  1531. * Reads the current URL (hash) and navigates accordingly.
  1532. */
  1533. function readURL() {
  1534. var hash = window.location.hash;
  1535. // Attempt to parse the hash as either an index or name
  1536. var bits = hash.slice( 2 ).split( '/' ),
  1537. name = hash.replace( /#|\//gi, '' );
  1538. // If the first bit is invalid and there is a name we can
  1539. // assume that this is a named link
  1540. if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
  1541. // Find the slide with the specified name
  1542. var element = document.querySelector( '#' + name );
  1543. if( element ) {
  1544. // Find the position of the named slide and navigate to it
  1545. var indices = Reveal.getIndices( element );
  1546. slide( indices.h, indices.v );
  1547. }
  1548. // If the slide doesn't exist, navigate to the current slide
  1549. else {
  1550. slide( indexh || 0, indexv || 0 );
  1551. }
  1552. }
  1553. else {
  1554. // Read the index components of the hash
  1555. var h = parseInt( bits[0], 10 ) || 0,
  1556. v = parseInt( bits[1], 10 ) || 0;
  1557. if( h !== indexh || v !== indexv ) {
  1558. slide( h, v );
  1559. }
  1560. }
  1561. }
  1562. /**
  1563. * Updates the page URL (hash) to reflect the current
  1564. * state.
  1565. *
  1566. * @param {Number} delay The time in ms to wait before
  1567. * writing the hash
  1568. */
  1569. function writeURL( delay ) {
  1570. if( config.history ) {
  1571. // Make sure there's never more than one timeout running
  1572. clearTimeout( writeURLTimeout );
  1573. // If a delay is specified, timeout this call
  1574. if( typeof delay === 'number' ) {
  1575. writeURLTimeout = setTimeout( writeURL, delay );
  1576. }
  1577. else {
  1578. var url = '/';
  1579. // If the current slide has an ID, use that as a named link
  1580. if( currentSlide && typeof currentSlide.getAttribute( 'id' ) === 'string' ) {
  1581. url = '/' + currentSlide.getAttribute( 'id' );
  1582. }
  1583. // Otherwise use the /h/v index
  1584. else {
  1585. if( indexh > 0 || indexv > 0 ) url += indexh;
  1586. if( indexv > 0 ) url += '/' + indexv;
  1587. }
  1588. window.location.hash = url;
  1589. }
  1590. }
  1591. }
  1592. /**
  1593. * Retrieves the h/v location of the current, or specified,
  1594. * slide.
  1595. *
  1596. * @param {HTMLElement} slide If specified, the returned
  1597. * index will be for this slide rather than the currently
  1598. * active one
  1599. *
  1600. * @return {Object} { h: <int>, v: <int>, f: <int> }
  1601. */
  1602. function getIndices( slide ) {
  1603. // By default, return the current indices
  1604. var h = indexh,
  1605. v = indexv,
  1606. f;
  1607. // If a slide is specified, return the indices of that slide
  1608. if( slide ) {
  1609. var isVertical = isVerticalSlide( slide );
  1610. var slideh = isVertical ? slide.parentNode : slide;
  1611. // Select all horizontal slides
  1612. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1613. // Now that we know which the horizontal slide is, get its index
  1614. h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
  1615. // If this is a vertical slide, grab the vertical index
  1616. if( isVertical ) {
  1617. v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
  1618. }
  1619. }
  1620. if( !slide && currentSlide ) {
  1621. var hasFragments = currentSlide.querySelectorAll( '.fragment' ).length > 0;
  1622. if( hasFragments ) {
  1623. var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
  1624. f = visibleFragments.length;
  1625. }
  1626. }
  1627. return { h: h, v: v, f: f };
  1628. }
  1629. /**
  1630. * Navigate to the next slide fragment.
  1631. *
  1632. * @return {Boolean} true if there was a next fragment,
  1633. * false otherwise
  1634. */
  1635. function nextFragment() {
  1636. if( currentSlide && config.fragments ) {
  1637. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment:not(.visible)' ) );
  1638. if( fragments.length ) {
  1639. // Find the index of the next fragment
  1640. var index = fragments[0].getAttribute( 'data-fragment-index' );
  1641. // Find all fragments with the same index
  1642. fragments = currentSlide.querySelectorAll( '.fragment[data-fragment-index="'+ index +'"]' );
  1643. toArray( fragments ).forEach( function( element ) {
  1644. element.classList.add( 'visible' );
  1645. } );
  1646. // Notify subscribers of the change
  1647. dispatchEvent( 'fragmentshown', { fragment: fragments[0], fragments: fragments } );
  1648. updateControls();
  1649. return true;
  1650. }
  1651. }
  1652. return false;
  1653. }
  1654. /**
  1655. * Navigate to the previous slide fragment.
  1656. *
  1657. * @return {Boolean} true if there was a previous fragment,
  1658. * false otherwise
  1659. */
  1660. function previousFragment() {
  1661. if( currentSlide && config.fragments ) {
  1662. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) );
  1663. if( fragments.length ) {
  1664. // Find the index of the previous fragment
  1665. var index = fragments[ fragments.length - 1 ].getAttribute( 'data-fragment-index' );
  1666. // Find all fragments with the same index
  1667. fragments = currentSlide.querySelectorAll( '.fragment[data-fragment-index="'+ index +'"]' );
  1668. toArray( fragments ).forEach( function( f ) {
  1669. f.classList.remove( 'visible' );
  1670. } );
  1671. // Notify subscribers of the change
  1672. dispatchEvent( 'fragmenthidden', { fragment: fragments[0], fragments: fragments } );
  1673. updateControls();
  1674. return true;
  1675. }
  1676. }
  1677. return false;
  1678. }
  1679. /**
  1680. * Cues a new automated slide if enabled in the config.
  1681. */
  1682. function cueAutoSlide() {
  1683. clearTimeout( autoSlideTimeout );
  1684. // Cue the next auto-slide if enabled
  1685. if( autoSlide && !isPaused() && !isOverview() ) {
  1686. autoSlideTimeout = setTimeout( navigateNext, autoSlide );
  1687. }
  1688. }
  1689. /**
  1690. * Cancels any ongoing request to auto-slide.
  1691. */
  1692. function cancelAutoSlide() {
  1693. clearTimeout( autoSlideTimeout );
  1694. }
  1695. function navigateLeft() {
  1696. // Reverse for RTL
  1697. if( config.rtl ) {
  1698. if( ( isOverview() || nextFragment() === false ) && availableRoutes().left ) {
  1699. slide( indexh + 1 );
  1700. }
  1701. }
  1702. // Normal navigation
  1703. else if( ( isOverview() || previousFragment() === false ) && availableRoutes().left ) {
  1704. slide( indexh - 1 );
  1705. }
  1706. }
  1707. function navigateRight() {
  1708. // Reverse for RTL
  1709. if( config.rtl ) {
  1710. if( ( isOverview() || previousFragment() === false ) && availableRoutes().right ) {
  1711. slide( indexh - 1 );
  1712. }
  1713. }
  1714. // Normal navigation
  1715. else if( ( isOverview() || nextFragment() === false ) && availableRoutes().right ) {
  1716. slide( indexh + 1 );
  1717. }
  1718. }
  1719. function navigateUp() {
  1720. // Prioritize hiding fragments
  1721. if( ( isOverview() || previousFragment() === false ) && availableRoutes().up ) {
  1722. slide( indexh, indexv - 1 );
  1723. }
  1724. }
  1725. function navigateDown() {
  1726. // Prioritize revealing fragments
  1727. if( ( isOverview() || nextFragment() === false ) && availableRoutes().down ) {
  1728. slide( indexh, indexv + 1 );
  1729. }
  1730. }
  1731. /**
  1732. * Navigates backwards, prioritized in the following order:
  1733. * 1) Previous fragment
  1734. * 2) Previous vertical slide
  1735. * 3) Previous horizontal slide
  1736. */
  1737. function navigatePrev() {
  1738. // Prioritize revealing fragments
  1739. if( previousFragment() === false ) {
  1740. if( availableRoutes().up ) {
  1741. navigateUp();
  1742. }
  1743. else {
  1744. // Fetch the previous horizontal slide, if there is one
  1745. var previousSlide = document.querySelector( HORIZONTAL_SLIDES_SELECTOR + '.past:nth-child(' + indexh + ')' );
  1746. if( previousSlide ) {
  1747. var v = ( previousSlide.querySelectorAll( 'section' ).length - 1 ) || undefined;
  1748. var h = indexh - 1;
  1749. slide( h, v );
  1750. }
  1751. }
  1752. }
  1753. }
  1754. /**
  1755. * Same as #navigatePrev() but navigates forwards.
  1756. */
  1757. function navigateNext() {
  1758. // Prioritize revealing fragments
  1759. if( nextFragment() === false ) {
  1760. availableRoutes().down ? navigateDown() : navigateRight();
  1761. }
  1762. // If auto-sliding is enabled we need to cue up
  1763. // another timeout
  1764. cueAutoSlide();
  1765. }
  1766. // --------------------------------------------------------------------//
  1767. // ----------------------------- EVENTS -------------------------------//
  1768. // --------------------------------------------------------------------//
  1769. /**
  1770. * Handler for the document level 'keydown' event.
  1771. *
  1772. * @param {Object} event
  1773. */
  1774. function onDocumentKeyDown( event ) {
  1775. // Check if there's a focused element that could be using
  1776. // the keyboard
  1777. var activeElement = document.activeElement;
  1778. var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) );
  1779. // Disregard the event if there's a focused element or a
  1780. // keyboard modifier key is present
  1781. if( hasFocus || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
  1782. // While paused only allow "unpausing" keyboard events (b and .)
  1783. if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) {
  1784. return false;
  1785. }
  1786. var triggered = false;
  1787. // 1. User defined key bindings
  1788. if( typeof config.keyboard === 'object' ) {
  1789. for( var key in config.keyboard ) {
  1790. // Check if this binding matches the pressed key
  1791. if( parseInt( key, 10 ) === event.keyCode ) {
  1792. var value = config.keyboard[ key ];
  1793. // Callback function
  1794. if( typeof value === 'function' ) {
  1795. value.apply( null, [ event ] );
  1796. }
  1797. // String shortcuts to reveal.js API
  1798. else if( typeof value === 'string' && typeof Reveal[ value ] === 'function' ) {
  1799. Reveal[ value ].call();
  1800. }
  1801. triggered = true;
  1802. }
  1803. }
  1804. }
  1805. // 2. System defined key bindings
  1806. if( triggered === false ) {
  1807. // Assume true and try to prove false
  1808. triggered = true;
  1809. switch( event.keyCode ) {
  1810. // p, page up
  1811. case 80: case 33: navigatePrev(); break;
  1812. // n, page down
  1813. case 78: case 34: navigateNext(); break;
  1814. // h, left
  1815. case 72: case 37: navigateLeft(); break;
  1816. // l, right
  1817. case 76: case 39: navigateRight(); break;
  1818. // k, up
  1819. case 75: case 38: navigateUp(); break;
  1820. // j, down
  1821. case 74: case 40: navigateDown(); break;
  1822. // home
  1823. case 36: slide( 0 ); break;
  1824. // end
  1825. case 35: slide( Number.MAX_VALUE ); break;
  1826. // space
  1827. case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
  1828. // return
  1829. case 13: isOverview() ? deactivateOverview() : triggered = false; break;
  1830. // b, period, Logitech presenter tools "black screen" button
  1831. case 66: case 190: case 191: togglePause(); break;
  1832. // f
  1833. case 70: enterFullscreen(); break;
  1834. default:
  1835. triggered = false;
  1836. }
  1837. }
  1838. // If the input resulted in a triggered action we should prevent
  1839. // the browsers default behavior
  1840. if( triggered ) {
  1841. event.preventDefault();
  1842. }
  1843. // ESC or O key
  1844. else if ( ( event.keyCode === 27 || event.keyCode === 79 ) && supports3DTransforms ) {
  1845. toggleOverview();
  1846. event.preventDefault();
  1847. }
  1848. // If auto-sliding is enabled we need to cue up
  1849. // another timeout
  1850. cueAutoSlide();
  1851. }
  1852. /**
  1853. * Handler for the 'touchstart' event, enables support for
  1854. * swipe and pinch gestures.
  1855. */
  1856. function onTouchStart( event ) {
  1857. touch.startX = event.touches[0].clientX;
  1858. touch.startY = event.touches[0].clientY;
  1859. touch.startCount = event.touches.length;
  1860. // If there's two touches we need to memorize the distance
  1861. // between those two points to detect pinching
  1862. if( event.touches.length === 2 && config.overview ) {
  1863. touch.startSpan = distanceBetween( {
  1864. x: event.touches[1].clientX,
  1865. y: event.touches[1].clientY
  1866. }, {
  1867. x: touch.startX,
  1868. y: touch.startY
  1869. } );
  1870. }
  1871. }
  1872. /**
  1873. * Handler for the 'touchmove' event.
  1874. */
  1875. function onTouchMove( event ) {
  1876. // Each touch should only trigger one action
  1877. if( !touch.captured ) {
  1878. var currentX = event.touches[0].clientX;
  1879. var currentY = event.touches[0].clientY;
  1880. // If the touch started with two points and still has
  1881. // two active touches; test for the pinch gesture
  1882. if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
  1883. // The current distance in pixels between the two touch points
  1884. var currentSpan = distanceBetween( {
  1885. x: event.touches[1].clientX,
  1886. y: event.touches[1].clientY
  1887. }, {
  1888. x: touch.startX,
  1889. y: touch.startY
  1890. } );
  1891. // If the span is larger than the desire amount we've got
  1892. // ourselves a pinch
  1893. if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
  1894. touch.captured = true;
  1895. if( currentSpan < touch.startSpan ) {
  1896. activateOverview();
  1897. }
  1898. else {
  1899. deactivateOverview();
  1900. }
  1901. }
  1902. event.preventDefault();
  1903. }
  1904. // There was only one touch point, look for a swipe
  1905. else if( event.touches.length === 1 && touch.startCount !== 2 ) {
  1906. var deltaX = currentX - touch.startX,
  1907. deltaY = currentY - touch.startY;
  1908. if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  1909. touch.captured = true;
  1910. navigateLeft();
  1911. }
  1912. else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  1913. touch.captured = true;
  1914. navigateRight();
  1915. }
  1916. else if( deltaY > touch.threshold ) {
  1917. touch.captured = true;
  1918. navigateUp();
  1919. }
  1920. else if( deltaY < -touch.threshold ) {
  1921. touch.captured = true;
  1922. navigateDown();
  1923. }
  1924. // If we're embedded, only block touch events if they have
  1925. // triggered an action
  1926. if( config.embedded ) {
  1927. if( touch.captured || isVerticalSlide( currentSlide ) ) {
  1928. event.preventDefault();
  1929. }
  1930. }
  1931. // Not embedded? Block them all to avoid needless tossing
  1932. // around of the viewport in iOS
  1933. else {
  1934. event.preventDefault();
  1935. }
  1936. }
  1937. }
  1938. // There's a bug with swiping on some Android devices unless
  1939. // the default action is always prevented
  1940. else if( navigator.userAgent.match( /android/gi ) ) {
  1941. event.preventDefault();
  1942. }
  1943. }
  1944. /**
  1945. * Handler for the 'touchend' event.
  1946. */
  1947. function onTouchEnd( event ) {
  1948. touch.captured = false;
  1949. }
  1950. /**
  1951. * Convert pointer down to touch start.
  1952. */
  1953. function onPointerDown( event ) {
  1954. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  1955. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  1956. onTouchStart( event );
  1957. }
  1958. }
  1959. /**
  1960. * Convert pointer move to touch move.
  1961. */
  1962. function onPointerMove( event ) {
  1963. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  1964. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  1965. onTouchMove( event );
  1966. }
  1967. }
  1968. /**
  1969. * Convert pointer up to touch end.
  1970. */
  1971. function onPointerUp( event ) {
  1972. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  1973. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  1974. onTouchEnd( event );
  1975. }
  1976. }
  1977. /**
  1978. * Handles mouse wheel scrolling, throttled to avoid skipping
  1979. * multiple slides.
  1980. */
  1981. function onDocumentMouseScroll( event ) {
  1982. if( Date.now() - lastMouseWheelStep > 600 ) {
  1983. lastMouseWheelStep = Date.now();
  1984. var delta = event.detail || -event.wheelDelta;
  1985. if( delta > 0 ) {
  1986. navigateNext();
  1987. }
  1988. else {
  1989. navigatePrev();
  1990. }
  1991. }
  1992. }
  1993. /**
  1994. * Clicking on the progress bar results in a navigation to the
  1995. * closest approximate horizontal slide using this equation:
  1996. *
  1997. * ( clickX / presentationWidth ) * numberOfSlides
  1998. */
  1999. function onProgressClicked( event ) {
  2000. event.preventDefault();
  2001. var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
  2002. var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
  2003. slide( slideIndex );
  2004. }
  2005. /**
  2006. * Event handler for navigation control buttons.
  2007. */
  2008. function onNavigateLeftClicked( event ) { event.preventDefault(); navigateLeft(); }
  2009. function onNavigateRightClicked( event ) { event.preventDefault(); navigateRight(); }
  2010. function onNavigateUpClicked( event ) { event.preventDefault(); navigateUp(); }
  2011. function onNavigateDownClicked( event ) { event.preventDefault(); navigateDown(); }
  2012. function onNavigatePrevClicked( event ) { event.preventDefault(); navigatePrev(); }
  2013. function onNavigateNextClicked( event ) { event.preventDefault(); navigateNext(); }
  2014. /**
  2015. * Handler for the window level 'hashchange' event.
  2016. */
  2017. function onWindowHashChange( event ) {
  2018. readURL();
  2019. }
  2020. /**
  2021. * Handler for the window level 'resize' event.
  2022. */
  2023. function onWindowResize( event ) {
  2024. layout();
  2025. }
  2026. /**
  2027. * Invoked when a slide is and we're in the overview.
  2028. */
  2029. function onOverviewSlideClicked( event ) {
  2030. // TODO There's a bug here where the event listeners are not
  2031. // removed after deactivating the overview.
  2032. if( eventsAreBound && isOverview() ) {
  2033. event.preventDefault();
  2034. var element = event.target;
  2035. while( element && !element.nodeName.match( /section/gi ) ) {
  2036. element = element.parentNode;
  2037. }
  2038. if( element && !element.classList.contains( 'disabled' ) ) {
  2039. deactivateOverview();
  2040. if( element.nodeName.match( /section/gi ) ) {
  2041. var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
  2042. v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
  2043. slide( h, v );
  2044. }
  2045. }
  2046. }
  2047. }
  2048. /**
  2049. * Handles clicks on links that are set to preview in the
  2050. * iframe overlay.
  2051. */
  2052. function onPreviewLinkClicked( event ) {
  2053. var url = event.target.getAttribute( 'href' );
  2054. if( url ) {
  2055. openPreview( url );
  2056. event.preventDefault();
  2057. }
  2058. }
  2059. // --------------------------------------------------------------------//
  2060. // ------------------------------- API --------------------------------//
  2061. // --------------------------------------------------------------------//
  2062. return {
  2063. initialize: initialize,
  2064. configure: configure,
  2065. sync: sync,
  2066. // Navigation methods
  2067. slide: slide,
  2068. left: navigateLeft,
  2069. right: navigateRight,
  2070. up: navigateUp,
  2071. down: navigateDown,
  2072. prev: navigatePrev,
  2073. next: navigateNext,
  2074. prevFragment: previousFragment,
  2075. nextFragment: nextFragment,
  2076. // Deprecated aliases
  2077. navigateTo: slide,
  2078. navigateLeft: navigateLeft,
  2079. navigateRight: navigateRight,
  2080. navigateUp: navigateUp,
  2081. navigateDown: navigateDown,
  2082. navigatePrev: navigatePrev,
  2083. navigateNext: navigateNext,
  2084. // Forces an update in slide layout
  2085. layout: layout,
  2086. // Returns an object with the available routes as booleans (left/right/top/bottom)
  2087. availableRoutes: availableRoutes,
  2088. // Returns an object with the available fragments as booleans (prev/next)
  2089. availableFragments: availableFragments,
  2090. // Toggles the overview mode on/off
  2091. toggleOverview: toggleOverview,
  2092. // Toggles the "black screen" mode on/off
  2093. togglePause: togglePause,
  2094. // State checks
  2095. isOverview: isOverview,
  2096. isPaused: isPaused,
  2097. // Adds or removes all internal event listeners (such as keyboard)
  2098. addEventListeners: addEventListeners,
  2099. removeEventListeners: removeEventListeners,
  2100. // Returns the indices of the current, or specified, slide
  2101. getIndices: getIndices,
  2102. // Returns the slide at the specified index, y is optional
  2103. getSlide: function( x, y ) {
  2104. var horizontalSlide = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
  2105. var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
  2106. if( typeof y !== 'undefined' ) {
  2107. return verticalSlides ? verticalSlides[ y ] : undefined;
  2108. }
  2109. return horizontalSlide;
  2110. },
  2111. // Returns the previous slide element, may be null
  2112. getPreviousSlide: function() {
  2113. return previousSlide;
  2114. },
  2115. // Returns the current slide element
  2116. getCurrentSlide: function() {
  2117. return currentSlide;
  2118. },
  2119. // Returns the current scale of the presentation content
  2120. getScale: function() {
  2121. return scale;
  2122. },
  2123. // Returns the current configuration object
  2124. getConfig: function() {
  2125. return config;
  2126. },
  2127. // Helper method, retrieves query string as a key/value hash
  2128. getQueryHash: function() {
  2129. var query = {};
  2130. location.search.replace( /[A-Z0-9]+?=(\w*)/gi, function(a) {
  2131. query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
  2132. } );
  2133. return query;
  2134. },
  2135. // Returns true if we're currently on the first slide
  2136. isFirstSlide: function() {
  2137. return document.querySelector( SLIDES_SELECTOR + '.past' ) == null ? true : false;
  2138. },
  2139. // Returns true if we're currently on the last slide
  2140. isLastSlide: function() {
  2141. if( currentSlide ) {
  2142. // Does this slide has next a sibling?
  2143. if( currentSlide.nextElementSibling ) return false;
  2144. // If it's vertical, does its parent have a next sibling?
  2145. if( isVerticalSlide( currentSlide ) && currentSlide.parentNode.nextElementSibling ) return false;
  2146. return true;
  2147. }
  2148. return false;
  2149. },
  2150. // Checks if reveal.js has been loaded and is ready for use
  2151. isReady: function() {
  2152. return loaded;
  2153. },
  2154. // Forward event binding to the reveal DOM element
  2155. addEventListener: function( type, listener, useCapture ) {
  2156. if( 'addEventListener' in window ) {
  2157. ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
  2158. }
  2159. },
  2160. removeEventListener: function( type, listener, useCapture ) {
  2161. if( 'addEventListener' in window ) {
  2162. ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
  2163. }
  2164. }
  2165. };
  2166. })();