reveal.js 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841
  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. "url('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 so
  360. var parallaxBackgroundImage = config.parallaxBackgroundImage,
  361. parallaxBackgroundSize = config.parallaxBackgroundSize;
  362. if( parallaxBackgroundImage ) {
  363. dom.wrapper.style.background = parallaxBackgroundImage;
  364. dom.wrapper.style.backgroundSize = parallaxBackgroundSize;
  365. // Make sure the below properties are set on the element - these properties are
  366. // needed for proper transitions to be set on the element via CSS. To remove
  367. // annoying background slide-in effect when the presentation starts, apply
  368. // these properties after short time delay
  369. setTimeout( function() {
  370. dom.wrapper.setAttribute( 'data-parallax-background', parallaxBackgroundImage );
  371. dom.wrapper.setAttribute( 'data-parallax-background-size', parallaxBackgroundSize );
  372. }, 1 );
  373. }
  374. }
  375. /**
  376. * Applies the configuration settings from the config
  377. * object. May be called multiple times.
  378. */
  379. function configure( options ) {
  380. dom.wrapper.classList.remove( config.transition );
  381. // New config options may be passed when this method
  382. // is invoked through the API after initialization
  383. if( typeof options === 'object' ) extend( config, options );
  384. // Force linear transition based on browser capabilities
  385. if( supports3DTransforms === false ) config.transition = 'linear';
  386. dom.wrapper.classList.add( config.transition );
  387. dom.wrapper.setAttribute( 'data-transition-speed', config.transitionSpeed );
  388. dom.wrapper.setAttribute( 'data-background-transition', config.backgroundTransition );
  389. dom.controls.style.display = config.controls ? 'block' : 'none';
  390. dom.progress.style.display = config.progress ? 'block' : 'none';
  391. if( config.rtl ) {
  392. dom.wrapper.classList.add( 'rtl' );
  393. }
  394. else {
  395. dom.wrapper.classList.remove( 'rtl' );
  396. }
  397. if( config.center ) {
  398. dom.wrapper.classList.add( 'center' );
  399. }
  400. else {
  401. dom.wrapper.classList.remove( 'center' );
  402. }
  403. if( config.mouseWheel ) {
  404. document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  405. document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
  406. }
  407. else {
  408. document.removeEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  409. document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
  410. }
  411. // Rolling 3D links
  412. if( config.rollingLinks ) {
  413. enableRollingLinks();
  414. }
  415. else {
  416. disableRollingLinks();
  417. }
  418. // Iframe link previews
  419. if( config.previewLinks ) {
  420. enablePreviewLinks();
  421. }
  422. else {
  423. disablePreviewLinks();
  424. enablePreviewLinks( '[data-preview-link]' );
  425. }
  426. // Load the theme in the config, if it's not already loaded
  427. if( config.theme && dom.theme ) {
  428. var themeURL = dom.theme.getAttribute( 'href' );
  429. var themeFinder = /[^\/]*?(?=\.css)/;
  430. var themeName = themeURL.match(themeFinder)[0];
  431. if( config.theme !== themeName ) {
  432. themeURL = themeURL.replace(themeFinder, config.theme);
  433. dom.theme.setAttribute( 'href', themeURL );
  434. }
  435. }
  436. sync();
  437. }
  438. /**
  439. * Binds all event listeners.
  440. */
  441. function addEventListeners() {
  442. eventsAreBound = true;
  443. window.addEventListener( 'hashchange', onWindowHashChange, false );
  444. window.addEventListener( 'resize', onWindowResize, false );
  445. if( config.touch ) {
  446. dom.wrapper.addEventListener( 'touchstart', onTouchStart, false );
  447. dom.wrapper.addEventListener( 'touchmove', onTouchMove, false );
  448. dom.wrapper.addEventListener( 'touchend', onTouchEnd, false );
  449. // Support pointer-style touch interaction as well
  450. if( window.navigator.msPointerEnabled ) {
  451. dom.wrapper.addEventListener( 'MSPointerDown', onPointerDown, false );
  452. dom.wrapper.addEventListener( 'MSPointerMove', onPointerMove, false );
  453. dom.wrapper.addEventListener( 'MSPointerUp', onPointerUp, false );
  454. }
  455. }
  456. if( config.keyboard ) {
  457. document.addEventListener( 'keydown', onDocumentKeyDown, false );
  458. }
  459. if ( config.progress && dom.progress ) {
  460. dom.progress.addEventListener( 'click', onProgressClicked, false );
  461. }
  462. [ 'touchstart', 'click' ].forEach( function( eventName ) {
  463. dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } );
  464. dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } );
  465. dom.controlsUp.forEach( function( el ) { el.addEventListener( eventName, onNavigateUpClicked, false ); } );
  466. dom.controlsDown.forEach( function( el ) { el.addEventListener( eventName, onNavigateDownClicked, false ); } );
  467. dom.controlsPrev.forEach( function( el ) { el.addEventListener( eventName, onNavigatePrevClicked, false ); } );
  468. dom.controlsNext.forEach( function( el ) { el.addEventListener( eventName, onNavigateNextClicked, false ); } );
  469. } );
  470. }
  471. /**
  472. * Unbinds all event listeners.
  473. */
  474. function removeEventListeners() {
  475. eventsAreBound = false;
  476. document.removeEventListener( 'keydown', onDocumentKeyDown, false );
  477. window.removeEventListener( 'hashchange', onWindowHashChange, false );
  478. window.removeEventListener( 'resize', onWindowResize, false );
  479. dom.wrapper.removeEventListener( 'touchstart', onTouchStart, false );
  480. dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false );
  481. dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false );
  482. if( window.navigator.msPointerEnabled ) {
  483. dom.wrapper.removeEventListener( 'MSPointerDown', onPointerDown, false );
  484. dom.wrapper.removeEventListener( 'MSPointerMove', onPointerMove, false );
  485. dom.wrapper.removeEventListener( 'MSPointerUp', onPointerUp, false );
  486. }
  487. if ( config.progress && dom.progress ) {
  488. dom.progress.removeEventListener( 'click', onProgressClicked, false );
  489. }
  490. [ 'touchstart', 'click' ].forEach( function( eventName ) {
  491. dom.controlsLeft.forEach( function( el ) { el.removeEventListener( eventName, onNavigateLeftClicked, false ); } );
  492. dom.controlsRight.forEach( function( el ) { el.removeEventListener( eventName, onNavigateRightClicked, false ); } );
  493. dom.controlsUp.forEach( function( el ) { el.removeEventListener( eventName, onNavigateUpClicked, false ); } );
  494. dom.controlsDown.forEach( function( el ) { el.removeEventListener( eventName, onNavigateDownClicked, false ); } );
  495. dom.controlsPrev.forEach( function( el ) { el.removeEventListener( eventName, onNavigatePrevClicked, false ); } );
  496. dom.controlsNext.forEach( function( el ) { el.removeEventListener( eventName, onNavigateNextClicked, false ); } );
  497. } );
  498. }
  499. /**
  500. * Extend object a with the properties of object b.
  501. * If there's a conflict, object b takes precedence.
  502. */
  503. function extend( a, b ) {
  504. for( var i in b ) {
  505. a[ i ] = b[ i ];
  506. }
  507. }
  508. /**
  509. * Converts the target object to an array.
  510. */
  511. function toArray( o ) {
  512. return Array.prototype.slice.call( o );
  513. }
  514. /**
  515. * Measures the distance in pixels between point a
  516. * and point b.
  517. *
  518. * @param {Object} a point with x/y properties
  519. * @param {Object} b point with x/y properties
  520. */
  521. function distanceBetween( a, b ) {
  522. var dx = a.x - b.x,
  523. dy = a.y - b.y;
  524. return Math.sqrt( dx*dx + dy*dy );
  525. }
  526. /**
  527. * Applies a CSS transform to the target element.
  528. */
  529. function transformElement( element, transform ) {
  530. element.style.WebkitTransform = transform;
  531. element.style.MozTransform = transform;
  532. element.style.msTransform = transform;
  533. element.style.OTransform = transform;
  534. element.style.transform = transform;
  535. }
  536. /**
  537. * Retrieves the height of the given element by looking
  538. * at the position and height of its immediate children.
  539. */
  540. function getAbsoluteHeight( element ) {
  541. var height = 0;
  542. if( element ) {
  543. var absoluteChildren = 0;
  544. toArray( element.childNodes ).forEach( function( child ) {
  545. if( typeof child.offsetTop === 'number' && child.style ) {
  546. // Count # of abs children
  547. if( child.style.position === 'absolute' ) {
  548. absoluteChildren += 1;
  549. }
  550. height = Math.max( height, child.offsetTop + child.offsetHeight );
  551. }
  552. } );
  553. // If there are no absolute children, use offsetHeight
  554. if( absoluteChildren === 0 ) {
  555. height = element.offsetHeight;
  556. }
  557. }
  558. return height;
  559. }
  560. /**
  561. * Returns the remaining height within the parent of the
  562. * target element after subtracting the height of all
  563. * siblings.
  564. *
  565. * remaining height = [parent height] - [ siblings height]
  566. */
  567. function getRemainingHeight( element, height ) {
  568. height = height || 0;
  569. if( element ) {
  570. var parent = element.parentNode;
  571. var siblings = parent.childNodes;
  572. // Subtract the height of each sibling
  573. toArray( siblings ).forEach( function( sibling ) {
  574. if( typeof sibling.offsetHeight === 'number' && sibling !== element ) {
  575. var styles = window.getComputedStyle( sibling ),
  576. marginTop = parseInt( styles.marginTop, 10 ),
  577. marginBottom = parseInt( styles.marginBottom, 10 );
  578. height -= sibling.offsetHeight + marginTop + marginBottom;
  579. }
  580. } );
  581. var elementStyles = window.getComputedStyle( element );
  582. // Subtract the margins of the target element
  583. height -= parseInt( elementStyles.marginTop, 10 ) +
  584. parseInt( elementStyles.marginBottom, 10 );
  585. }
  586. return height;
  587. }
  588. /**
  589. * Checks if this instance is being used to print a PDF.
  590. */
  591. function isPrintingPDF() {
  592. return ( /print-pdf/gi ).test( window.location.search );
  593. }
  594. /**
  595. * Hides the address bar if we're on a mobile device.
  596. */
  597. function hideAddressBar() {
  598. if( config.hideAddressBar && isMobileDevice ) {
  599. // Events that should trigger the address bar to hide
  600. window.addEventListener( 'load', removeAddressBar, false );
  601. window.addEventListener( 'orientationchange', removeAddressBar, false );
  602. }
  603. }
  604. /**
  605. * Causes the address bar to hide on mobile devices,
  606. * more vertical space ftw.
  607. */
  608. function removeAddressBar() {
  609. // Portrait and not Chrome for iOS
  610. if( window.orientation === 0 && !/crios/gi.test( navigator.userAgent ) ) {
  611. document.documentElement.style.overflow = 'scroll';
  612. document.body.style.height = '120%';
  613. }
  614. else {
  615. document.documentElement.style.overflow = '';
  616. document.body.style.height = '100%';
  617. }
  618. setTimeout( function() {
  619. window.scrollTo( 0, 1 );
  620. }, 10 );
  621. }
  622. /**
  623. * Dispatches an event of the specified type from the
  624. * reveal DOM element.
  625. */
  626. function dispatchEvent( type, properties ) {
  627. var event = document.createEvent( "HTMLEvents", 1, 2 );
  628. event.initEvent( type, true, true );
  629. extend( event, properties );
  630. dom.wrapper.dispatchEvent( event );
  631. }
  632. /**
  633. * Wrap all links in 3D goodness.
  634. */
  635. function enableRollingLinks() {
  636. if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) {
  637. var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
  638. for( var i = 0, len = anchors.length; i < len; i++ ) {
  639. var anchor = anchors[i];
  640. if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
  641. var span = document.createElement('span');
  642. span.setAttribute('data-title', anchor.text);
  643. span.innerHTML = anchor.innerHTML;
  644. anchor.classList.add( 'roll' );
  645. anchor.innerHTML = '';
  646. anchor.appendChild(span);
  647. }
  648. }
  649. }
  650. }
  651. /**
  652. * Unwrap all 3D links.
  653. */
  654. function disableRollingLinks() {
  655. var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
  656. for( var i = 0, len = anchors.length; i < len; i++ ) {
  657. var anchor = anchors[i];
  658. var span = anchor.querySelector( 'span' );
  659. if( span ) {
  660. anchor.classList.remove( 'roll' );
  661. anchor.innerHTML = span.innerHTML;
  662. }
  663. }
  664. }
  665. /**
  666. * Bind preview frame links.
  667. */
  668. function enablePreviewLinks( selector ) {
  669. var anchors = toArray( document.querySelectorAll( selector ? selector : 'a' ) );
  670. anchors.forEach( function( element ) {
  671. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  672. element.addEventListener( 'click', onPreviewLinkClicked, false );
  673. }
  674. } );
  675. }
  676. /**
  677. * Unbind preview frame links.
  678. */
  679. function disablePreviewLinks() {
  680. var anchors = toArray( document.querySelectorAll( 'a' ) );
  681. anchors.forEach( function( element ) {
  682. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  683. element.removeEventListener( 'click', onPreviewLinkClicked, false );
  684. }
  685. } );
  686. }
  687. /**
  688. * Opens a preview window for the target URL.
  689. */
  690. function openPreview( url ) {
  691. closePreview();
  692. dom.preview = document.createElement( 'div' );
  693. dom.preview.classList.add( 'preview-link-overlay' );
  694. dom.wrapper.appendChild( dom.preview );
  695. dom.preview.innerHTML = [
  696. '<header>',
  697. '<a class="close" href="#"><span class="icon"></span></a>',
  698. '<a class="external" href="'+ url +'" target="_blank"><span class="icon"></span></a>',
  699. '</header>',
  700. '<div class="spinner"></div>',
  701. '<div class="viewport">',
  702. '<iframe src="'+ url +'"></iframe>',
  703. '</div>'
  704. ].join('');
  705. dom.preview.querySelector( 'iframe' ).addEventListener( 'load', function( event ) {
  706. dom.preview.classList.add( 'loaded' );
  707. }, false );
  708. dom.preview.querySelector( '.close' ).addEventListener( 'click', function( event ) {
  709. closePreview();
  710. event.preventDefault();
  711. }, false );
  712. dom.preview.querySelector( '.external' ).addEventListener( 'click', function( event ) {
  713. closePreview();
  714. }, false );
  715. setTimeout( function() {
  716. dom.preview.classList.add( 'visible' );
  717. }, 1 );
  718. }
  719. /**
  720. * Closes the iframe preview window.
  721. */
  722. function closePreview() {
  723. if( dom.preview ) {
  724. dom.preview.setAttribute( 'src', '' );
  725. dom.preview.parentNode.removeChild( dom.preview );
  726. dom.preview = null;
  727. }
  728. }
  729. /**
  730. * Return a sorted fragments list, ordered by an increasing
  731. * "data-fragment-index" attribute.
  732. *
  733. * Fragments will be revealed in the order that they are returned by
  734. * this function, so you can use the index attributes to control the
  735. * order of fragment appearance.
  736. *
  737. * To maintain a sensible default fragment order, fragments are presumed
  738. * to be passed in document order. This function adds a "fragment-index"
  739. * attribute to each node if such an attribute is not already present,
  740. * and sets that attribute to an integer value which is the position of
  741. * the fragment within the fragments list.
  742. */
  743. function sortFragments( fragments ) {
  744. var a = toArray( fragments );
  745. a.forEach( function( el, idx ) {
  746. if( !el.hasAttribute( 'data-fragment-index' ) ) {
  747. el.setAttribute( 'data-fragment-index', idx );
  748. }
  749. } );
  750. a.sort( function( l, r ) {
  751. return l.getAttribute( 'data-fragment-index' ) - r.getAttribute( 'data-fragment-index');
  752. } );
  753. return a;
  754. }
  755. /**
  756. * Applies JavaScript-controlled layout rules to the
  757. * presentation.
  758. */
  759. function layout() {
  760. if( dom.wrapper && !isPrintingPDF() ) {
  761. // Available space to scale within
  762. var availableWidth = dom.wrapper.offsetWidth,
  763. availableHeight = dom.wrapper.offsetHeight;
  764. // Reduce available space by margin
  765. availableWidth -= ( availableHeight * config.margin );
  766. availableHeight -= ( availableHeight * config.margin );
  767. // Dimensions of the content
  768. var slideWidth = config.width,
  769. slideHeight = config.height,
  770. slidePadding = 20; // TODO Dig this out of DOM
  771. // Layout the contents of the slides
  772. layoutSlideContents( config.width, config.height, slidePadding );
  773. // Slide width may be a percentage of available width
  774. if( typeof slideWidth === 'string' && /%$/.test( slideWidth ) ) {
  775. slideWidth = parseInt( slideWidth, 10 ) / 100 * availableWidth;
  776. }
  777. // Slide height may be a percentage of available height
  778. if( typeof slideHeight === 'string' && /%$/.test( slideHeight ) ) {
  779. slideHeight = parseInt( slideHeight, 10 ) / 100 * availableHeight;
  780. }
  781. dom.slides.style.width = slideWidth + 'px';
  782. dom.slides.style.height = slideHeight + 'px';
  783. // Determine scale of content to fit within available space
  784. scale = Math.min( availableWidth / slideWidth, availableHeight / slideHeight );
  785. // Respect max/min scale settings
  786. scale = Math.max( scale, config.minScale );
  787. scale = Math.min( scale, config.maxScale );
  788. // Prefer applying scale via zoom since Chrome blurs scaled content
  789. // with nested transforms
  790. if( typeof dom.slides.style.zoom !== 'undefined' && !navigator.userAgent.match( /(iphone|ipod|ipad|android)/gi ) ) {
  791. dom.slides.style.zoom = scale;
  792. }
  793. // Apply scale transform as a fallback
  794. else {
  795. transformElement( dom.slides, 'translate(-50%, -50%) scale('+ scale +') translate(50%, 50%)' );
  796. }
  797. // Select all slides, vertical and horizontal
  798. var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
  799. for( var i = 0, len = slides.length; i < len; i++ ) {
  800. var slide = slides[ i ];
  801. // Don't bother updating invisible slides
  802. if( slide.style.display === 'none' ) {
  803. continue;
  804. }
  805. if( config.center ) {
  806. // Vertical stacks are not centred since their section
  807. // children will be
  808. if( slide.classList.contains( 'stack' ) ) {
  809. slide.style.top = 0;
  810. }
  811. else {
  812. slide.style.top = Math.max( - ( getAbsoluteHeight( slide ) / 2 ) - slidePadding, -slideHeight / 2 ) + 'px';
  813. }
  814. }
  815. else {
  816. slide.style.top = '';
  817. }
  818. }
  819. updateProgress();
  820. updateParallax();
  821. }
  822. }
  823. /**
  824. * Applies layout logic to the contents of all slides in
  825. * the presentation.
  826. */
  827. function layoutSlideContents( width, height, padding ) {
  828. // Handle sizing of elements with the 'stretch' class
  829. toArray( dom.slides.querySelectorAll( 'section > .stretch' ) ).forEach( function( element ) {
  830. // Determine how much vertical space we can use
  831. var remainingHeight = getRemainingHeight( element, ( height - ( padding * 2 ) ) );
  832. // Consider the aspect ratio of media elements
  833. if( /(img|video)/gi.test( element.nodeName ) ) {
  834. var nw = element.naturalWidth || element.videoWidth,
  835. nh = element.naturalHeight || element.videoHeight;
  836. var es = Math.min( width / nw, remainingHeight / nh );
  837. element.style.width = ( nw * es ) + 'px';
  838. element.style.height = ( nh * es ) + 'px';
  839. }
  840. else {
  841. element.style.width = width + 'px';
  842. element.style.height = remainingHeight + 'px';
  843. }
  844. } );
  845. }
  846. /**
  847. * Stores the vertical index of a stack so that the same
  848. * vertical slide can be selected when navigating to and
  849. * from the stack.
  850. *
  851. * @param {HTMLElement} stack The vertical stack element
  852. * @param {int} v Index to memorize
  853. */
  854. function setPreviousVerticalIndex( stack, v ) {
  855. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
  856. stack.setAttribute( 'data-previous-indexv', v || 0 );
  857. }
  858. }
  859. /**
  860. * Retrieves the vertical index which was stored using
  861. * #setPreviousVerticalIndex() or 0 if no previous index
  862. * exists.
  863. *
  864. * @param {HTMLElement} stack The vertical stack element
  865. */
  866. function getPreviousVerticalIndex( stack ) {
  867. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
  868. // Prefer manually defined start-indexv
  869. var attributeName = stack.hasAttribute( 'data-start-indexv' ) ? 'data-start-indexv' : 'data-previous-indexv';
  870. return parseInt( stack.getAttribute( attributeName ) || 0, 10 );
  871. }
  872. return 0;
  873. }
  874. /**
  875. * Displays the overview of slides (quick nav) by
  876. * scaling down and arranging all slide elements.
  877. *
  878. * Experimental feature, might be dropped if perf
  879. * can't be improved.
  880. */
  881. function activateOverview() {
  882. // Only proceed if enabled in config
  883. if( config.overview ) {
  884. // Don't auto-slide while in overview mode
  885. cancelAutoSlide();
  886. var wasActive = dom.wrapper.classList.contains( 'overview' );
  887. // Vary the depth of the overview based on screen size
  888. var depth = window.innerWidth < 400 ? 1000 : 2500;
  889. dom.wrapper.classList.add( 'overview' );
  890. dom.wrapper.classList.remove( 'overview-deactivating' );
  891. clearTimeout( activateOverviewTimeout );
  892. clearTimeout( deactivateOverviewTimeout );
  893. // Not the pretties solution, but need to let the overview
  894. // class apply first so that slides are measured accurately
  895. // before we can position them
  896. activateOverviewTimeout = setTimeout( function() {
  897. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  898. for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
  899. var hslide = horizontalSlides[i],
  900. hoffset = config.rtl ? -105 : 105;
  901. hslide.setAttribute( 'data-index-h', i );
  902. // Apply CSS transform
  903. transformElement( hslide, 'translateZ(-'+ depth +'px) translate(' + ( ( i - indexh ) * hoffset ) + '%, 0%)' );
  904. if( hslide.classList.contains( 'stack' ) ) {
  905. var verticalSlides = hslide.querySelectorAll( 'section' );
  906. for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
  907. var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
  908. var vslide = verticalSlides[j];
  909. vslide.setAttribute( 'data-index-h', i );
  910. vslide.setAttribute( 'data-index-v', j );
  911. // Apply CSS transform
  912. transformElement( vslide, 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)' );
  913. // Navigate to this slide on click
  914. vslide.addEventListener( 'click', onOverviewSlideClicked, true );
  915. }
  916. }
  917. else {
  918. // Navigate to this slide on click
  919. hslide.addEventListener( 'click', onOverviewSlideClicked, true );
  920. }
  921. }
  922. updateSlidesVisibility();
  923. layout();
  924. if( !wasActive ) {
  925. // Notify observers of the overview showing
  926. dispatchEvent( 'overviewshown', {
  927. 'indexh': indexh,
  928. 'indexv': indexv,
  929. 'currentSlide': currentSlide
  930. } );
  931. }
  932. }, 10 );
  933. }
  934. }
  935. /**
  936. * Exits the slide overview and enters the currently
  937. * active slide.
  938. */
  939. function deactivateOverview() {
  940. // Only proceed if enabled in config
  941. if( config.overview ) {
  942. clearTimeout( activateOverviewTimeout );
  943. clearTimeout( deactivateOverviewTimeout );
  944. dom.wrapper.classList.remove( 'overview' );
  945. // Temporarily add a class so that transitions can do different things
  946. // depending on whether they are exiting/entering overview, or just
  947. // moving from slide to slide
  948. dom.wrapper.classList.add( 'overview-deactivating' );
  949. deactivateOverviewTimeout = setTimeout( function () {
  950. dom.wrapper.classList.remove( 'overview-deactivating' );
  951. }, 1 );
  952. // Select all slides
  953. toArray( document.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
  954. // Resets all transforms to use the external styles
  955. transformElement( slide, '' );
  956. slide.removeEventListener( 'click', onOverviewSlideClicked, true );
  957. } );
  958. slide( indexh, indexv );
  959. cueAutoSlide();
  960. // Notify observers of the overview hiding
  961. dispatchEvent( 'overviewhidden', {
  962. 'indexh': indexh,
  963. 'indexv': indexv,
  964. 'currentSlide': currentSlide
  965. } );
  966. }
  967. }
  968. /**
  969. * Toggles the slide overview mode on and off.
  970. *
  971. * @param {Boolean} override Optional flag which overrides the
  972. * toggle logic and forcibly sets the desired state. True means
  973. * overview is open, false means it's closed.
  974. */
  975. function toggleOverview( override ) {
  976. if( typeof override === 'boolean' ) {
  977. override ? activateOverview() : deactivateOverview();
  978. }
  979. else {
  980. isOverview() ? deactivateOverview() : activateOverview();
  981. }
  982. }
  983. /**
  984. * Checks if the overview is currently active.
  985. *
  986. * @return {Boolean} true if the overview is active,
  987. * false otherwise
  988. */
  989. function isOverview() {
  990. return dom.wrapper.classList.contains( 'overview' );
  991. }
  992. /**
  993. * Checks if the current or specified slide is vertical
  994. * (nested within another slide).
  995. *
  996. * @param {HTMLElement} slide [optional] The slide to check
  997. * orientation of
  998. */
  999. function isVerticalSlide( slide ) {
  1000. // Prefer slide argument, otherwise use current slide
  1001. slide = slide ? slide : currentSlide;
  1002. return slide && slide.parentNode && !!slide.parentNode.nodeName.match( /section/i );
  1003. }
  1004. /**
  1005. * Handling the fullscreen functionality via the fullscreen API
  1006. *
  1007. * @see http://fullscreen.spec.whatwg.org/
  1008. * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
  1009. */
  1010. function enterFullscreen() {
  1011. var element = document.body;
  1012. // Check which implementation is available
  1013. var requestMethod = element.requestFullScreen ||
  1014. element.webkitRequestFullscreen ||
  1015. element.webkitRequestFullScreen ||
  1016. element.mozRequestFullScreen ||
  1017. element.msRequestFullScreen;
  1018. if( requestMethod ) {
  1019. requestMethod.apply( element );
  1020. }
  1021. }
  1022. /**
  1023. * Enters the paused mode which fades everything on screen to
  1024. * black.
  1025. */
  1026. function pause() {
  1027. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1028. cancelAutoSlide();
  1029. dom.wrapper.classList.add( 'paused' );
  1030. if( wasPaused === false ) {
  1031. dispatchEvent( 'paused' );
  1032. }
  1033. }
  1034. /**
  1035. * Exits from the paused mode.
  1036. */
  1037. function resume() {
  1038. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1039. dom.wrapper.classList.remove( 'paused' );
  1040. cueAutoSlide();
  1041. if( wasPaused ) {
  1042. dispatchEvent( 'resumed' );
  1043. }
  1044. }
  1045. /**
  1046. * Toggles the paused mode on and off.
  1047. */
  1048. function togglePause() {
  1049. if( isPaused() ) {
  1050. resume();
  1051. }
  1052. else {
  1053. pause();
  1054. }
  1055. }
  1056. /**
  1057. * Checks if we are currently in the paused mode.
  1058. */
  1059. function isPaused() {
  1060. return dom.wrapper.classList.contains( 'paused' );
  1061. }
  1062. /**
  1063. * Steps from the current point in the presentation to the
  1064. * slide which matches the specified horizontal and vertical
  1065. * indices.
  1066. *
  1067. * @param {int} h Horizontal index of the target slide
  1068. * @param {int} v Vertical index of the target slide
  1069. * @param {int} f Optional index of a fragment within the
  1070. * target slide to activate
  1071. * @param {int} o Optional origin for use in multimaster environments
  1072. */
  1073. function slide( h, v, f, o ) {
  1074. // Remember where we were at before
  1075. previousSlide = currentSlide;
  1076. // Query all horizontal slides in the deck
  1077. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  1078. // If no vertical index is specified and the upcoming slide is a
  1079. // stack, resume at its previous vertical index
  1080. if( v === undefined ) {
  1081. v = getPreviousVerticalIndex( horizontalSlides[ h ] );
  1082. }
  1083. // If we were on a vertical stack, remember what vertical index
  1084. // it was on so we can resume at the same position when returning
  1085. if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
  1086. setPreviousVerticalIndex( previousSlide.parentNode, indexv );
  1087. }
  1088. // Remember the state before this slide
  1089. var stateBefore = state.concat();
  1090. // Reset the state array
  1091. state.length = 0;
  1092. var indexhBefore = indexh || 0,
  1093. indexvBefore = indexv || 0;
  1094. // Activate and transition to the new slide
  1095. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
  1096. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
  1097. // Update the visibility of slides now that the indices have changed
  1098. updateSlidesVisibility();
  1099. layout();
  1100. // Apply the new state
  1101. stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
  1102. // Check if this state existed on the previous slide. If it
  1103. // did, we will avoid adding it repeatedly
  1104. for( var j = 0; j < stateBefore.length; j++ ) {
  1105. if( stateBefore[j] === state[i] ) {
  1106. stateBefore.splice( j, 1 );
  1107. continue stateLoop;
  1108. }
  1109. }
  1110. document.documentElement.classList.add( state[i] );
  1111. // Dispatch custom event matching the state's name
  1112. dispatchEvent( state[i] );
  1113. }
  1114. // Clean up the remains of the previous state
  1115. while( stateBefore.length ) {
  1116. document.documentElement.classList.remove( stateBefore.pop() );
  1117. }
  1118. // If the overview is active, re-activate it to update positions
  1119. if( isOverview() ) {
  1120. activateOverview();
  1121. }
  1122. // Find the current horizontal slide and any possible vertical slides
  1123. // within it
  1124. var currentHorizontalSlide = horizontalSlides[ indexh ],
  1125. currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
  1126. // Store references to the previous and current slides
  1127. currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
  1128. ////////////////////////////////////
  1129. // Show fragment, if specified
  1130. if( typeof f !== 'undefined' ) {
  1131. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
  1132. toArray( fragments ).forEach( function( fragment, indexf ) {
  1133. if( indexf < f ) {
  1134. fragment.classList.add( 'visible' );
  1135. }
  1136. else {
  1137. fragment.classList.remove( 'visible' );
  1138. }
  1139. } );
  1140. }
  1141. // Dispatch an event if the slide changed
  1142. var slideChanged = ( indexh !== indexhBefore || indexv !== indexvBefore );
  1143. if( slideChanged ) {
  1144. dispatchEvent( 'slidechanged', {
  1145. 'indexh': indexh,
  1146. 'indexv': indexv,
  1147. 'previousSlide': previousSlide,
  1148. 'currentSlide': currentSlide,
  1149. 'origin': o
  1150. } );
  1151. }
  1152. else {
  1153. // Ensure that the previous slide is never the same as the current
  1154. previousSlide = null;
  1155. }
  1156. // Solves an edge case where the previous slide maintains the
  1157. // 'present' class when navigating between adjacent vertical
  1158. // stacks
  1159. if( previousSlide ) {
  1160. previousSlide.classList.remove( 'present' );
  1161. // Reset all slides upon navigate to home
  1162. // Issue: #285
  1163. if ( document.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
  1164. // Launch async task
  1165. setTimeout( function () {
  1166. var slides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
  1167. for( i in slides ) {
  1168. if( slides[i] ) {
  1169. // Reset stack
  1170. setPreviousVerticalIndex( slides[i], 0 );
  1171. }
  1172. }
  1173. }, 0 );
  1174. }
  1175. }
  1176. // Handle embedded content
  1177. if( slideChanged ) {
  1178. stopEmbeddedContent( previousSlide );
  1179. startEmbeddedContent( currentSlide );
  1180. }
  1181. updateControls();
  1182. updateProgress();
  1183. updateBackground();
  1184. updateParallax();
  1185. // Update the URL hash
  1186. writeURL();
  1187. }
  1188. /**
  1189. * Syncs the presentation with the current DOM. Useful
  1190. * when new slides or control elements are added or when
  1191. * the configuration has changed.
  1192. */
  1193. function sync() {
  1194. // Subscribe to input
  1195. removeEventListeners();
  1196. addEventListeners();
  1197. // Force a layout to make sure the current config is accounted for
  1198. layout();
  1199. // Reflect the current autoSlide value
  1200. autoSlide = config.autoSlide;
  1201. // Start auto-sliding if it's enabled
  1202. cueAutoSlide();
  1203. // Re-create the slide backgrounds
  1204. createBackgrounds();
  1205. updateControls();
  1206. updateProgress();
  1207. updateBackground();
  1208. }
  1209. /**
  1210. * Updates one dimension of slides by showing the slide
  1211. * with the specified index.
  1212. *
  1213. * @param {String} selector A CSS selector that will fetch
  1214. * the group of slides we are working with
  1215. * @param {Number} index The index of the slide that should be
  1216. * shown
  1217. *
  1218. * @return {Number} The index of the slide that is now shown,
  1219. * might differ from the passed in index if it was out of
  1220. * bounds.
  1221. */
  1222. function updateSlides( selector, index ) {
  1223. // Select all slides and convert the NodeList result to
  1224. // an array
  1225. var slides = toArray( document.querySelectorAll( selector ) ),
  1226. slidesLength = slides.length;
  1227. if( slidesLength ) {
  1228. // Should the index loop?
  1229. if( config.loop ) {
  1230. index %= slidesLength;
  1231. if( index < 0 ) {
  1232. index = slidesLength + index;
  1233. }
  1234. }
  1235. // Enforce max and minimum index bounds
  1236. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  1237. for( var i = 0; i < slidesLength; i++ ) {
  1238. var element = slides[i];
  1239. var reverse = config.rtl && !isVerticalSlide( element );
  1240. element.classList.remove( 'past' );
  1241. element.classList.remove( 'present' );
  1242. element.classList.remove( 'future' );
  1243. // http://www.w3.org/html/wg/drafts/html/master/editing.html#the-hidden-attribute
  1244. element.setAttribute( 'hidden', '' );
  1245. if( i < index ) {
  1246. // Any element previous to index is given the 'past' class
  1247. element.classList.add( reverse ? 'future' : 'past' );
  1248. }
  1249. else if( i > index ) {
  1250. // Any element subsequent to index is given the 'future' class
  1251. element.classList.add( reverse ? 'past' : 'future' );
  1252. var fragments = toArray( element.querySelectorAll( '.fragment.visible' ) );
  1253. // No fragments in future slides should be visible ahead of time
  1254. while( fragments.length ) {
  1255. fragments.pop().classList.remove( 'visible' );
  1256. }
  1257. }
  1258. // If this element contains vertical slides
  1259. if( element.querySelector( 'section' ) ) {
  1260. element.classList.add( 'stack' );
  1261. }
  1262. }
  1263. // Mark the current slide as present
  1264. slides[index].classList.add( 'present' );
  1265. slides[index].removeAttribute( 'hidden' );
  1266. // If this slide has a state associated with it, add it
  1267. // onto the current state of the deck
  1268. var slideState = slides[index].getAttribute( 'data-state' );
  1269. if( slideState ) {
  1270. state = state.concat( slideState.split( ' ' ) );
  1271. }
  1272. // If this slide has a data-autoslide attribute associated use this as
  1273. // autoSlide value otherwise use the global configured time
  1274. var slideAutoSlide = slides[index].getAttribute( 'data-autoslide' );
  1275. if( slideAutoSlide ) {
  1276. autoSlide = parseInt( slideAutoSlide, 10 );
  1277. }
  1278. else {
  1279. autoSlide = config.autoSlide;
  1280. }
  1281. cueAutoSlide();
  1282. }
  1283. else {
  1284. // Since there are no slides we can't be anywhere beyond the
  1285. // zeroth index
  1286. index = 0;
  1287. }
  1288. return index;
  1289. }
  1290. /**
  1291. * Optimization method; hide all slides that are far away
  1292. * from the present slide.
  1293. */
  1294. function updateSlidesVisibility() {
  1295. // Select all slides and convert the NodeList result to
  1296. // an array
  1297. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ),
  1298. horizontalSlidesLength = horizontalSlides.length,
  1299. distanceX,
  1300. distanceY;
  1301. if( horizontalSlidesLength ) {
  1302. // The number of steps away from the present slide that will
  1303. // be visible
  1304. var viewDistance = isOverview() ? 10 : config.viewDistance;
  1305. // Limit view distance on weaker devices
  1306. if( isMobileDevice ) {
  1307. viewDistance = isOverview() ? 6 : 1;
  1308. }
  1309. for( var x = 0; x < horizontalSlidesLength; x++ ) {
  1310. var horizontalSlide = horizontalSlides[x];
  1311. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) ),
  1312. verticalSlidesLength = verticalSlides.length;
  1313. // Loops so that it measures 1 between the first and last slides
  1314. distanceX = Math.abs( ( indexh - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0;
  1315. // Show the horizontal slide if it's within the view distance
  1316. horizontalSlide.style.display = distanceX > viewDistance ? 'none' : 'block';
  1317. if( verticalSlidesLength ) {
  1318. var oy = getPreviousVerticalIndex( horizontalSlide );
  1319. for( var y = 0; y < verticalSlidesLength; y++ ) {
  1320. var verticalSlide = verticalSlides[y];
  1321. distanceY = x === indexh ? Math.abs( indexv - y ) : Math.abs( y - oy );
  1322. verticalSlide.style.display = ( distanceX + distanceY ) > viewDistance ? 'none' : 'block';
  1323. }
  1324. }
  1325. }
  1326. }
  1327. }
  1328. /**
  1329. * Updates the progress bar to reflect the current slide.
  1330. */
  1331. function updateProgress() {
  1332. // Update progress if enabled
  1333. if( config.progress && dom.progress ) {
  1334. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1335. // The number of past and total slides
  1336. var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  1337. var pastCount = 0;
  1338. // Step through all slides and count the past ones
  1339. mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
  1340. var horizontalSlide = horizontalSlides[i];
  1341. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1342. for( var j = 0; j < verticalSlides.length; j++ ) {
  1343. // Stop as soon as we arrive at the present
  1344. if( verticalSlides[j].classList.contains( 'present' ) ) {
  1345. break mainLoop;
  1346. }
  1347. pastCount++;
  1348. }
  1349. // Stop as soon as we arrive at the present
  1350. if( horizontalSlide.classList.contains( 'present' ) ) {
  1351. break;
  1352. }
  1353. // Don't count the wrapping section for vertical slides
  1354. if( horizontalSlide.classList.contains( 'stack' ) === false ) {
  1355. pastCount++;
  1356. }
  1357. }
  1358. dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px';
  1359. }
  1360. }
  1361. /**
  1362. * Updates the state of all control/navigation arrows.
  1363. */
  1364. function updateControls() {
  1365. var routes = availableRoutes();
  1366. var fragments = availableFragments();
  1367. // Remove the 'enabled' class from all directions
  1368. dom.controlsLeft.concat( dom.controlsRight )
  1369. .concat( dom.controlsUp )
  1370. .concat( dom.controlsDown )
  1371. .concat( dom.controlsPrev )
  1372. .concat( dom.controlsNext ).forEach( function( node ) {
  1373. node.classList.remove( 'enabled' );
  1374. node.classList.remove( 'fragmented' );
  1375. } );
  1376. // Add the 'enabled' class to the available routes
  1377. if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1378. if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1379. if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1380. if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1381. // Prev/next buttons
  1382. if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1383. if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1384. // Highlight fragment directions
  1385. if( currentSlide ) {
  1386. // Always apply fragment decorator to prev/next buttons
  1387. if( fragments.prev ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1388. if( fragments.next ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1389. // Apply fragment decorators to directional buttons based on
  1390. // what slide axis they are in
  1391. if( isVerticalSlide( currentSlide ) ) {
  1392. if( fragments.prev ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1393. if( fragments.next ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1394. }
  1395. else {
  1396. if( fragments.prev ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1397. if( fragments.next ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1398. }
  1399. }
  1400. }
  1401. /**
  1402. * Updates the background elements to reflect the current
  1403. * slide.
  1404. */
  1405. function updateBackground() {
  1406. // Update the classes of all backgrounds to match the
  1407. // states of their slides (past/present/future)
  1408. toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) {
  1409. // Reverse past/future classes when in RTL mode
  1410. var horizontalPast = config.rtl ? 'future' : 'past',
  1411. horizontalFuture = config.rtl ? 'past' : 'future';
  1412. backgroundh.className = 'slide-background ' + ( h < indexh ? horizontalPast : h > indexh ? horizontalFuture : 'present' );
  1413. toArray( backgroundh.childNodes ).forEach( function( backgroundv, v ) {
  1414. backgroundv.className = 'slide-background ' + ( v < indexv ? 'past' : v > indexv ? 'future' : 'present' );
  1415. } );
  1416. } );
  1417. // Allow the first background to apply without transition
  1418. setTimeout( function() {
  1419. dom.background.classList.remove( 'no-transition' );
  1420. }, 1 );
  1421. }
  1422. /**
  1423. * Updates the position of the parallax background based
  1424. * on the current slide index.
  1425. */
  1426. function updateParallax() {
  1427. // Animate parallax background
  1428. if( dom.wrapper.getAttribute( 'data-parallax-background' ) || config.parallaxBackgroundImage ) {
  1429. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1430. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1431. var backgroundSize = dom.wrapper.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.wrapper.offsetWidth;
  1441. var horizontalSlideCount = horizontalSlides.length;
  1442. var horizontalOffset = -( backgroundWidth - slideWidth ) / ( horizontalSlideCount-1 ) * indexh;
  1443. var slideHeight = dom.wrapper.offsetHeight;
  1444. var verticalSlideCount = verticalSlides.length;
  1445. var verticalOffset = verticalSlideCount > 0 ? -( backgroundHeight - slideHeight ) / ( verticalSlideCount-1 ) * indexv : 0;
  1446. dom.wrapper.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. })();