reveal.js 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559
  1. /*!
  2. * reveal.js
  3. * http://lab.hakim.se/reveal-js
  4. * MIT licensed
  5. *
  6. * Copyright (C) 2014 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-of-type',
  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. // Display the page number of the current slide
  30. slideNumber: false,
  31. // Push each slide change to the browser history
  32. history: false,
  33. // Enable keyboard shortcuts for navigation
  34. keyboard: true,
  35. // Enable the slide overview mode
  36. overview: true,
  37. // Vertical centering of slides
  38. center: true,
  39. // Enables touch navigation on devices with touch input
  40. touch: true,
  41. // Loop the presentation
  42. loop: false,
  43. // Change the presentation direction to be RTL
  44. rtl: false,
  45. // Turns fragments on and off globally
  46. fragments: true,
  47. // Flags if the presentation is running in an embedded mode,
  48. // i.e. contained within a limited portion of the screen
  49. embedded: false,
  50. // Number of milliseconds between automatically proceeding to the
  51. // next slide, disabled when set to 0, this value can be overwritten
  52. // by using a data-autoslide attribute on your slides
  53. autoSlide: 0,
  54. // Stop auto-sliding after user input
  55. autoSlideStoppable: true,
  56. // Enable slide navigation via mouse wheel
  57. mouseWheel: false,
  58. // Apply a 3D roll to links on hover
  59. rollingLinks: false,
  60. // Hides the address bar on mobile devices
  61. hideAddressBar: true,
  62. // Opens links in an iframe preview overlay
  63. previewLinks: false,
  64. // Focuses body when page changes visiblity to ensure keyboard shortcuts work
  65. focusBodyOnPageVisiblityChange: true,
  66. // Theme (see /css/theme)
  67. theme: null,
  68. // Transition style
  69. transition: 'default', // default/cube/page/concave/zoom/linear/fade/none
  70. // Transition speed
  71. transitionSpeed: 'default', // default/fast/slow
  72. // Transition style for full page slide backgrounds
  73. backgroundTransition: 'default', // default/linear/none
  74. // Parallax background image
  75. parallaxBackgroundImage: '', // CSS syntax, e.g. "a.jpg"
  76. // Parallax background size
  77. parallaxBackgroundSize: '', // CSS syntax, e.g. "3000px 2000px"
  78. // Number of slides away from the current that are visible
  79. viewDistance: 3,
  80. // Script dependencies to load
  81. dependencies: []
  82. },
  83. // Flags if reveal.js is loaded (has dispatched the 'ready' event)
  84. loaded = false,
  85. // The horizontal and vertical index of the currently active slide
  86. indexh,
  87. indexv,
  88. // The previous and current slide HTML elements
  89. previousSlide,
  90. currentSlide,
  91. previousBackground,
  92. // Slides may hold a data-state attribute which we pick up and apply
  93. // as a class to the body. This list contains the combined state of
  94. // all current slides.
  95. state = [],
  96. // The current scale of the presentation (see width/height config)
  97. scale = 1,
  98. // Cached references to DOM elements
  99. dom = {},
  100. // Features supported by the browser, see #checkCapabilities()
  101. features = {},
  102. // Client is a mobile device, see #checkCapabilities()
  103. isMobileDevice,
  104. // Throttles mouse wheel navigation
  105. lastMouseWheelStep = 0,
  106. // Delays updates to the URL due to a Chrome thumbnailer bug
  107. writeURLTimeout = 0,
  108. // Flags if the interaction event listeners are bound
  109. eventsAreBound = false,
  110. // The current auto-slide duration
  111. autoSlide = 0,
  112. // Auto slide properties
  113. autoSlidePlayer,
  114. autoSlideTimeout = 0,
  115. autoSlideStartTime = -1,
  116. autoSlidePaused = false,
  117. // Holds information about the currently ongoing touch input
  118. touch = {
  119. startX: 0,
  120. startY: 0,
  121. startSpan: 0,
  122. startCount: 0,
  123. captured: false,
  124. threshold: 40
  125. };
  126. /**
  127. * Starts up the presentation if the client is capable.
  128. */
  129. function initialize( options ) {
  130. checkCapabilities();
  131. if( !features.transforms2d && !features.transforms3d ) {
  132. document.body.setAttribute( 'class', 'no-transforms' );
  133. // If the browser doesn't support core features we won't be
  134. // using JavaScript to control the presentation
  135. return;
  136. }
  137. // Force a layout when the whole page, incl fonts, has loaded
  138. window.addEventListener( 'load', layout, false );
  139. var query = Reveal.getQueryHash();
  140. // Do not accept new dependencies via query config to avoid
  141. // the potential of malicious script injection
  142. if( typeof query['dependencies'] !== 'undefined' ) delete query['dependencies'];
  143. // Copy options over to our config object
  144. extend( config, options );
  145. extend( config, query );
  146. // Hide the address bar in mobile browsers
  147. hideAddressBar();
  148. // Loads the dependencies and continues to #start() once done
  149. load();
  150. }
  151. /**
  152. * Inspect the client to see what it's capable of, this
  153. * should only happens once per runtime.
  154. */
  155. function checkCapabilities() {
  156. features.transforms3d = 'WebkitPerspective' in document.body.style ||
  157. 'MozPerspective' in document.body.style ||
  158. 'msPerspective' in document.body.style ||
  159. 'OPerspective' in document.body.style ||
  160. 'perspective' in document.body.style;
  161. features.transforms2d = 'WebkitTransform' in document.body.style ||
  162. 'MozTransform' in document.body.style ||
  163. 'msTransform' in document.body.style ||
  164. 'OTransform' in document.body.style ||
  165. 'transform' in document.body.style;
  166. features.requestAnimationFrameMethod = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
  167. features.requestAnimationFrame = typeof features.requestAnimationFrameMethod === 'function';
  168. features.canvas = !!document.createElement( 'canvas' ).getContext;
  169. isMobileDevice = navigator.userAgent.match( /(iphone|ipod|android)/gi );
  170. }
  171. /**
  172. * Loads the dependencies of reveal.js. Dependencies are
  173. * defined via the configuration option 'dependencies'
  174. * and will be loaded prior to starting/binding reveal.js.
  175. * Some dependencies may have an 'async' flag, if so they
  176. * will load after reveal.js has been started up.
  177. */
  178. function load() {
  179. var scripts = [],
  180. scriptsAsync = [],
  181. scriptsToPreload = 0;
  182. // Called once synchronous scripts finish loading
  183. function proceed() {
  184. if( scriptsAsync.length ) {
  185. // Load asynchronous scripts
  186. head.js.apply( null, scriptsAsync );
  187. }
  188. start();
  189. }
  190. function loadScript( s ) {
  191. head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], function() {
  192. // Extension may contain callback functions
  193. if( typeof s.callback === 'function' ) {
  194. s.callback.apply( this );
  195. }
  196. if( --scriptsToPreload === 0 ) {
  197. proceed();
  198. }
  199. });
  200. }
  201. for( var i = 0, len = config.dependencies.length; i < len; i++ ) {
  202. var s = config.dependencies[i];
  203. // Load if there's no condition or the condition is truthy
  204. if( !s.condition || s.condition() ) {
  205. if( s.async ) {
  206. scriptsAsync.push( s.src );
  207. }
  208. else {
  209. scripts.push( s.src );
  210. }
  211. loadScript( s );
  212. }
  213. }
  214. if( scripts.length ) {
  215. scriptsToPreload = scripts.length;
  216. // Load synchronous scripts
  217. head.js.apply( null, scripts );
  218. }
  219. else {
  220. proceed();
  221. }
  222. }
  223. /**
  224. * Starts up reveal.js by binding input events and navigating
  225. * to the current URL deeplink if there is one.
  226. */
  227. function start() {
  228. // Make sure we've got all the DOM elements we need
  229. setupDOM();
  230. // Resets all vertical slides so that only the first is visible
  231. resetVerticalSlides();
  232. // Updates the presentation to match the current configuration values
  233. configure();
  234. // Read the initial hash
  235. readURL();
  236. // Update all backgrounds
  237. updateBackground( true );
  238. // Notify listeners that the presentation is ready but use a 1ms
  239. // timeout to ensure it's not fired synchronously after #initialize()
  240. setTimeout( function() {
  241. // Enable transitions now that we're loaded
  242. dom.slides.classList.remove( 'no-transition' );
  243. loaded = true;
  244. dispatchEvent( 'ready', {
  245. 'indexh': indexh,
  246. 'indexv': indexv,
  247. 'currentSlide': currentSlide
  248. } );
  249. }, 1 );
  250. }
  251. /**
  252. * Finds and stores references to DOM elements which are
  253. * required by the presentation. If a required element is
  254. * not found, it is created.
  255. */
  256. function setupDOM() {
  257. // Cache references to key DOM elements
  258. dom.theme = document.querySelector( '#theme' );
  259. dom.wrapper = document.querySelector( '.reveal' );
  260. dom.slides = document.querySelector( '.reveal .slides' );
  261. // Prevent transitions while we're loading
  262. dom.slides.classList.add( 'no-transition' );
  263. // Background element
  264. dom.background = createSingletonNode( dom.wrapper, 'div', 'backgrounds', null );
  265. // Progress bar
  266. dom.progress = createSingletonNode( dom.wrapper, 'div', 'progress', '<span></span>' );
  267. dom.progressbar = dom.progress.querySelector( 'span' );
  268. // Arrow controls
  269. createSingletonNode( dom.wrapper, 'aside', 'controls',
  270. '<div class="navigate-left"></div>' +
  271. '<div class="navigate-right"></div>' +
  272. '<div class="navigate-up"></div>' +
  273. '<div class="navigate-down"></div>' );
  274. // Slide number
  275. dom.slideNumber = createSingletonNode( dom.wrapper, 'div', 'slide-number', '' );
  276. // State background element [DEPRECATED]
  277. createSingletonNode( dom.wrapper, 'div', 'state-background', null );
  278. // Overlay graphic which is displayed during the paused mode
  279. createSingletonNode( dom.wrapper, 'div', 'pause-overlay', null );
  280. // Cache references to elements
  281. dom.controls = document.querySelector( '.reveal .controls' );
  282. // There can be multiple instances of controls throughout the page
  283. dom.controlsLeft = toArray( document.querySelectorAll( '.navigate-left' ) );
  284. dom.controlsRight = toArray( document.querySelectorAll( '.navigate-right' ) );
  285. dom.controlsUp = toArray( document.querySelectorAll( '.navigate-up' ) );
  286. dom.controlsDown = toArray( document.querySelectorAll( '.navigate-down' ) );
  287. dom.controlsPrev = toArray( document.querySelectorAll( '.navigate-prev' ) );
  288. dom.controlsNext = toArray( document.querySelectorAll( '.navigate-next' ) );
  289. }
  290. /**
  291. * Creates an HTML element and returns a reference to it.
  292. * If the element already exists the existing instance will
  293. * be returned.
  294. */
  295. function createSingletonNode( container, tagname, classname, innerHTML ) {
  296. var node = container.querySelector( '.' + classname );
  297. if( !node ) {
  298. node = document.createElement( tagname );
  299. node.classList.add( classname );
  300. if( innerHTML !== null ) {
  301. node.innerHTML = innerHTML;
  302. }
  303. container.appendChild( node );
  304. }
  305. return node;
  306. }
  307. /**
  308. * Creates the slide background elements and appends them
  309. * to the background container. One element is created per
  310. * slide no matter if the given slide has visible background.
  311. */
  312. function createBackgrounds() {
  313. if( isPrintingPDF() ) {
  314. document.body.classList.add( 'print-pdf' );
  315. }
  316. // Clear prior backgrounds
  317. dom.background.innerHTML = '';
  318. dom.background.classList.add( 'no-transition' );
  319. // Iterate over all horizontal slides
  320. toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).forEach( function( slideh ) {
  321. var backgroundStack;
  322. if( isPrintingPDF() ) {
  323. backgroundStack = createBackground( slideh, slideh );
  324. }
  325. else {
  326. backgroundStack = createBackground( slideh, dom.background );
  327. }
  328. // Iterate over all vertical slides
  329. toArray( slideh.querySelectorAll( 'section' ) ).forEach( function( slidev ) {
  330. if( isPrintingPDF() ) {
  331. createBackground( slidev, slidev );
  332. }
  333. else {
  334. createBackground( slidev, backgroundStack );
  335. }
  336. } );
  337. } );
  338. // Add parallax background if specified
  339. if( config.parallaxBackgroundImage ) {
  340. dom.background.style.backgroundImage = 'url("' + config.parallaxBackgroundImage + '")';
  341. dom.background.style.backgroundSize = config.parallaxBackgroundSize;
  342. // Make sure the below properties are set on the element - these properties are
  343. // needed for proper transitions to be set on the element via CSS. To remove
  344. // annoying background slide-in effect when the presentation starts, apply
  345. // these properties after short time delay
  346. setTimeout( function() {
  347. dom.wrapper.classList.add( 'has-parallax-background' );
  348. }, 1 );
  349. }
  350. else {
  351. dom.background.style.backgroundImage = '';
  352. dom.wrapper.classList.remove( 'has-parallax-background' );
  353. }
  354. }
  355. /**
  356. * Creates a background for the given slide.
  357. *
  358. * @param {HTMLElement} slide
  359. * @param {HTMLElement} container The element that the background
  360. * should be appended to
  361. */
  362. function createBackground( slide, container ) {
  363. var data = {
  364. background: slide.getAttribute( 'data-background' ),
  365. backgroundSize: slide.getAttribute( 'data-background-size' ),
  366. backgroundImage: slide.getAttribute( 'data-background-image' ),
  367. backgroundVideo: slide.getAttribute( 'data-background-video' ),
  368. backgroundColor: slide.getAttribute( 'data-background-color' ),
  369. backgroundRepeat: slide.getAttribute( 'data-background-repeat' ),
  370. backgroundPosition: slide.getAttribute( 'data-background-position' ),
  371. backgroundTransition: slide.getAttribute( 'data-background-transition' )
  372. };
  373. var element = document.createElement( 'div' );
  374. element.className = 'slide-background';
  375. if( data.background ) {
  376. // Auto-wrap image urls in url(...)
  377. if( /^(http|file|\/\/)/gi.test( data.background ) || /\.(svg|png|jpg|jpeg|gif|bmp)$/gi.test( data.background ) ) {
  378. element.style.backgroundImage = 'url('+ data.background +')';
  379. }
  380. else {
  381. element.style.background = data.background;
  382. }
  383. }
  384. // Create a hash for this combination of background settings.
  385. // This is used to determine when two slide backgrounds are
  386. // the same.
  387. if( data.background || data.backgroundColor || data.backgroundImage || data.backgroundVideo ) {
  388. element.setAttribute( 'data-background-hash', data.background +
  389. data.backgroundSize +
  390. data.backgroundImage +
  391. data.backgroundVideo +
  392. data.backgroundColor +
  393. data.backgroundRepeat +
  394. data.backgroundPosition +
  395. data.backgroundTransition );
  396. }
  397. // Additional and optional background properties
  398. if( data.backgroundSize ) element.style.backgroundSize = data.backgroundSize;
  399. if( data.backgroundImage ) element.style.backgroundImage = 'url("' + data.backgroundImage + '")';
  400. if( data.backgroundColor ) element.style.backgroundColor = data.backgroundColor;
  401. if( data.backgroundRepeat ) element.style.backgroundRepeat = data.backgroundRepeat;
  402. if( data.backgroundPosition ) element.style.backgroundPosition = data.backgroundPosition;
  403. if( data.backgroundTransition ) element.setAttribute( 'data-background-transition', data.backgroundTransition );
  404. // Create video background element
  405. if( data.backgroundVideo ) {
  406. var video = document.createElement( 'video' );
  407. // Support comma separated lists of video sources
  408. data.backgroundVideo.split( ',' ).forEach( function( source ) {
  409. video.innerHTML += '<source src="'+ source +'">';
  410. } );
  411. element.appendChild( video );
  412. }
  413. container.appendChild( element );
  414. return element;
  415. }
  416. /**
  417. * Applies the configuration settings from the config
  418. * object. May be called multiple times.
  419. */
  420. function configure( options ) {
  421. var numberOfSlides = document.querySelectorAll( SLIDES_SELECTOR ).length;
  422. dom.wrapper.classList.remove( config.transition );
  423. // New config options may be passed when this method
  424. // is invoked through the API after initialization
  425. if( typeof options === 'object' ) extend( config, options );
  426. // Force linear transition based on browser capabilities
  427. if( features.transforms3d === false ) config.transition = 'linear';
  428. dom.wrapper.classList.add( config.transition );
  429. dom.wrapper.setAttribute( 'data-transition-speed', config.transitionSpeed );
  430. dom.wrapper.setAttribute( 'data-background-transition', config.backgroundTransition );
  431. dom.controls.style.display = config.controls ? 'block' : 'none';
  432. dom.progress.style.display = config.progress ? 'block' : 'none';
  433. if( config.rtl ) {
  434. dom.wrapper.classList.add( 'rtl' );
  435. }
  436. else {
  437. dom.wrapper.classList.remove( 'rtl' );
  438. }
  439. if( config.center ) {
  440. dom.wrapper.classList.add( 'center' );
  441. }
  442. else {
  443. dom.wrapper.classList.remove( 'center' );
  444. }
  445. if( config.mouseWheel ) {
  446. document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  447. document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
  448. }
  449. else {
  450. document.removeEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  451. document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
  452. }
  453. // Rolling 3D links
  454. if( config.rollingLinks ) {
  455. enableRollingLinks();
  456. }
  457. else {
  458. disableRollingLinks();
  459. }
  460. // Iframe link previews
  461. if( config.previewLinks ) {
  462. enablePreviewLinks();
  463. }
  464. else {
  465. disablePreviewLinks();
  466. enablePreviewLinks( '[data-preview-link]' );
  467. }
  468. // Remove existing auto-slide controls
  469. if( autoSlidePlayer ) {
  470. autoSlidePlayer.destroy();
  471. autoSlidePlayer = null;
  472. }
  473. // Generate auto-slide controls if needed
  474. if( numberOfSlides > 1 && config.autoSlide && config.autoSlideStoppable && features.canvas && features.requestAnimationFrame ) {
  475. autoSlidePlayer = new Playback( dom.wrapper, function() {
  476. return Math.min( Math.max( ( Date.now() - autoSlideStartTime ) / autoSlide, 0 ), 1 );
  477. } );
  478. autoSlidePlayer.on( 'click', onAutoSlidePlayerClick );
  479. autoSlidePaused = false;
  480. }
  481. // When fragments are turned off they should be visible
  482. if( config.fragments === false ) {
  483. toArray( dom.slides.querySelectorAll( '.fragment' ) ).forEach( function( element ) {
  484. element.classList.add( 'visible' );
  485. element.classList.remove( 'current-fragment' );
  486. } );
  487. }
  488. // Load the theme in the config, if it's not already loaded
  489. if( config.theme && dom.theme ) {
  490. var themeURL = dom.theme.getAttribute( 'href' );
  491. var themeFinder = /[^\/]*?(?=\.css)/;
  492. var themeName = themeURL.match(themeFinder)[0];
  493. if( config.theme !== themeName ) {
  494. themeURL = themeURL.replace(themeFinder, config.theme);
  495. dom.theme.setAttribute( 'href', themeURL );
  496. }
  497. }
  498. sync();
  499. }
  500. /**
  501. * Binds all event listeners.
  502. */
  503. function addEventListeners() {
  504. eventsAreBound = true;
  505. window.addEventListener( 'hashchange', onWindowHashChange, false );
  506. window.addEventListener( 'resize', onWindowResize, false );
  507. if( config.touch ) {
  508. dom.wrapper.addEventListener( 'touchstart', onTouchStart, false );
  509. dom.wrapper.addEventListener( 'touchmove', onTouchMove, false );
  510. dom.wrapper.addEventListener( 'touchend', onTouchEnd, false );
  511. // Support pointer-style touch interaction as well
  512. if( window.navigator.pointerEnabled ) {
  513. // IE 11 uses un-prefixed version of pointer events
  514. dom.wrapper.addEventListener( 'pointerdown', onPointerDown, false );
  515. dom.wrapper.addEventListener( 'pointermove', onPointerMove, false );
  516. dom.wrapper.addEventListener( 'pointerup', onPointerUp, false );
  517. }
  518. else if( window.navigator.msPointerEnabled ) {
  519. // IE 10 uses prefixed version of pointer events
  520. dom.wrapper.addEventListener( 'MSPointerDown', onPointerDown, false );
  521. dom.wrapper.addEventListener( 'MSPointerMove', onPointerMove, false );
  522. dom.wrapper.addEventListener( 'MSPointerUp', onPointerUp, false );
  523. }
  524. }
  525. if( config.keyboard ) {
  526. document.addEventListener( 'keydown', onDocumentKeyDown, false );
  527. }
  528. if( config.progress && dom.progress ) {
  529. dom.progress.addEventListener( 'click', onProgressClicked, false );
  530. }
  531. if( config.focusBodyOnPageVisiblityChange ) {
  532. var visibilityChange;
  533. if( 'hidden' in document ) {
  534. visibilityChange = 'visibilitychange';
  535. }
  536. else if( 'msHidden' in document ) {
  537. visibilityChange = 'msvisibilitychange';
  538. }
  539. else if( 'webkitHidden' in document ) {
  540. visibilityChange = 'webkitvisibilitychange';
  541. }
  542. if( visibilityChange ) {
  543. document.addEventListener( visibilityChange, onPageVisibilityChange, false );
  544. }
  545. }
  546. [ 'touchstart', 'click' ].forEach( function( eventName ) {
  547. dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } );
  548. dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } );
  549. dom.controlsUp.forEach( function( el ) { el.addEventListener( eventName, onNavigateUpClicked, false ); } );
  550. dom.controlsDown.forEach( function( el ) { el.addEventListener( eventName, onNavigateDownClicked, false ); } );
  551. dom.controlsPrev.forEach( function( el ) { el.addEventListener( eventName, onNavigatePrevClicked, false ); } );
  552. dom.controlsNext.forEach( function( el ) { el.addEventListener( eventName, onNavigateNextClicked, false ); } );
  553. } );
  554. }
  555. /**
  556. * Unbinds all event listeners.
  557. */
  558. function removeEventListeners() {
  559. eventsAreBound = false;
  560. document.removeEventListener( 'keydown', onDocumentKeyDown, false );
  561. window.removeEventListener( 'hashchange', onWindowHashChange, false );
  562. window.removeEventListener( 'resize', onWindowResize, false );
  563. dom.wrapper.removeEventListener( 'touchstart', onTouchStart, false );
  564. dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false );
  565. dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false );
  566. // IE11
  567. if( window.navigator.pointerEnabled ) {
  568. dom.wrapper.removeEventListener( 'pointerdown', onPointerDown, false );
  569. dom.wrapper.removeEventListener( 'pointermove', onPointerMove, false );
  570. dom.wrapper.removeEventListener( 'pointerup', onPointerUp, false );
  571. }
  572. // IE10
  573. else if( window.navigator.msPointerEnabled ) {
  574. dom.wrapper.removeEventListener( 'MSPointerDown', onPointerDown, false );
  575. dom.wrapper.removeEventListener( 'MSPointerMove', onPointerMove, false );
  576. dom.wrapper.removeEventListener( 'MSPointerUp', onPointerUp, false );
  577. }
  578. if ( config.progress && dom.progress ) {
  579. dom.progress.removeEventListener( 'click', onProgressClicked, false );
  580. }
  581. [ 'touchstart', 'click' ].forEach( function( eventName ) {
  582. dom.controlsLeft.forEach( function( el ) { el.removeEventListener( eventName, onNavigateLeftClicked, false ); } );
  583. dom.controlsRight.forEach( function( el ) { el.removeEventListener( eventName, onNavigateRightClicked, false ); } );
  584. dom.controlsUp.forEach( function( el ) { el.removeEventListener( eventName, onNavigateUpClicked, false ); } );
  585. dom.controlsDown.forEach( function( el ) { el.removeEventListener( eventName, onNavigateDownClicked, false ); } );
  586. dom.controlsPrev.forEach( function( el ) { el.removeEventListener( eventName, onNavigatePrevClicked, false ); } );
  587. dom.controlsNext.forEach( function( el ) { el.removeEventListener( eventName, onNavigateNextClicked, false ); } );
  588. } );
  589. }
  590. /**
  591. * Extend object a with the properties of object b.
  592. * If there's a conflict, object b takes precedence.
  593. */
  594. function extend( a, b ) {
  595. for( var i in b ) {
  596. a[ i ] = b[ i ];
  597. }
  598. }
  599. /**
  600. * Converts the target object to an array.
  601. */
  602. function toArray( o ) {
  603. return Array.prototype.slice.call( o );
  604. }
  605. /**
  606. * Utility for deserializing a value.
  607. */
  608. function deserialize( value ) {
  609. if( typeof value === 'string' ) {
  610. if( value === 'null' ) return null;
  611. else if( value === 'true' ) return true;
  612. else if( value === 'false' ) return false;
  613. else if( value.match( /^\d+$/ ) ) return parseFloat( value );
  614. }
  615. return value;
  616. }
  617. /**
  618. * Measures the distance in pixels between point a
  619. * and point b.
  620. *
  621. * @param {Object} a point with x/y properties
  622. * @param {Object} b point with x/y properties
  623. */
  624. function distanceBetween( a, b ) {
  625. var dx = a.x - b.x,
  626. dy = a.y - b.y;
  627. return Math.sqrt( dx*dx + dy*dy );
  628. }
  629. /**
  630. * Applies a CSS transform to the target element.
  631. */
  632. function transformElement( element, transform ) {
  633. element.style.WebkitTransform = transform;
  634. element.style.MozTransform = transform;
  635. element.style.msTransform = transform;
  636. element.style.OTransform = transform;
  637. element.style.transform = transform;
  638. }
  639. /**
  640. * Retrieves the height of the given element by looking
  641. * at the position and height of its immediate children.
  642. */
  643. function getAbsoluteHeight( element ) {
  644. var height = 0;
  645. if( element ) {
  646. var absoluteChildren = 0;
  647. toArray( element.childNodes ).forEach( function( child ) {
  648. if( typeof child.offsetTop === 'number' && child.style ) {
  649. // Count # of abs children
  650. if( child.style.position === 'absolute' ) {
  651. absoluteChildren += 1;
  652. }
  653. height = Math.max( height, child.offsetTop + child.offsetHeight );
  654. }
  655. } );
  656. // If there are no absolute children, use offsetHeight
  657. if( absoluteChildren === 0 ) {
  658. height = element.offsetHeight;
  659. }
  660. }
  661. return height;
  662. }
  663. /**
  664. * Returns the remaining height within the parent of the
  665. * target element.
  666. *
  667. * remaining height = [ configured parent height ] - [ current parent height ]
  668. */
  669. function getRemainingHeight( element, height ) {
  670. height = height || 0;
  671. if( element ) {
  672. var newHeight, oldHeight = element.style.height;
  673. // Change the .stretch element height to 0 in order find the height of all
  674. // the other elements
  675. element.style.height = '0px';
  676. newHeight = height - element.parentNode.offsetHeight;
  677. // Restore the old height, just in case
  678. element.style.height = oldHeight + 'px';
  679. return newHeight;
  680. }
  681. return height;
  682. }
  683. /**
  684. * Checks if this instance is being used to print a PDF.
  685. */
  686. function isPrintingPDF() {
  687. return ( /print-pdf/gi ).test( window.location.search );
  688. }
  689. /**
  690. * Hides the address bar if we're on a mobile device.
  691. */
  692. function hideAddressBar() {
  693. if( config.hideAddressBar && isMobileDevice ) {
  694. // Events that should trigger the address bar to hide
  695. window.addEventListener( 'load', removeAddressBar, false );
  696. window.addEventListener( 'orientationchange', removeAddressBar, false );
  697. }
  698. }
  699. /**
  700. * Causes the address bar to hide on mobile devices,
  701. * more vertical space ftw.
  702. */
  703. function removeAddressBar() {
  704. setTimeout( function() {
  705. window.scrollTo( 0, 1 );
  706. }, 10 );
  707. }
  708. /**
  709. * Dispatches an event of the specified type from the
  710. * reveal DOM element.
  711. */
  712. function dispatchEvent( type, properties ) {
  713. var event = document.createEvent( "HTMLEvents", 1, 2 );
  714. event.initEvent( type, true, true );
  715. extend( event, properties );
  716. dom.wrapper.dispatchEvent( event );
  717. }
  718. /**
  719. * Wrap all links in 3D goodness.
  720. */
  721. function enableRollingLinks() {
  722. if( features.transforms3d && !( 'msPerspective' in document.body.style ) ) {
  723. var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a' );
  724. for( var i = 0, len = anchors.length; i < len; i++ ) {
  725. var anchor = anchors[i];
  726. if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
  727. var span = document.createElement('span');
  728. span.setAttribute('data-title', anchor.text);
  729. span.innerHTML = anchor.innerHTML;
  730. anchor.classList.add( 'roll' );
  731. anchor.innerHTML = '';
  732. anchor.appendChild(span);
  733. }
  734. }
  735. }
  736. }
  737. /**
  738. * Unwrap all 3D links.
  739. */
  740. function disableRollingLinks() {
  741. var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
  742. for( var i = 0, len = anchors.length; i < len; i++ ) {
  743. var anchor = anchors[i];
  744. var span = anchor.querySelector( 'span' );
  745. if( span ) {
  746. anchor.classList.remove( 'roll' );
  747. anchor.innerHTML = span.innerHTML;
  748. }
  749. }
  750. }
  751. /**
  752. * Bind preview frame links.
  753. */
  754. function enablePreviewLinks( selector ) {
  755. var anchors = toArray( document.querySelectorAll( selector ? selector : 'a' ) );
  756. anchors.forEach( function( element ) {
  757. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  758. element.addEventListener( 'click', onPreviewLinkClicked, false );
  759. }
  760. } );
  761. }
  762. /**
  763. * Unbind preview frame links.
  764. */
  765. function disablePreviewLinks() {
  766. var anchors = toArray( document.querySelectorAll( 'a' ) );
  767. anchors.forEach( function( element ) {
  768. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  769. element.removeEventListener( 'click', onPreviewLinkClicked, false );
  770. }
  771. } );
  772. }
  773. /**
  774. * Opens a preview window for the target URL.
  775. */
  776. function openPreview( url ) {
  777. closePreview();
  778. dom.preview = document.createElement( 'div' );
  779. dom.preview.classList.add( 'preview-link-overlay' );
  780. dom.wrapper.appendChild( dom.preview );
  781. dom.preview.innerHTML = [
  782. '<header>',
  783. '<a class="close" href="#"><span class="icon"></span></a>',
  784. '<a class="external" href="'+ url +'" target="_blank"><span class="icon"></span></a>',
  785. '</header>',
  786. '<div class="spinner"></div>',
  787. '<div class="viewport">',
  788. '<iframe src="'+ url +'"></iframe>',
  789. '</div>'
  790. ].join('');
  791. dom.preview.querySelector( 'iframe' ).addEventListener( 'load', function( event ) {
  792. dom.preview.classList.add( 'loaded' );
  793. }, false );
  794. dom.preview.querySelector( '.close' ).addEventListener( 'click', function( event ) {
  795. closePreview();
  796. event.preventDefault();
  797. }, false );
  798. dom.preview.querySelector( '.external' ).addEventListener( 'click', function( event ) {
  799. closePreview();
  800. }, false );
  801. setTimeout( function() {
  802. dom.preview.classList.add( 'visible' );
  803. }, 1 );
  804. }
  805. /**
  806. * Closes the iframe preview window.
  807. */
  808. function closePreview() {
  809. if( dom.preview ) {
  810. dom.preview.setAttribute( 'src', '' );
  811. dom.preview.parentNode.removeChild( dom.preview );
  812. dom.preview = null;
  813. }
  814. }
  815. /**
  816. * Applies JavaScript-controlled layout rules to the
  817. * presentation.
  818. */
  819. function layout() {
  820. if( dom.wrapper && !isPrintingPDF() ) {
  821. // Available space to scale within
  822. var availableWidth = dom.wrapper.offsetWidth,
  823. availableHeight = dom.wrapper.offsetHeight;
  824. // Reduce available space by margin
  825. availableWidth -= ( availableHeight * config.margin );
  826. availableHeight -= ( availableHeight * config.margin );
  827. // Dimensions of the content
  828. var slideWidth = config.width,
  829. slideHeight = config.height,
  830. slidePadding = 20; // TODO Dig this out of DOM
  831. // Layout the contents of the slides
  832. layoutSlideContents( config.width, config.height, slidePadding );
  833. // Slide width may be a percentage of available width
  834. if( typeof slideWidth === 'string' && /%$/.test( slideWidth ) ) {
  835. slideWidth = parseInt( slideWidth, 10 ) / 100 * availableWidth;
  836. }
  837. // Slide height may be a percentage of available height
  838. if( typeof slideHeight === 'string' && /%$/.test( slideHeight ) ) {
  839. slideHeight = parseInt( slideHeight, 10 ) / 100 * availableHeight;
  840. }
  841. dom.slides.style.width = slideWidth + 'px';
  842. dom.slides.style.height = slideHeight + 'px';
  843. // Determine scale of content to fit within available space
  844. scale = Math.min( availableWidth / slideWidth, availableHeight / slideHeight );
  845. // Respect max/min scale settings
  846. scale = Math.max( scale, config.minScale );
  847. scale = Math.min( scale, config.maxScale );
  848. // Prefer applying scale via zoom since Chrome blurs scaled content
  849. // with nested transforms
  850. if( typeof dom.slides.style.zoom !== 'undefined' && !navigator.userAgent.match( /(iphone|ipod|ipad|android)/gi ) ) {
  851. dom.slides.style.zoom = scale;
  852. }
  853. // Apply scale transform as a fallback
  854. else {
  855. transformElement( dom.slides, 'translate(-50%, -50%) scale('+ scale +') translate(50%, 50%)' );
  856. }
  857. // Select all slides, vertical and horizontal
  858. var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
  859. for( var i = 0, len = slides.length; i < len; i++ ) {
  860. var slide = slides[ i ];
  861. // Don't bother updating invisible slides
  862. if( slide.style.display === 'none' ) {
  863. continue;
  864. }
  865. if( config.center || slide.classList.contains( 'center' ) ) {
  866. // Vertical stacks are not centred since their section
  867. // children will be
  868. if( slide.classList.contains( 'stack' ) ) {
  869. slide.style.top = 0;
  870. }
  871. else {
  872. slide.style.top = Math.max( - ( getAbsoluteHeight( slide ) / 2 ) - slidePadding, -slideHeight / 2 ) + 'px';
  873. }
  874. }
  875. else {
  876. slide.style.top = '';
  877. }
  878. }
  879. updateProgress();
  880. updateParallax();
  881. }
  882. }
  883. /**
  884. * Applies layout logic to the contents of all slides in
  885. * the presentation.
  886. */
  887. function layoutSlideContents( width, height, padding ) {
  888. // Handle sizing of elements with the 'stretch' class
  889. toArray( dom.slides.querySelectorAll( 'section > .stretch' ) ).forEach( function( element ) {
  890. // Determine how much vertical space we can use
  891. var remainingHeight = getRemainingHeight( element, height );
  892. // Consider the aspect ratio of media elements
  893. if( /(img|video)/gi.test( element.nodeName ) ) {
  894. var nw = element.naturalWidth || element.videoWidth,
  895. nh = element.naturalHeight || element.videoHeight;
  896. var es = Math.min( width / nw, remainingHeight / nh );
  897. element.style.width = ( nw * es ) + 'px';
  898. element.style.height = ( nh * es ) + 'px';
  899. }
  900. else {
  901. element.style.width = width + 'px';
  902. element.style.height = remainingHeight + 'px';
  903. }
  904. } );
  905. }
  906. /**
  907. * Stores the vertical index of a stack so that the same
  908. * vertical slide can be selected when navigating to and
  909. * from the stack.
  910. *
  911. * @param {HTMLElement} stack The vertical stack element
  912. * @param {int} v Index to memorize
  913. */
  914. function setPreviousVerticalIndex( stack, v ) {
  915. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
  916. stack.setAttribute( 'data-previous-indexv', v || 0 );
  917. }
  918. }
  919. /**
  920. * Retrieves the vertical index which was stored using
  921. * #setPreviousVerticalIndex() or 0 if no previous index
  922. * exists.
  923. *
  924. * @param {HTMLElement} stack The vertical stack element
  925. */
  926. function getPreviousVerticalIndex( stack ) {
  927. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
  928. // Prefer manually defined start-indexv
  929. var attributeName = stack.hasAttribute( 'data-start-indexv' ) ? 'data-start-indexv' : 'data-previous-indexv';
  930. return parseInt( stack.getAttribute( attributeName ) || 0, 10 );
  931. }
  932. return 0;
  933. }
  934. /**
  935. * Displays the overview of slides (quick nav) by
  936. * scaling down and arranging all slide elements.
  937. *
  938. * Experimental feature, might be dropped if perf
  939. * can't be improved.
  940. */
  941. function activateOverview() {
  942. // Only proceed if enabled in config
  943. if( config.overview ) {
  944. // Don't auto-slide while in overview mode
  945. cancelAutoSlide();
  946. var wasActive = dom.wrapper.classList.contains( 'overview' );
  947. // Vary the depth of the overview based on screen size
  948. var depth = window.innerWidth < 400 ? 1000 : 2500;
  949. dom.wrapper.classList.add( 'overview' );
  950. dom.wrapper.classList.remove( 'overview-deactivating' );
  951. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  952. for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
  953. var hslide = horizontalSlides[i],
  954. hoffset = config.rtl ? -105 : 105;
  955. hslide.setAttribute( 'data-index-h', i );
  956. // Apply CSS transform
  957. transformElement( hslide, 'translateZ(-'+ depth +'px) translate(' + ( ( i - indexh ) * hoffset ) + '%, 0%)' );
  958. if( hslide.classList.contains( 'stack' ) ) {
  959. var verticalSlides = hslide.querySelectorAll( 'section' );
  960. for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
  961. var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
  962. var vslide = verticalSlides[j];
  963. vslide.setAttribute( 'data-index-h', i );
  964. vslide.setAttribute( 'data-index-v', j );
  965. // Apply CSS transform
  966. transformElement( vslide, 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)' );
  967. // Navigate to this slide on click
  968. vslide.addEventListener( 'click', onOverviewSlideClicked, true );
  969. }
  970. }
  971. else {
  972. // Navigate to this slide on click
  973. hslide.addEventListener( 'click', onOverviewSlideClicked, true );
  974. }
  975. }
  976. updateSlidesVisibility();
  977. layout();
  978. if( !wasActive ) {
  979. // Notify observers of the overview showing
  980. dispatchEvent( 'overviewshown', {
  981. 'indexh': indexh,
  982. 'indexv': indexv,
  983. 'currentSlide': currentSlide
  984. } );
  985. }
  986. }
  987. }
  988. /**
  989. * Exits the slide overview and enters the currently
  990. * active slide.
  991. */
  992. function deactivateOverview() {
  993. // Only proceed if enabled in config
  994. if( config.overview ) {
  995. dom.wrapper.classList.remove( 'overview' );
  996. // Temporarily add a class so that transitions can do different things
  997. // depending on whether they are exiting/entering overview, or just
  998. // moving from slide to slide
  999. dom.wrapper.classList.add( 'overview-deactivating' );
  1000. setTimeout( function () {
  1001. dom.wrapper.classList.remove( 'overview-deactivating' );
  1002. }, 1 );
  1003. // Select all slides
  1004. toArray( document.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
  1005. // Resets all transforms to use the external styles
  1006. transformElement( slide, '' );
  1007. slide.removeEventListener( 'click', onOverviewSlideClicked, true );
  1008. } );
  1009. slide( indexh, indexv );
  1010. cueAutoSlide();
  1011. // Notify observers of the overview hiding
  1012. dispatchEvent( 'overviewhidden', {
  1013. 'indexh': indexh,
  1014. 'indexv': indexv,
  1015. 'currentSlide': currentSlide
  1016. } );
  1017. }
  1018. }
  1019. /**
  1020. * Toggles the slide overview mode on and off.
  1021. *
  1022. * @param {Boolean} override Optional flag which overrides the
  1023. * toggle logic and forcibly sets the desired state. True means
  1024. * overview is open, false means it's closed.
  1025. */
  1026. function toggleOverview( override ) {
  1027. if( typeof override === 'boolean' ) {
  1028. override ? activateOverview() : deactivateOverview();
  1029. }
  1030. else {
  1031. isOverview() ? deactivateOverview() : activateOverview();
  1032. }
  1033. }
  1034. /**
  1035. * Checks if the overview is currently active.
  1036. *
  1037. * @return {Boolean} true if the overview is active,
  1038. * false otherwise
  1039. */
  1040. function isOverview() {
  1041. return dom.wrapper.classList.contains( 'overview' );
  1042. }
  1043. /**
  1044. * Checks if the current or specified slide is vertical
  1045. * (nested within another slide).
  1046. *
  1047. * @param {HTMLElement} slide [optional] The slide to check
  1048. * orientation of
  1049. */
  1050. function isVerticalSlide( slide ) {
  1051. // Prefer slide argument, otherwise use current slide
  1052. slide = slide ? slide : currentSlide;
  1053. return slide && slide.parentNode && !!slide.parentNode.nodeName.match( /section/i );
  1054. }
  1055. /**
  1056. * Handling the fullscreen functionality via the fullscreen API
  1057. *
  1058. * @see http://fullscreen.spec.whatwg.org/
  1059. * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
  1060. */
  1061. function enterFullscreen() {
  1062. var element = document.body;
  1063. // Check which implementation is available
  1064. var requestMethod = element.requestFullScreen ||
  1065. element.webkitRequestFullscreen ||
  1066. element.webkitRequestFullScreen ||
  1067. element.mozRequestFullScreen ||
  1068. element.msRequestFullscreen;
  1069. if( requestMethod ) {
  1070. requestMethod.apply( element );
  1071. }
  1072. }
  1073. /**
  1074. * Enters the paused mode which fades everything on screen to
  1075. * black.
  1076. */
  1077. function pause() {
  1078. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1079. cancelAutoSlide();
  1080. dom.wrapper.classList.add( 'paused' );
  1081. if( wasPaused === false ) {
  1082. dispatchEvent( 'paused' );
  1083. }
  1084. }
  1085. /**
  1086. * Exits from the paused mode.
  1087. */
  1088. function resume() {
  1089. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1090. dom.wrapper.classList.remove( 'paused' );
  1091. cueAutoSlide();
  1092. if( wasPaused ) {
  1093. dispatchEvent( 'resumed' );
  1094. }
  1095. }
  1096. /**
  1097. * Toggles the paused mode on and off.
  1098. */
  1099. function togglePause( override ) {
  1100. if( typeof override === 'boolean' ) {
  1101. override ? pause() : resume();
  1102. }
  1103. else {
  1104. isPaused() ? resume() : pause();
  1105. }
  1106. }
  1107. /**
  1108. * Checks if we are currently in the paused mode.
  1109. */
  1110. function isPaused() {
  1111. return dom.wrapper.classList.contains( 'paused' );
  1112. }
  1113. /**
  1114. * Toggles the auto slide mode on and off.
  1115. *
  1116. * @param {Boolean} override Optional flag which sets the desired state.
  1117. * True means autoplay starts, false means it stops.
  1118. */
  1119. function toggleAutoSlide( override ) {
  1120. if( typeof override === 'boolean' ) {
  1121. override ? resumeAutoSlide() : pauseAutoSlide();
  1122. }
  1123. else {
  1124. autoSlidePaused ? resumeAutoSlide() : pauseAutoSlide();
  1125. }
  1126. }
  1127. /**
  1128. * Checks if the auto slide mode is currently on.
  1129. */
  1130. function isAutoSliding() {
  1131. return !!( autoSlide && !autoSlidePaused );
  1132. }
  1133. /**
  1134. * Steps from the current point in the presentation to the
  1135. * slide which matches the specified horizontal and vertical
  1136. * indices.
  1137. *
  1138. * @param {int} h Horizontal index of the target slide
  1139. * @param {int} v Vertical index of the target slide
  1140. * @param {int} f Optional index of a fragment within the
  1141. * target slide to activate
  1142. * @param {int} o Optional origin for use in multimaster environments
  1143. */
  1144. function slide( h, v, f, o ) {
  1145. // Remember where we were at before
  1146. previousSlide = currentSlide;
  1147. // Query all horizontal slides in the deck
  1148. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  1149. // If no vertical index is specified and the upcoming slide is a
  1150. // stack, resume at its previous vertical index
  1151. if( v === undefined ) {
  1152. v = getPreviousVerticalIndex( horizontalSlides[ h ] );
  1153. }
  1154. // If we were on a vertical stack, remember what vertical index
  1155. // it was on so we can resume at the same position when returning
  1156. if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
  1157. setPreviousVerticalIndex( previousSlide.parentNode, indexv );
  1158. }
  1159. // Remember the state before this slide
  1160. var stateBefore = state.concat();
  1161. // Reset the state array
  1162. state.length = 0;
  1163. var indexhBefore = indexh || 0,
  1164. indexvBefore = indexv || 0;
  1165. // Activate and transition to the new slide
  1166. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
  1167. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
  1168. // Update the visibility of slides now that the indices have changed
  1169. updateSlidesVisibility();
  1170. layout();
  1171. // Apply the new state
  1172. stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
  1173. // Check if this state existed on the previous slide. If it
  1174. // did, we will avoid adding it repeatedly
  1175. for( var j = 0; j < stateBefore.length; j++ ) {
  1176. if( stateBefore[j] === state[i] ) {
  1177. stateBefore.splice( j, 1 );
  1178. continue stateLoop;
  1179. }
  1180. }
  1181. document.documentElement.classList.add( state[i] );
  1182. // Dispatch custom event matching the state's name
  1183. dispatchEvent( state[i] );
  1184. }
  1185. // Clean up the remains of the previous state
  1186. while( stateBefore.length ) {
  1187. document.documentElement.classList.remove( stateBefore.pop() );
  1188. }
  1189. // If the overview is active, re-activate it to update positions
  1190. if( isOverview() ) {
  1191. activateOverview();
  1192. }
  1193. // Find the current horizontal slide and any possible vertical slides
  1194. // within it
  1195. var currentHorizontalSlide = horizontalSlides[ indexh ],
  1196. currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
  1197. // Store references to the previous and current slides
  1198. currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
  1199. // Show fragment, if specified
  1200. if( typeof f !== 'undefined' ) {
  1201. navigateFragment( f );
  1202. }
  1203. // Dispatch an event if the slide changed
  1204. var slideChanged = ( indexh !== indexhBefore || indexv !== indexvBefore );
  1205. if( slideChanged ) {
  1206. dispatchEvent( 'slidechanged', {
  1207. 'indexh': indexh,
  1208. 'indexv': indexv,
  1209. 'previousSlide': previousSlide,
  1210. 'currentSlide': currentSlide,
  1211. 'origin': o
  1212. } );
  1213. }
  1214. else {
  1215. // Ensure that the previous slide is never the same as the current
  1216. previousSlide = null;
  1217. }
  1218. // Solves an edge case where the previous slide maintains the
  1219. // 'present' class when navigating between adjacent vertical
  1220. // stacks
  1221. if( previousSlide ) {
  1222. previousSlide.classList.remove( 'present' );
  1223. // Reset all slides upon navigate to home
  1224. // Issue: #285
  1225. if ( document.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
  1226. // Launch async task
  1227. setTimeout( function () {
  1228. var slides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
  1229. for( i in slides ) {
  1230. if( slides[i] ) {
  1231. // Reset stack
  1232. setPreviousVerticalIndex( slides[i], 0 );
  1233. }
  1234. }
  1235. }, 0 );
  1236. }
  1237. }
  1238. // Handle embedded content
  1239. if( slideChanged ) {
  1240. stopEmbeddedContent( previousSlide );
  1241. startEmbeddedContent( currentSlide );
  1242. }
  1243. updateControls();
  1244. updateProgress();
  1245. updateBackground();
  1246. updateParallax();
  1247. updateSlideNumber();
  1248. // Update the URL hash
  1249. writeURL();
  1250. cueAutoSlide();
  1251. }
  1252. /**
  1253. * Syncs the presentation with the current DOM. Useful
  1254. * when new slides or control elements are added or when
  1255. * the configuration has changed.
  1256. */
  1257. function sync() {
  1258. // Subscribe to input
  1259. removeEventListeners();
  1260. addEventListeners();
  1261. // Force a layout to make sure the current config is accounted for
  1262. layout();
  1263. // Reflect the current autoSlide value
  1264. autoSlide = config.autoSlide;
  1265. // Start auto-sliding if it's enabled
  1266. cueAutoSlide();
  1267. // Re-create the slide backgrounds
  1268. createBackgrounds();
  1269. sortAllFragments();
  1270. updateControls();
  1271. updateProgress();
  1272. updateBackground( true );
  1273. updateSlideNumber();
  1274. }
  1275. /**
  1276. * Resets all vertical slides so that only the first
  1277. * is visible.
  1278. */
  1279. function resetVerticalSlides() {
  1280. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1281. horizontalSlides.forEach( function( horizontalSlide ) {
  1282. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1283. verticalSlides.forEach( function( verticalSlide, y ) {
  1284. if( y > 0 ) {
  1285. verticalSlide.classList.remove( 'present' );
  1286. verticalSlide.classList.remove( 'past' );
  1287. verticalSlide.classList.add( 'future' );
  1288. }
  1289. } );
  1290. } );
  1291. }
  1292. /**
  1293. * Sorts and formats all of fragments in the
  1294. * presentation.
  1295. */
  1296. function sortAllFragments() {
  1297. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1298. horizontalSlides.forEach( function( horizontalSlide ) {
  1299. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1300. verticalSlides.forEach( function( verticalSlide, y ) {
  1301. sortFragments( verticalSlide.querySelectorAll( '.fragment' ) );
  1302. } );
  1303. if( verticalSlides.length === 0 ) sortFragments( horizontalSlide.querySelectorAll( '.fragment' ) );
  1304. } );
  1305. }
  1306. /**
  1307. * Updates one dimension of slides by showing the slide
  1308. * with the specified index.
  1309. *
  1310. * @param {String} selector A CSS selector that will fetch
  1311. * the group of slides we are working with
  1312. * @param {Number} index The index of the slide that should be
  1313. * shown
  1314. *
  1315. * @return {Number} The index of the slide that is now shown,
  1316. * might differ from the passed in index if it was out of
  1317. * bounds.
  1318. */
  1319. function updateSlides( selector, index ) {
  1320. // Select all slides and convert the NodeList result to
  1321. // an array
  1322. var slides = toArray( document.querySelectorAll( selector ) ),
  1323. slidesLength = slides.length;
  1324. if( slidesLength ) {
  1325. // Should the index loop?
  1326. if( config.loop ) {
  1327. index %= slidesLength;
  1328. if( index < 0 ) {
  1329. index = slidesLength + index;
  1330. }
  1331. }
  1332. // Enforce max and minimum index bounds
  1333. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  1334. for( var i = 0; i < slidesLength; i++ ) {
  1335. var element = slides[i];
  1336. var reverse = config.rtl && !isVerticalSlide( element );
  1337. element.classList.remove( 'past' );
  1338. element.classList.remove( 'present' );
  1339. element.classList.remove( 'future' );
  1340. // http://www.w3.org/html/wg/drafts/html/master/editing.html#the-hidden-attribute
  1341. element.setAttribute( 'hidden', '' );
  1342. if( i < index ) {
  1343. // Any element previous to index is given the 'past' class
  1344. element.classList.add( reverse ? 'future' : 'past' );
  1345. if( config.fragments ) {
  1346. var pastFragments = toArray( element.querySelectorAll( '.fragment' ) );
  1347. // Show all fragments on prior slides
  1348. while( pastFragments.length ) {
  1349. var pastFragment = pastFragments.pop();
  1350. pastFragment.classList.add( 'visible' );
  1351. pastFragment.classList.remove( 'current-fragment' );
  1352. }
  1353. }
  1354. }
  1355. else if( i > index ) {
  1356. // Any element subsequent to index is given the 'future' class
  1357. element.classList.add( reverse ? 'past' : 'future' );
  1358. if( config.fragments ) {
  1359. var futureFragments = toArray( element.querySelectorAll( '.fragment.visible' ) );
  1360. // No fragments in future slides should be visible ahead of time
  1361. while( futureFragments.length ) {
  1362. var futureFragment = futureFragments.pop();
  1363. futureFragment.classList.remove( 'visible' );
  1364. futureFragment.classList.remove( 'current-fragment' );
  1365. }
  1366. }
  1367. }
  1368. // If this element contains vertical slides
  1369. if( element.querySelector( 'section' ) ) {
  1370. element.classList.add( 'stack' );
  1371. }
  1372. }
  1373. // Mark the current slide as present
  1374. slides[index].classList.add( 'present' );
  1375. slides[index].removeAttribute( 'hidden' );
  1376. // If this slide has a state associated with it, add it
  1377. // onto the current state of the deck
  1378. var slideState = slides[index].getAttribute( 'data-state' );
  1379. if( slideState ) {
  1380. state = state.concat( slideState.split( ' ' ) );
  1381. }
  1382. }
  1383. else {
  1384. // Since there are no slides we can't be anywhere beyond the
  1385. // zeroth index
  1386. index = 0;
  1387. }
  1388. return index;
  1389. }
  1390. /**
  1391. * Optimization method; hide all slides that are far away
  1392. * from the present slide.
  1393. */
  1394. function updateSlidesVisibility() {
  1395. // Select all slides and convert the NodeList result to
  1396. // an array
  1397. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ),
  1398. horizontalSlidesLength = horizontalSlides.length,
  1399. distanceX,
  1400. distanceY;
  1401. if( horizontalSlidesLength ) {
  1402. // The number of steps away from the present slide that will
  1403. // be visible
  1404. var viewDistance = isOverview() ? 10 : config.viewDistance;
  1405. // Limit view distance on weaker devices
  1406. if( isMobileDevice ) {
  1407. viewDistance = isOverview() ? 6 : 1;
  1408. }
  1409. for( var x = 0; x < horizontalSlidesLength; x++ ) {
  1410. var horizontalSlide = horizontalSlides[x];
  1411. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) ),
  1412. verticalSlidesLength = verticalSlides.length;
  1413. // Loops so that it measures 1 between the first and last slides
  1414. distanceX = Math.abs( ( indexh - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0;
  1415. // Show the horizontal slide if it's within the view distance
  1416. horizontalSlide.style.display = distanceX > viewDistance ? 'none' : 'block';
  1417. if( verticalSlidesLength ) {
  1418. var oy = getPreviousVerticalIndex( horizontalSlide );
  1419. for( var y = 0; y < verticalSlidesLength; y++ ) {
  1420. var verticalSlide = verticalSlides[y];
  1421. distanceY = x === indexh ? Math.abs( indexv - y ) : Math.abs( y - oy );
  1422. verticalSlide.style.display = ( distanceX + distanceY ) > viewDistance ? 'none' : 'block';
  1423. }
  1424. }
  1425. }
  1426. }
  1427. }
  1428. /**
  1429. * Updates the progress bar to reflect the current slide.
  1430. */
  1431. function updateProgress() {
  1432. // Update progress if enabled
  1433. if( config.progress && dom.progress ) {
  1434. dom.progressbar.style.width = getProgress() * window.innerWidth + 'px';
  1435. }
  1436. }
  1437. /**
  1438. * Updates the slide number div to reflect the current slide.
  1439. */
  1440. function updateSlideNumber() {
  1441. // Update slide number if enabled
  1442. if( config.slideNumber && dom.slideNumber) {
  1443. // Display the number of the page using 'indexh - indexv' format
  1444. var indexString = indexh;
  1445. if( indexv > 0 ) {
  1446. indexString += ' - ' + indexv;
  1447. }
  1448. dom.slideNumber.innerHTML = indexString;
  1449. }
  1450. }
  1451. /**
  1452. * Updates the state of all control/navigation arrows.
  1453. */
  1454. function updateControls() {
  1455. var routes = availableRoutes();
  1456. var fragments = availableFragments();
  1457. // Remove the 'enabled' class from all directions
  1458. dom.controlsLeft.concat( dom.controlsRight )
  1459. .concat( dom.controlsUp )
  1460. .concat( dom.controlsDown )
  1461. .concat( dom.controlsPrev )
  1462. .concat( dom.controlsNext ).forEach( function( node ) {
  1463. node.classList.remove( 'enabled' );
  1464. node.classList.remove( 'fragmented' );
  1465. } );
  1466. // Add the 'enabled' class to the available routes
  1467. if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1468. if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1469. if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1470. if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1471. // Prev/next buttons
  1472. if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1473. if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1474. // Highlight fragment directions
  1475. if( currentSlide ) {
  1476. // Always apply fragment decorator to prev/next buttons
  1477. if( fragments.prev ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1478. if( fragments.next ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1479. // Apply fragment decorators to directional buttons based on
  1480. // what slide axis they are in
  1481. if( isVerticalSlide( currentSlide ) ) {
  1482. if( fragments.prev ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1483. if( fragments.next ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1484. }
  1485. else {
  1486. if( fragments.prev ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1487. if( fragments.next ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1488. }
  1489. }
  1490. }
  1491. /**
  1492. * Updates the background elements to reflect the current
  1493. * slide.
  1494. *
  1495. * @param {Boolean} includeAll If true, the backgrounds of
  1496. * all vertical slides (not just the present) will be updated.
  1497. */
  1498. function updateBackground( includeAll ) {
  1499. var currentBackground = null;
  1500. // Reverse past/future classes when in RTL mode
  1501. var horizontalPast = config.rtl ? 'future' : 'past',
  1502. horizontalFuture = config.rtl ? 'past' : 'future';
  1503. // Update the classes of all backgrounds to match the
  1504. // states of their slides (past/present/future)
  1505. toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) {
  1506. if( h < indexh ) {
  1507. backgroundh.className = 'slide-background ' + horizontalPast;
  1508. }
  1509. else if ( h > indexh ) {
  1510. backgroundh.className = 'slide-background ' + horizontalFuture;
  1511. }
  1512. else {
  1513. backgroundh.className = 'slide-background present';
  1514. // Store a reference to the current background element
  1515. currentBackground = backgroundh;
  1516. }
  1517. if( includeAll || h === indexh ) {
  1518. toArray( backgroundh.childNodes ).forEach( function( backgroundv, v ) {
  1519. if( v < indexv ) {
  1520. backgroundv.className = 'slide-background past';
  1521. }
  1522. else if ( v > indexv ) {
  1523. backgroundv.className = 'slide-background future';
  1524. }
  1525. else {
  1526. backgroundv.className = 'slide-background present';
  1527. // Only if this is the present horizontal and vertical slide
  1528. if( h === indexh ) currentBackground = backgroundv;
  1529. }
  1530. } );
  1531. }
  1532. } );
  1533. // Don't transition between identical backgrounds. This
  1534. // prevents unwanted flicker.
  1535. if( currentBackground ) {
  1536. var previousBackgroundHash = previousBackground ? previousBackground.getAttribute( 'data-background-hash' ) : null;
  1537. var currentBackgroundHash = currentBackground.getAttribute( 'data-background-hash' );
  1538. if( currentBackgroundHash && currentBackgroundHash === previousBackgroundHash && currentBackground !== previousBackground ) {
  1539. dom.background.classList.add( 'no-transition' );
  1540. }
  1541. previousBackground = currentBackground;
  1542. }
  1543. // Allow the first background to apply without transition
  1544. setTimeout( function() {
  1545. dom.background.classList.remove( 'no-transition' );
  1546. }, 1 );
  1547. }
  1548. /**
  1549. * Updates the position of the parallax background based
  1550. * on the current slide index.
  1551. */
  1552. function updateParallax() {
  1553. if( config.parallaxBackgroundImage ) {
  1554. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1555. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1556. var backgroundSize = dom.background.style.backgroundSize.split( ' ' ),
  1557. backgroundWidth, backgroundHeight;
  1558. if( backgroundSize.length === 1 ) {
  1559. backgroundWidth = backgroundHeight = parseInt( backgroundSize[0], 10 );
  1560. }
  1561. else {
  1562. backgroundWidth = parseInt( backgroundSize[0], 10 );
  1563. backgroundHeight = parseInt( backgroundSize[1], 10 );
  1564. }
  1565. var slideWidth = dom.background.offsetWidth;
  1566. var horizontalSlideCount = horizontalSlides.length;
  1567. var horizontalOffset = -( backgroundWidth - slideWidth ) / ( horizontalSlideCount-1 ) * indexh;
  1568. var slideHeight = dom.background.offsetHeight;
  1569. var verticalSlideCount = verticalSlides.length;
  1570. var verticalOffset = verticalSlideCount > 1 ? -( backgroundHeight - slideHeight ) / ( verticalSlideCount-1 ) * indexv : 0;
  1571. dom.background.style.backgroundPosition = horizontalOffset + 'px ' + verticalOffset + 'px';
  1572. }
  1573. }
  1574. /**
  1575. * Determine what available routes there are for navigation.
  1576. *
  1577. * @return {Object} containing four booleans: left/right/up/down
  1578. */
  1579. function availableRoutes() {
  1580. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1581. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1582. var routes = {
  1583. left: indexh > 0 || config.loop,
  1584. right: indexh < horizontalSlides.length - 1 || config.loop,
  1585. up: indexv > 0,
  1586. down: indexv < verticalSlides.length - 1
  1587. };
  1588. // reverse horizontal controls for rtl
  1589. if( config.rtl ) {
  1590. var left = routes.left;
  1591. routes.left = routes.right;
  1592. routes.right = left;
  1593. }
  1594. return routes;
  1595. }
  1596. /**
  1597. * Returns an object describing the available fragment
  1598. * directions.
  1599. *
  1600. * @return {Object} two boolean properties: prev/next
  1601. */
  1602. function availableFragments() {
  1603. if( currentSlide && config.fragments ) {
  1604. var fragments = currentSlide.querySelectorAll( '.fragment' );
  1605. var hiddenFragments = currentSlide.querySelectorAll( '.fragment:not(.visible)' );
  1606. return {
  1607. prev: fragments.length - hiddenFragments.length > 0,
  1608. next: !!hiddenFragments.length
  1609. };
  1610. }
  1611. else {
  1612. return { prev: false, next: false };
  1613. }
  1614. }
  1615. /**
  1616. * Start playback of any embedded content inside of
  1617. * the targeted slide.
  1618. */
  1619. function startEmbeddedContent( slide ) {
  1620. if( slide && !isSpeakerNotes() ) {
  1621. // HTML5 media elements
  1622. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1623. if( el.hasAttribute( 'data-autoplay' ) ) {
  1624. el.play();
  1625. }
  1626. } );
  1627. // iframe embeds
  1628. toArray( slide.querySelectorAll( 'iframe' ) ).forEach( function( el ) {
  1629. el.contentWindow.postMessage( 'slide:start', '*' );
  1630. });
  1631. // YouTube embeds
  1632. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  1633. if( el.hasAttribute( 'data-autoplay' ) ) {
  1634. el.contentWindow.postMessage( '{"event":"command","func":"playVideo","args":""}', '*' );
  1635. }
  1636. });
  1637. }
  1638. }
  1639. /**
  1640. * Stop playback of any embedded content inside of
  1641. * the targeted slide.
  1642. */
  1643. function stopEmbeddedContent( slide ) {
  1644. if( slide ) {
  1645. // HTML5 media elements
  1646. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1647. if( !el.hasAttribute( 'data-ignore' ) ) {
  1648. el.pause();
  1649. }
  1650. } );
  1651. // iframe embeds
  1652. toArray( slide.querySelectorAll( 'iframe' ) ).forEach( function( el ) {
  1653. el.contentWindow.postMessage( 'slide:stop', '*' );
  1654. });
  1655. // YouTube embeds
  1656. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  1657. if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
  1658. el.contentWindow.postMessage( '{"event":"command","func":"pauseVideo","args":""}', '*' );
  1659. }
  1660. });
  1661. }
  1662. }
  1663. /**
  1664. * Returns a value ranging from 0-1 that represents
  1665. * how far into the presentation we have navigated.
  1666. */
  1667. function getProgress() {
  1668. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1669. // The number of past and total slides
  1670. var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  1671. var pastCount = 0;
  1672. // Step through all slides and count the past ones
  1673. mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
  1674. var horizontalSlide = horizontalSlides[i];
  1675. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1676. for( var j = 0; j < verticalSlides.length; j++ ) {
  1677. // Stop as soon as we arrive at the present
  1678. if( verticalSlides[j].classList.contains( 'present' ) ) {
  1679. break mainLoop;
  1680. }
  1681. pastCount++;
  1682. }
  1683. // Stop as soon as we arrive at the present
  1684. if( horizontalSlide.classList.contains( 'present' ) ) {
  1685. break;
  1686. }
  1687. // Don't count the wrapping section for vertical slides
  1688. if( horizontalSlide.classList.contains( 'stack' ) === false ) {
  1689. pastCount++;
  1690. }
  1691. }
  1692. if( currentSlide ) {
  1693. var allFragments = currentSlide.querySelectorAll( '.fragment' );
  1694. // If there are fragments in the current slide those should be
  1695. // accounted for in the progress.
  1696. if( allFragments.length > 0 ) {
  1697. var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
  1698. // This value represents how big a portion of the slide progress
  1699. // that is made up by its fragments (0-1)
  1700. var fragmentWeight = 0.9;
  1701. // Add fragment progress to the past slide count
  1702. pastCount += ( visibleFragments.length / allFragments.length ) * fragmentWeight;
  1703. }
  1704. }
  1705. return pastCount / ( totalCount - 1 );
  1706. }
  1707. /**
  1708. * Checks if this presentation is running inside of the
  1709. * speaker notes window.
  1710. */
  1711. function isSpeakerNotes() {
  1712. return !!window.location.search.match( /receiver/gi );
  1713. }
  1714. /**
  1715. * Reads the current URL (hash) and navigates accordingly.
  1716. */
  1717. function readURL() {
  1718. var hash = window.location.hash;
  1719. // Attempt to parse the hash as either an index or name
  1720. var bits = hash.slice( 2 ).split( '/' ),
  1721. name = hash.replace( /#|\//gi, '' );
  1722. // If the first bit is invalid and there is a name we can
  1723. // assume that this is a named link
  1724. if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
  1725. var element;
  1726. try {
  1727. // Find the slide with the specified name
  1728. element = document.querySelector( '#' + name );
  1729. }
  1730. catch( e ) {
  1731. // If the ID is an invalid selector a harmless SyntaxError
  1732. // may be thrown here.
  1733. }
  1734. if( element ) {
  1735. // Find the position of the named slide and navigate to it
  1736. var indices = Reveal.getIndices( element );
  1737. slide( indices.h, indices.v );
  1738. }
  1739. // If the slide doesn't exist, navigate to the current slide
  1740. else {
  1741. slide( indexh || 0, indexv || 0 );
  1742. }
  1743. }
  1744. else {
  1745. // Read the index components of the hash
  1746. var h = parseInt( bits[0], 10 ) || 0,
  1747. v = parseInt( bits[1], 10 ) || 0;
  1748. if( h !== indexh || v !== indexv ) {
  1749. slide( h, v );
  1750. }
  1751. }
  1752. }
  1753. /**
  1754. * Updates the page URL (hash) to reflect the current
  1755. * state.
  1756. *
  1757. * @param {Number} delay The time in ms to wait before
  1758. * writing the hash
  1759. */
  1760. function writeURL( delay ) {
  1761. if( config.history ) {
  1762. // Make sure there's never more than one timeout running
  1763. clearTimeout( writeURLTimeout );
  1764. // If a delay is specified, timeout this call
  1765. if( typeof delay === 'number' ) {
  1766. writeURLTimeout = setTimeout( writeURL, delay );
  1767. }
  1768. else {
  1769. var url = '/';
  1770. // Attempt to create a named link based on the slide's ID
  1771. var id = currentSlide.getAttribute( 'id' );
  1772. if( id ) {
  1773. id = id.toLowerCase();
  1774. id = id.replace( /[^a-zA-Z0-9\-\_\:\.]/g, '' );
  1775. }
  1776. // If the current slide has an ID, use that as a named link
  1777. if( currentSlide && typeof id === 'string' && id.length ) {
  1778. url = '/' + id;
  1779. }
  1780. // Otherwise use the /h/v index
  1781. else {
  1782. if( indexh > 0 || indexv > 0 ) url += indexh;
  1783. if( indexv > 0 ) url += '/' + indexv;
  1784. }
  1785. window.location.hash = url;
  1786. }
  1787. }
  1788. }
  1789. /**
  1790. * Retrieves the h/v location of the current, or specified,
  1791. * slide.
  1792. *
  1793. * @param {HTMLElement} slide If specified, the returned
  1794. * index will be for this slide rather than the currently
  1795. * active one
  1796. *
  1797. * @return {Object} { h: <int>, v: <int>, f: <int> }
  1798. */
  1799. function getIndices( slide ) {
  1800. // By default, return the current indices
  1801. var h = indexh,
  1802. v = indexv,
  1803. f;
  1804. // If a slide is specified, return the indices of that slide
  1805. if( slide ) {
  1806. var isVertical = isVerticalSlide( slide );
  1807. var slideh = isVertical ? slide.parentNode : slide;
  1808. // Select all horizontal slides
  1809. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1810. // Now that we know which the horizontal slide is, get its index
  1811. h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
  1812. // If this is a vertical slide, grab the vertical index
  1813. if( isVertical ) {
  1814. v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
  1815. }
  1816. }
  1817. if( !slide && currentSlide ) {
  1818. var hasFragments = currentSlide.querySelectorAll( '.fragment' ).length > 0;
  1819. if( hasFragments ) {
  1820. var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
  1821. f = visibleFragments.length - 1;
  1822. }
  1823. }
  1824. return { h: h, v: v, f: f };
  1825. }
  1826. /**
  1827. * Retrieves the total number of slides in this presentation.
  1828. */
  1829. function getTotalSlides() {
  1830. return document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  1831. }
  1832. /**
  1833. * Retrieves the current state of the presentation as
  1834. * an object. This state can then be restored at any
  1835. * time.
  1836. */
  1837. function getState() {
  1838. var indices = getIndices();
  1839. return {
  1840. indexh: indices.h,
  1841. indexv: indices.v,
  1842. indexf: indices.f,
  1843. paused: isPaused(),
  1844. overview: isOverview()
  1845. };
  1846. }
  1847. /**
  1848. * Restores the presentation to the given state.
  1849. *
  1850. * @param {Object} state As generated by getState()
  1851. */
  1852. function setState( state ) {
  1853. if( typeof state === 'object' ) {
  1854. slide( deserialize( state.indexh ), deserialize( state.indexv ), deserialize( state.indexf ) );
  1855. togglePause( deserialize( state.paused ) );
  1856. toggleOverview( deserialize( state.overview ) );
  1857. }
  1858. }
  1859. /**
  1860. * Return a sorted fragments list, ordered by an increasing
  1861. * "data-fragment-index" attribute.
  1862. *
  1863. * Fragments will be revealed in the order that they are returned by
  1864. * this function, so you can use the index attributes to control the
  1865. * order of fragment appearance.
  1866. *
  1867. * To maintain a sensible default fragment order, fragments are presumed
  1868. * to be passed in document order. This function adds a "fragment-index"
  1869. * attribute to each node if such an attribute is not already present,
  1870. * and sets that attribute to an integer value which is the position of
  1871. * the fragment within the fragments list.
  1872. */
  1873. function sortFragments( fragments ) {
  1874. fragments = toArray( fragments );
  1875. var ordered = [],
  1876. unordered = [],
  1877. sorted = [];
  1878. // Group ordered and unordered elements
  1879. fragments.forEach( function( fragment, i ) {
  1880. if( fragment.hasAttribute( 'data-fragment-index' ) ) {
  1881. var index = parseInt( fragment.getAttribute( 'data-fragment-index' ), 10 );
  1882. if( !ordered[index] ) {
  1883. ordered[index] = [];
  1884. }
  1885. ordered[index].push( fragment );
  1886. }
  1887. else {
  1888. unordered.push( [ fragment ] );
  1889. }
  1890. } );
  1891. // Append fragments without explicit indices in their
  1892. // DOM order
  1893. ordered = ordered.concat( unordered );
  1894. // Manually count the index up per group to ensure there
  1895. // are no gaps
  1896. var index = 0;
  1897. // Push all fragments in their sorted order to an array,
  1898. // this flattens the groups
  1899. ordered.forEach( function( group ) {
  1900. group.forEach( function( fragment ) {
  1901. sorted.push( fragment );
  1902. fragment.setAttribute( 'data-fragment-index', index );
  1903. } );
  1904. index ++;
  1905. } );
  1906. return sorted;
  1907. }
  1908. /**
  1909. * Navigate to the specified slide fragment.
  1910. *
  1911. * @param {Number} index The index of the fragment that
  1912. * should be shown, -1 means all are invisible
  1913. * @param {Number} offset Integer offset to apply to the
  1914. * fragment index
  1915. *
  1916. * @return {Boolean} true if a change was made in any
  1917. * fragments visibility as part of this call
  1918. */
  1919. function navigateFragment( index, offset ) {
  1920. if( currentSlide && config.fragments ) {
  1921. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
  1922. if( fragments.length ) {
  1923. // If no index is specified, find the current
  1924. if( typeof index !== 'number' ) {
  1925. var lastVisibleFragment = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) ).pop();
  1926. if( lastVisibleFragment ) {
  1927. index = parseInt( lastVisibleFragment.getAttribute( 'data-fragment-index' ) || 0, 10 );
  1928. }
  1929. else {
  1930. index = -1;
  1931. }
  1932. }
  1933. // If an offset is specified, apply it to the index
  1934. if( typeof offset === 'number' ) {
  1935. index += offset;
  1936. }
  1937. var fragmentsShown = [],
  1938. fragmentsHidden = [];
  1939. toArray( fragments ).forEach( function( element, i ) {
  1940. if( element.hasAttribute( 'data-fragment-index' ) ) {
  1941. i = parseInt( element.getAttribute( 'data-fragment-index' ), 10 );
  1942. }
  1943. // Visible fragments
  1944. if( i <= index ) {
  1945. if( !element.classList.contains( 'visible' ) ) fragmentsShown.push( element );
  1946. element.classList.add( 'visible' );
  1947. element.classList.remove( 'current-fragment' );
  1948. if( i === index ) {
  1949. element.classList.add( 'current-fragment' );
  1950. }
  1951. }
  1952. // Hidden fragments
  1953. else {
  1954. if( element.classList.contains( 'visible' ) ) fragmentsHidden.push( element );
  1955. element.classList.remove( 'visible' );
  1956. element.classList.remove( 'current-fragment' );
  1957. }
  1958. } );
  1959. if( fragmentsHidden.length ) {
  1960. dispatchEvent( 'fragmenthidden', { fragment: fragmentsHidden[0], fragments: fragmentsHidden } );
  1961. }
  1962. if( fragmentsShown.length ) {
  1963. dispatchEvent( 'fragmentshown', { fragment: fragmentsShown[0], fragments: fragmentsShown } );
  1964. }
  1965. updateControls();
  1966. updateProgress();
  1967. return !!( fragmentsShown.length || fragmentsHidden.length );
  1968. }
  1969. }
  1970. return false;
  1971. }
  1972. /**
  1973. * Navigate to the next slide fragment.
  1974. *
  1975. * @return {Boolean} true if there was a next fragment,
  1976. * false otherwise
  1977. */
  1978. function nextFragment() {
  1979. return navigateFragment( null, 1 );
  1980. }
  1981. /**
  1982. * Navigate to the previous slide fragment.
  1983. *
  1984. * @return {Boolean} true if there was a previous fragment,
  1985. * false otherwise
  1986. */
  1987. function previousFragment() {
  1988. return navigateFragment( null, -1 );
  1989. }
  1990. /**
  1991. * Cues a new automated slide if enabled in the config.
  1992. */
  1993. function cueAutoSlide() {
  1994. cancelAutoSlide();
  1995. if( currentSlide ) {
  1996. var currentFragment = currentSlide.querySelector( '.current-fragment' );
  1997. var fragmentAutoSlide = currentFragment ? currentFragment.getAttribute( 'data-autoslide' ) : null;
  1998. var parentAutoSlide = currentSlide.parentNode ? currentSlide.parentNode.getAttribute( 'data-autoslide' ) : null;
  1999. var slideAutoSlide = currentSlide.getAttribute( 'data-autoslide' );
  2000. // Pick value in the following priority order:
  2001. // 1. Current fragment's data-autoslide
  2002. // 2. Current slide's data-autoslide
  2003. // 3. Parent slide's data-autoslide
  2004. // 4. Global autoSlide setting
  2005. if( fragmentAutoSlide ) {
  2006. autoSlide = parseInt( fragmentAutoSlide, 10 );
  2007. }
  2008. else if( slideAutoSlide ) {
  2009. autoSlide = parseInt( slideAutoSlide, 10 );
  2010. }
  2011. else if( parentAutoSlide ) {
  2012. autoSlide = parseInt( parentAutoSlide, 10 );
  2013. }
  2014. else {
  2015. autoSlide = config.autoSlide;
  2016. }
  2017. // If there are media elements with data-autoplay,
  2018. // automatically set the autoSlide duration to the
  2019. // length of that media
  2020. toArray( currentSlide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  2021. if( el.hasAttribute( 'data-autoplay' ) ) {
  2022. if( autoSlide && el.duration * 1000 > autoSlide ) {
  2023. autoSlide = ( el.duration * 1000 ) + 1000;
  2024. }
  2025. }
  2026. } );
  2027. // Cue the next auto-slide if:
  2028. // - There is an autoSlide value
  2029. // - Auto-sliding isn't paused by the user
  2030. // - The presentation isn't paused
  2031. // - The overview isn't active
  2032. // - The presentation isn't over
  2033. if( autoSlide && !autoSlidePaused && !isPaused() && !isOverview() && ( !Reveal.isLastSlide() || config.loop === true ) ) {
  2034. autoSlideTimeout = setTimeout( navigateNext, autoSlide );
  2035. autoSlideStartTime = Date.now();
  2036. }
  2037. if( autoSlidePlayer ) {
  2038. autoSlidePlayer.setPlaying( autoSlideTimeout !== -1 );
  2039. }
  2040. }
  2041. }
  2042. /**
  2043. * Cancels any ongoing request to auto-slide.
  2044. */
  2045. function cancelAutoSlide() {
  2046. clearTimeout( autoSlideTimeout );
  2047. autoSlideTimeout = -1;
  2048. }
  2049. function pauseAutoSlide() {
  2050. autoSlidePaused = true;
  2051. dispatchEvent( 'autoslidepaused' );
  2052. clearTimeout( autoSlideTimeout );
  2053. if( autoSlidePlayer ) {
  2054. autoSlidePlayer.setPlaying( false );
  2055. }
  2056. }
  2057. function resumeAutoSlide() {
  2058. autoSlidePaused = false;
  2059. dispatchEvent( 'autoslideresumed' );
  2060. cueAutoSlide();
  2061. }
  2062. function navigateLeft() {
  2063. // Reverse for RTL
  2064. if( config.rtl ) {
  2065. if( ( isOverview() || nextFragment() === false ) && availableRoutes().left ) {
  2066. slide( indexh + 1 );
  2067. }
  2068. }
  2069. // Normal navigation
  2070. else if( ( isOverview() || previousFragment() === false ) && availableRoutes().left ) {
  2071. slide( indexh - 1 );
  2072. }
  2073. }
  2074. function navigateRight() {
  2075. // Reverse for RTL
  2076. if( config.rtl ) {
  2077. if( ( isOverview() || previousFragment() === false ) && availableRoutes().right ) {
  2078. slide( indexh - 1 );
  2079. }
  2080. }
  2081. // Normal navigation
  2082. else if( ( isOverview() || nextFragment() === false ) && availableRoutes().right ) {
  2083. slide( indexh + 1 );
  2084. }
  2085. }
  2086. function navigateUp() {
  2087. // Prioritize hiding fragments
  2088. if( ( isOverview() || previousFragment() === false ) && availableRoutes().up ) {
  2089. slide( indexh, indexv - 1 );
  2090. }
  2091. }
  2092. function navigateDown() {
  2093. // Prioritize revealing fragments
  2094. if( ( isOverview() || nextFragment() === false ) && availableRoutes().down ) {
  2095. slide( indexh, indexv + 1 );
  2096. }
  2097. }
  2098. /**
  2099. * Navigates backwards, prioritized in the following order:
  2100. * 1) Previous fragment
  2101. * 2) Previous vertical slide
  2102. * 3) Previous horizontal slide
  2103. */
  2104. function navigatePrev() {
  2105. // Prioritize revealing fragments
  2106. if( previousFragment() === false ) {
  2107. if( availableRoutes().up ) {
  2108. navigateUp();
  2109. }
  2110. else {
  2111. // Fetch the previous horizontal slide, if there is one
  2112. var previousSlide = document.querySelector( HORIZONTAL_SLIDES_SELECTOR + '.past:nth-child(' + indexh + ')' );
  2113. if( previousSlide ) {
  2114. var v = ( previousSlide.querySelectorAll( 'section' ).length - 1 ) || undefined;
  2115. var h = indexh - 1;
  2116. slide( h, v );
  2117. }
  2118. }
  2119. }
  2120. }
  2121. /**
  2122. * Same as #navigatePrev() but navigates forwards.
  2123. */
  2124. function navigateNext() {
  2125. // Prioritize revealing fragments
  2126. if( nextFragment() === false ) {
  2127. availableRoutes().down ? navigateDown() : navigateRight();
  2128. }
  2129. // If auto-sliding is enabled we need to cue up
  2130. // another timeout
  2131. cueAutoSlide();
  2132. }
  2133. // --------------------------------------------------------------------//
  2134. // ----------------------------- EVENTS -------------------------------//
  2135. // --------------------------------------------------------------------//
  2136. /**
  2137. * Called by all event handlers that are based on user
  2138. * input.
  2139. */
  2140. function onUserInput( event ) {
  2141. if( config.autoSlideStoppable ) {
  2142. pauseAutoSlide();
  2143. }
  2144. }
  2145. /**
  2146. * Handler for the document level 'keydown' event.
  2147. */
  2148. function onDocumentKeyDown( event ) {
  2149. // Remember if auto-sliding was paused so we can toggle it
  2150. var autoSlideWasPaused = autoSlidePaused;
  2151. onUserInput( event );
  2152. // Check if there's a focused element that could be using
  2153. // the keyboard
  2154. var activeElement = document.activeElement;
  2155. var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) );
  2156. // Disregard the event if there's a focused element or a
  2157. // keyboard modifier key is present
  2158. if( hasFocus || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
  2159. // While paused only allow "unpausing" keyboard events (b and .)
  2160. if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) {
  2161. return false;
  2162. }
  2163. var triggered = false;
  2164. // 1. User defined key bindings
  2165. if( typeof config.keyboard === 'object' ) {
  2166. for( var key in config.keyboard ) {
  2167. // Check if this binding matches the pressed key
  2168. if( parseInt( key, 10 ) === event.keyCode ) {
  2169. var value = config.keyboard[ key ];
  2170. // Callback function
  2171. if( typeof value === 'function' ) {
  2172. value.apply( null, [ event ] );
  2173. }
  2174. // String shortcuts to reveal.js API
  2175. else if( typeof value === 'string' && typeof Reveal[ value ] === 'function' ) {
  2176. Reveal[ value ].call();
  2177. }
  2178. triggered = true;
  2179. }
  2180. }
  2181. }
  2182. // 2. System defined key bindings
  2183. if( triggered === false ) {
  2184. // Assume true and try to prove false
  2185. triggered = true;
  2186. switch( event.keyCode ) {
  2187. // p, page up
  2188. case 80: case 33: navigatePrev(); break;
  2189. // n, page down
  2190. case 78: case 34: navigateNext(); break;
  2191. // h, left
  2192. case 72: case 37: navigateLeft(); break;
  2193. // l, right
  2194. case 76: case 39: navigateRight(); break;
  2195. // k, up
  2196. case 75: case 38: navigateUp(); break;
  2197. // j, down
  2198. case 74: case 40: navigateDown(); break;
  2199. // home
  2200. case 36: slide( 0 ); break;
  2201. // end
  2202. case 35: slide( Number.MAX_VALUE ); break;
  2203. // space
  2204. case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
  2205. // return
  2206. case 13: isOverview() ? deactivateOverview() : triggered = false; break;
  2207. // b, period, Logitech presenter tools "black screen" button
  2208. case 66: case 190: case 191: togglePause(); break;
  2209. // f
  2210. case 70: enterFullscreen(); break;
  2211. // a
  2212. case 65: if ( config.autoSlideStoppable ) toggleAutoSlide( autoSlideWasPaused ); break;
  2213. default:
  2214. triggered = false;
  2215. }
  2216. }
  2217. // If the input resulted in a triggered action we should prevent
  2218. // the browsers default behavior
  2219. if( triggered ) {
  2220. event.preventDefault();
  2221. }
  2222. // ESC or O key
  2223. else if ( ( event.keyCode === 27 || event.keyCode === 79 ) && features.transforms3d ) {
  2224. if( dom.preview ) {
  2225. closePreview();
  2226. }
  2227. else {
  2228. toggleOverview();
  2229. }
  2230. event.preventDefault();
  2231. }
  2232. // If auto-sliding is enabled we need to cue up
  2233. // another timeout
  2234. cueAutoSlide();
  2235. }
  2236. /**
  2237. * Handler for the 'touchstart' event, enables support for
  2238. * swipe and pinch gestures.
  2239. */
  2240. function onTouchStart( event ) {
  2241. touch.startX = event.touches[0].clientX;
  2242. touch.startY = event.touches[0].clientY;
  2243. touch.startCount = event.touches.length;
  2244. // If there's two touches we need to memorize the distance
  2245. // between those two points to detect pinching
  2246. if( event.touches.length === 2 && config.overview ) {
  2247. touch.startSpan = distanceBetween( {
  2248. x: event.touches[1].clientX,
  2249. y: event.touches[1].clientY
  2250. }, {
  2251. x: touch.startX,
  2252. y: touch.startY
  2253. } );
  2254. }
  2255. }
  2256. /**
  2257. * Handler for the 'touchmove' event.
  2258. */
  2259. function onTouchMove( event ) {
  2260. // Each touch should only trigger one action
  2261. if( !touch.captured ) {
  2262. onUserInput( event );
  2263. var currentX = event.touches[0].clientX;
  2264. var currentY = event.touches[0].clientY;
  2265. // If the touch started with two points and still has
  2266. // two active touches; test for the pinch gesture
  2267. if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
  2268. // The current distance in pixels between the two touch points
  2269. var currentSpan = distanceBetween( {
  2270. x: event.touches[1].clientX,
  2271. y: event.touches[1].clientY
  2272. }, {
  2273. x: touch.startX,
  2274. y: touch.startY
  2275. } );
  2276. // If the span is larger than the desire amount we've got
  2277. // ourselves a pinch
  2278. if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
  2279. touch.captured = true;
  2280. if( currentSpan < touch.startSpan ) {
  2281. activateOverview();
  2282. }
  2283. else {
  2284. deactivateOverview();
  2285. }
  2286. }
  2287. event.preventDefault();
  2288. }
  2289. // There was only one touch point, look for a swipe
  2290. else if( event.touches.length === 1 && touch.startCount !== 2 ) {
  2291. var deltaX = currentX - touch.startX,
  2292. deltaY = currentY - touch.startY;
  2293. if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  2294. touch.captured = true;
  2295. navigateLeft();
  2296. }
  2297. else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  2298. touch.captured = true;
  2299. navigateRight();
  2300. }
  2301. else if( deltaY > touch.threshold ) {
  2302. touch.captured = true;
  2303. navigateUp();
  2304. }
  2305. else if( deltaY < -touch.threshold ) {
  2306. touch.captured = true;
  2307. navigateDown();
  2308. }
  2309. // If we're embedded, only block touch events if they have
  2310. // triggered an action
  2311. if( config.embedded ) {
  2312. if( touch.captured || isVerticalSlide( currentSlide ) ) {
  2313. event.preventDefault();
  2314. }
  2315. }
  2316. // Not embedded? Block them all to avoid needless tossing
  2317. // around of the viewport in iOS
  2318. else {
  2319. event.preventDefault();
  2320. }
  2321. }
  2322. }
  2323. // There's a bug with swiping on some Android devices unless
  2324. // the default action is always prevented
  2325. else if( navigator.userAgent.match( /android/gi ) ) {
  2326. event.preventDefault();
  2327. }
  2328. }
  2329. /**
  2330. * Handler for the 'touchend' event.
  2331. */
  2332. function onTouchEnd( event ) {
  2333. touch.captured = false;
  2334. }
  2335. /**
  2336. * Convert pointer down to touch start.
  2337. */
  2338. function onPointerDown( event ) {
  2339. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  2340. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  2341. onTouchStart( event );
  2342. }
  2343. }
  2344. /**
  2345. * Convert pointer move to touch move.
  2346. */
  2347. function onPointerMove( event ) {
  2348. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  2349. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  2350. onTouchMove( event );
  2351. }
  2352. }
  2353. /**
  2354. * Convert pointer up to touch end.
  2355. */
  2356. function onPointerUp( event ) {
  2357. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  2358. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  2359. onTouchEnd( event );
  2360. }
  2361. }
  2362. /**
  2363. * Handles mouse wheel scrolling, throttled to avoid skipping
  2364. * multiple slides.
  2365. */
  2366. function onDocumentMouseScroll( event ) {
  2367. if( Date.now() - lastMouseWheelStep > 600 ) {
  2368. lastMouseWheelStep = Date.now();
  2369. var delta = event.detail || -event.wheelDelta;
  2370. if( delta > 0 ) {
  2371. navigateNext();
  2372. }
  2373. else {
  2374. navigatePrev();
  2375. }
  2376. }
  2377. }
  2378. /**
  2379. * Clicking on the progress bar results in a navigation to the
  2380. * closest approximate horizontal slide using this equation:
  2381. *
  2382. * ( clickX / presentationWidth ) * numberOfSlides
  2383. */
  2384. function onProgressClicked( event ) {
  2385. onUserInput( event );
  2386. event.preventDefault();
  2387. var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
  2388. var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
  2389. slide( slideIndex );
  2390. }
  2391. /**
  2392. * Event handler for navigation control buttons.
  2393. */
  2394. function onNavigateLeftClicked( event ) { event.preventDefault(); onUserInput(); navigateLeft(); }
  2395. function onNavigateRightClicked( event ) { event.preventDefault(); onUserInput(); navigateRight(); }
  2396. function onNavigateUpClicked( event ) { event.preventDefault(); onUserInput(); navigateUp(); }
  2397. function onNavigateDownClicked( event ) { event.preventDefault(); onUserInput(); navigateDown(); }
  2398. function onNavigatePrevClicked( event ) { event.preventDefault(); onUserInput(); navigatePrev(); }
  2399. function onNavigateNextClicked( event ) { event.preventDefault(); onUserInput(); navigateNext(); }
  2400. /**
  2401. * Handler for the window level 'hashchange' event.
  2402. */
  2403. function onWindowHashChange( event ) {
  2404. readURL();
  2405. }
  2406. /**
  2407. * Handler for the window level 'resize' event.
  2408. */
  2409. function onWindowResize( event ) {
  2410. layout();
  2411. }
  2412. /**
  2413. * Handle for the window level 'visibilitychange' event.
  2414. */
  2415. function onPageVisibilityChange( event ) {
  2416. var isHidden = document.webkitHidden ||
  2417. document.msHidden ||
  2418. document.hidden;
  2419. // If, after clicking a link or similar and we're coming back,
  2420. // focus the document.body to ensure we can use keyboard shortcuts
  2421. if( isHidden === false && document.activeElement !== document.body ) {
  2422. document.activeElement.blur();
  2423. document.body.focus();
  2424. }
  2425. }
  2426. /**
  2427. * Invoked when a slide is and we're in the overview.
  2428. */
  2429. function onOverviewSlideClicked( event ) {
  2430. // TODO There's a bug here where the event listeners are not
  2431. // removed after deactivating the overview.
  2432. if( eventsAreBound && isOverview() ) {
  2433. event.preventDefault();
  2434. var element = event.target;
  2435. while( element && !element.nodeName.match( /section/gi ) ) {
  2436. element = element.parentNode;
  2437. }
  2438. if( element && !element.classList.contains( 'disabled' ) ) {
  2439. deactivateOverview();
  2440. if( element.nodeName.match( /section/gi ) ) {
  2441. var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
  2442. v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
  2443. slide( h, v );
  2444. }
  2445. }
  2446. }
  2447. }
  2448. /**
  2449. * Handles clicks on links that are set to preview in the
  2450. * iframe overlay.
  2451. */
  2452. function onPreviewLinkClicked( event ) {
  2453. var url = event.target.getAttribute( 'href' );
  2454. if( url ) {
  2455. openPreview( url );
  2456. event.preventDefault();
  2457. }
  2458. }
  2459. /**
  2460. * Handles click on the auto-sliding controls element.
  2461. */
  2462. function onAutoSlidePlayerClick( event ) {
  2463. // Replay
  2464. if( Reveal.isLastSlide() && config.loop === false ) {
  2465. slide( 0, 0 );
  2466. resumeAutoSlide();
  2467. }
  2468. // Resume
  2469. else if( autoSlidePaused ) {
  2470. resumeAutoSlide();
  2471. }
  2472. // Pause
  2473. else {
  2474. pauseAutoSlide();
  2475. }
  2476. }
  2477. // --------------------------------------------------------------------//
  2478. // ------------------------ PLAYBACK COMPONENT ------------------------//
  2479. // --------------------------------------------------------------------//
  2480. /**
  2481. * Constructor for the playback component, which displays
  2482. * play/pause/progress controls.
  2483. *
  2484. * @param {HTMLElement} container The component will append
  2485. * itself to this
  2486. * @param {Function} progressCheck A method which will be
  2487. * called frequently to get the current progress on a range
  2488. * of 0-1
  2489. */
  2490. function Playback( container, progressCheck ) {
  2491. // Cosmetics
  2492. this.diameter = 50;
  2493. this.thickness = 3;
  2494. // Flags if we are currently playing
  2495. this.playing = false;
  2496. // Current progress on a 0-1 range
  2497. this.progress = 0;
  2498. // Used to loop the animation smoothly
  2499. this.progressOffset = 1;
  2500. this.container = container;
  2501. this.progressCheck = progressCheck;
  2502. this.canvas = document.createElement( 'canvas' );
  2503. this.canvas.className = 'playback';
  2504. this.canvas.width = this.diameter;
  2505. this.canvas.height = this.diameter;
  2506. this.context = this.canvas.getContext( '2d' );
  2507. this.container.appendChild( this.canvas );
  2508. this.render();
  2509. }
  2510. Playback.prototype.setPlaying = function( value ) {
  2511. var wasPlaying = this.playing;
  2512. this.playing = value;
  2513. // Start repainting if we weren't already
  2514. if( !wasPlaying && this.playing ) {
  2515. this.animate();
  2516. }
  2517. else {
  2518. this.render();
  2519. }
  2520. };
  2521. Playback.prototype.animate = function() {
  2522. var progressBefore = this.progress;
  2523. this.progress = this.progressCheck();
  2524. // When we loop, offset the progress so that it eases
  2525. // smoothly rather than immediately resetting
  2526. if( progressBefore > 0.8 && this.progress < 0.2 ) {
  2527. this.progressOffset = this.progress;
  2528. }
  2529. this.render();
  2530. if( this.playing ) {
  2531. features.requestAnimationFrameMethod.call( window, this.animate.bind( this ) );
  2532. }
  2533. };
  2534. /**
  2535. * Renders the current progress and playback state.
  2536. */
  2537. Playback.prototype.render = function() {
  2538. var progress = this.playing ? this.progress : 0,
  2539. radius = ( this.diameter / 2 ) - this.thickness,
  2540. x = this.diameter / 2,
  2541. y = this.diameter / 2,
  2542. iconSize = 14;
  2543. // Ease towards 1
  2544. this.progressOffset += ( 1 - this.progressOffset ) * 0.1;
  2545. var endAngle = ( - Math.PI / 2 ) + ( progress * ( Math.PI * 2 ) );
  2546. var startAngle = ( - Math.PI / 2 ) + ( this.progressOffset * ( Math.PI * 2 ) );
  2547. this.context.save();
  2548. this.context.clearRect( 0, 0, this.diameter, this.diameter );
  2549. // Solid background color
  2550. this.context.beginPath();
  2551. this.context.arc( x, y, radius + 2, 0, Math.PI * 2, false );
  2552. this.context.fillStyle = 'rgba( 0, 0, 0, 0.4 )';
  2553. this.context.fill();
  2554. // Draw progress track
  2555. this.context.beginPath();
  2556. this.context.arc( x, y, radius, 0, Math.PI * 2, false );
  2557. this.context.lineWidth = this.thickness;
  2558. this.context.strokeStyle = '#666';
  2559. this.context.stroke();
  2560. if( this.playing ) {
  2561. // Draw progress on top of track
  2562. this.context.beginPath();
  2563. this.context.arc( x, y, radius, startAngle, endAngle, false );
  2564. this.context.lineWidth = this.thickness;
  2565. this.context.strokeStyle = '#fff';
  2566. this.context.stroke();
  2567. }
  2568. this.context.translate( x - ( iconSize / 2 ), y - ( iconSize / 2 ) );
  2569. // Draw play/pause icons
  2570. if( this.playing ) {
  2571. this.context.fillStyle = '#fff';
  2572. this.context.fillRect( 0, 0, iconSize / 2 - 2, iconSize );
  2573. this.context.fillRect( iconSize / 2 + 2, 0, iconSize / 2 - 2, iconSize );
  2574. }
  2575. else {
  2576. this.context.beginPath();
  2577. this.context.translate( 2, 0 );
  2578. this.context.moveTo( 0, 0 );
  2579. this.context.lineTo( iconSize - 2, iconSize / 2 );
  2580. this.context.lineTo( 0, iconSize );
  2581. this.context.fillStyle = '#fff';
  2582. this.context.fill();
  2583. }
  2584. this.context.restore();
  2585. };
  2586. Playback.prototype.on = function( type, listener ) {
  2587. this.canvas.addEventListener( type, listener, false );
  2588. };
  2589. Playback.prototype.off = function( type, listener ) {
  2590. this.canvas.removeEventListener( type, listener, false );
  2591. };
  2592. Playback.prototype.destroy = function() {
  2593. this.playing = false;
  2594. if( this.canvas.parentNode ) {
  2595. this.container.removeChild( this.canvas );
  2596. }
  2597. };
  2598. // --------------------------------------------------------------------//
  2599. // ------------------------------- API --------------------------------//
  2600. // --------------------------------------------------------------------//
  2601. return {
  2602. initialize: initialize,
  2603. configure: configure,
  2604. sync: sync,
  2605. // Navigation methods
  2606. slide: slide,
  2607. left: navigateLeft,
  2608. right: navigateRight,
  2609. up: navigateUp,
  2610. down: navigateDown,
  2611. prev: navigatePrev,
  2612. next: navigateNext,
  2613. // Fragment methods
  2614. navigateFragment: navigateFragment,
  2615. prevFragment: previousFragment,
  2616. nextFragment: nextFragment,
  2617. // Deprecated aliases
  2618. navigateTo: slide,
  2619. navigateLeft: navigateLeft,
  2620. navigateRight: navigateRight,
  2621. navigateUp: navigateUp,
  2622. navigateDown: navigateDown,
  2623. navigatePrev: navigatePrev,
  2624. navigateNext: navigateNext,
  2625. // Forces an update in slide layout
  2626. layout: layout,
  2627. // Returns an object with the available routes as booleans (left/right/top/bottom)
  2628. availableRoutes: availableRoutes,
  2629. // Returns an object with the available fragments as booleans (prev/next)
  2630. availableFragments: availableFragments,
  2631. // Toggles the overview mode on/off
  2632. toggleOverview: toggleOverview,
  2633. // Toggles the "black screen" mode on/off
  2634. togglePause: togglePause,
  2635. // Toggles the auto slide mode on/off
  2636. toggleAutoSlide: toggleAutoSlide,
  2637. // State checks
  2638. isOverview: isOverview,
  2639. isPaused: isPaused,
  2640. isAutoSliding: isAutoSliding,
  2641. // Adds or removes all internal event listeners (such as keyboard)
  2642. addEventListeners: addEventListeners,
  2643. removeEventListeners: removeEventListeners,
  2644. // Facility for persisting and restoring the presentation state
  2645. getState: getState,
  2646. setState: setState,
  2647. // Presentation progress on range of 0-1
  2648. getProgress: getProgress,
  2649. // Returns the indices of the current, or specified, slide
  2650. getIndices: getIndices,
  2651. getTotalSlides: getTotalSlides,
  2652. // Returns the slide at the specified index, y is optional
  2653. getSlide: function( x, y ) {
  2654. var horizontalSlide = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
  2655. var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
  2656. if( typeof y !== 'undefined' ) {
  2657. return verticalSlides ? verticalSlides[ y ] : undefined;
  2658. }
  2659. return horizontalSlide;
  2660. },
  2661. // Returns the previous slide element, may be null
  2662. getPreviousSlide: function() {
  2663. return previousSlide;
  2664. },
  2665. // Returns the current slide element
  2666. getCurrentSlide: function() {
  2667. return currentSlide;
  2668. },
  2669. // Returns the current scale of the presentation content
  2670. getScale: function() {
  2671. return scale;
  2672. },
  2673. // Returns the current configuration object
  2674. getConfig: function() {
  2675. return config;
  2676. },
  2677. // Helper method, retrieves query string as a key/value hash
  2678. getQueryHash: function() {
  2679. var query = {};
  2680. location.search.replace( /[A-Z0-9]+?=([\w\.%-]*)/gi, function(a) {
  2681. query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
  2682. } );
  2683. // Basic deserialization
  2684. for( var i in query ) {
  2685. var value = query[ i ];
  2686. query[ i ] = deserialize( unescape( value ) );
  2687. }
  2688. return query;
  2689. },
  2690. // Returns true if we're currently on the first slide
  2691. isFirstSlide: function() {
  2692. return document.querySelector( SLIDES_SELECTOR + '.past' ) == null ? true : false;
  2693. },
  2694. // Returns true if we're currently on the last slide
  2695. isLastSlide: function() {
  2696. if( currentSlide ) {
  2697. // Does this slide has next a sibling?
  2698. if( currentSlide.nextElementSibling ) return false;
  2699. // If it's vertical, does its parent have a next sibling?
  2700. if( isVerticalSlide( currentSlide ) && currentSlide.parentNode.nextElementSibling ) return false;
  2701. return true;
  2702. }
  2703. return false;
  2704. },
  2705. // Checks if reveal.js has been loaded and is ready for use
  2706. isReady: function() {
  2707. return loaded;
  2708. },
  2709. // Forward event binding to the reveal DOM element
  2710. addEventListener: function( type, listener, useCapture ) {
  2711. if( 'addEventListener' in window ) {
  2712. ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
  2713. }
  2714. },
  2715. removeEventListener: function( type, listener, useCapture ) {
  2716. if( 'addEventListener' in window ) {
  2717. ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
  2718. }
  2719. }
  2720. };
  2721. })();