reveal.js 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563
  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. dom.slides.style.left = '50%';
  856. dom.slides.style.top = '50%';
  857. dom.slides.style.bottom = 'auto';
  858. dom.slides.style.right = 'auto';
  859. transformElement( dom.slides, 'translate(-50%, -50%) scale('+ scale +')' );
  860. }
  861. // Select all slides, vertical and horizontal
  862. var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
  863. for( var i = 0, len = slides.length; i < len; i++ ) {
  864. var slide = slides[ i ];
  865. // Don't bother updating invisible slides
  866. if( slide.style.display === 'none' ) {
  867. continue;
  868. }
  869. if( config.center || slide.classList.contains( 'center' ) ) {
  870. // Vertical stacks are not centred since their section
  871. // children will be
  872. if( slide.classList.contains( 'stack' ) ) {
  873. slide.style.top = 0;
  874. }
  875. else {
  876. slide.style.top = Math.max( ( ( slideHeight - getAbsoluteHeight( slide ) ) / 2 ) - slidePadding, 0 ) + 'px';
  877. }
  878. }
  879. else {
  880. slide.style.top = '';
  881. }
  882. }
  883. updateProgress();
  884. updateParallax();
  885. }
  886. }
  887. /**
  888. * Applies layout logic to the contents of all slides in
  889. * the presentation.
  890. */
  891. function layoutSlideContents( width, height, padding ) {
  892. // Handle sizing of elements with the 'stretch' class
  893. toArray( dom.slides.querySelectorAll( 'section > .stretch' ) ).forEach( function( element ) {
  894. // Determine how much vertical space we can use
  895. var remainingHeight = getRemainingHeight( element, height );
  896. // Consider the aspect ratio of media elements
  897. if( /(img|video)/gi.test( element.nodeName ) ) {
  898. var nw = element.naturalWidth || element.videoWidth,
  899. nh = element.naturalHeight || element.videoHeight;
  900. var es = Math.min( width / nw, remainingHeight / nh );
  901. element.style.width = ( nw * es ) + 'px';
  902. element.style.height = ( nh * es ) + 'px';
  903. }
  904. else {
  905. element.style.width = width + 'px';
  906. element.style.height = remainingHeight + 'px';
  907. }
  908. } );
  909. }
  910. /**
  911. * Stores the vertical index of a stack so that the same
  912. * vertical slide can be selected when navigating to and
  913. * from the stack.
  914. *
  915. * @param {HTMLElement} stack The vertical stack element
  916. * @param {int} v Index to memorize
  917. */
  918. function setPreviousVerticalIndex( stack, v ) {
  919. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
  920. stack.setAttribute( 'data-previous-indexv', v || 0 );
  921. }
  922. }
  923. /**
  924. * Retrieves the vertical index which was stored using
  925. * #setPreviousVerticalIndex() or 0 if no previous index
  926. * exists.
  927. *
  928. * @param {HTMLElement} stack The vertical stack element
  929. */
  930. function getPreviousVerticalIndex( stack ) {
  931. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
  932. // Prefer manually defined start-indexv
  933. var attributeName = stack.hasAttribute( 'data-start-indexv' ) ? 'data-start-indexv' : 'data-previous-indexv';
  934. return parseInt( stack.getAttribute( attributeName ) || 0, 10 );
  935. }
  936. return 0;
  937. }
  938. /**
  939. * Displays the overview of slides (quick nav) by
  940. * scaling down and arranging all slide elements.
  941. *
  942. * Experimental feature, might be dropped if perf
  943. * can't be improved.
  944. */
  945. function activateOverview() {
  946. // Only proceed if enabled in config
  947. if( config.overview ) {
  948. // Don't auto-slide while in overview mode
  949. cancelAutoSlide();
  950. var wasActive = dom.wrapper.classList.contains( 'overview' );
  951. // Vary the depth of the overview based on screen size
  952. var depth = window.innerWidth < 400 ? 1000 : 2500;
  953. dom.wrapper.classList.add( 'overview' );
  954. dom.wrapper.classList.remove( 'overview-deactivating' );
  955. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  956. for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
  957. var hslide = horizontalSlides[i],
  958. hoffset = config.rtl ? -105 : 105;
  959. hslide.setAttribute( 'data-index-h', i );
  960. // Apply CSS transform
  961. transformElement( hslide, 'translateZ(-'+ depth +'px) translate(' + ( ( i - indexh ) * hoffset ) + '%, 0%)' );
  962. if( hslide.classList.contains( 'stack' ) ) {
  963. var verticalSlides = hslide.querySelectorAll( 'section' );
  964. for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
  965. var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
  966. var vslide = verticalSlides[j];
  967. vslide.setAttribute( 'data-index-h', i );
  968. vslide.setAttribute( 'data-index-v', j );
  969. // Apply CSS transform
  970. transformElement( vslide, 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)' );
  971. // Navigate to this slide on click
  972. vslide.addEventListener( 'click', onOverviewSlideClicked, true );
  973. }
  974. }
  975. else {
  976. // Navigate to this slide on click
  977. hslide.addEventListener( 'click', onOverviewSlideClicked, true );
  978. }
  979. }
  980. updateSlidesVisibility();
  981. layout();
  982. if( !wasActive ) {
  983. // Notify observers of the overview showing
  984. dispatchEvent( 'overviewshown', {
  985. 'indexh': indexh,
  986. 'indexv': indexv,
  987. 'currentSlide': currentSlide
  988. } );
  989. }
  990. }
  991. }
  992. /**
  993. * Exits the slide overview and enters the currently
  994. * active slide.
  995. */
  996. function deactivateOverview() {
  997. // Only proceed if enabled in config
  998. if( config.overview ) {
  999. dom.wrapper.classList.remove( 'overview' );
  1000. // Temporarily add a class so that transitions can do different things
  1001. // depending on whether they are exiting/entering overview, or just
  1002. // moving from slide to slide
  1003. dom.wrapper.classList.add( 'overview-deactivating' );
  1004. setTimeout( function () {
  1005. dom.wrapper.classList.remove( 'overview-deactivating' );
  1006. }, 1 );
  1007. // Select all slides
  1008. toArray( document.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
  1009. // Resets all transforms to use the external styles
  1010. transformElement( slide, '' );
  1011. slide.removeEventListener( 'click', onOverviewSlideClicked, true );
  1012. } );
  1013. slide( indexh, indexv );
  1014. cueAutoSlide();
  1015. // Notify observers of the overview hiding
  1016. dispatchEvent( 'overviewhidden', {
  1017. 'indexh': indexh,
  1018. 'indexv': indexv,
  1019. 'currentSlide': currentSlide
  1020. } );
  1021. }
  1022. }
  1023. /**
  1024. * Toggles the slide overview mode on and off.
  1025. *
  1026. * @param {Boolean} override Optional flag which overrides the
  1027. * toggle logic and forcibly sets the desired state. True means
  1028. * overview is open, false means it's closed.
  1029. */
  1030. function toggleOverview( override ) {
  1031. if( typeof override === 'boolean' ) {
  1032. override ? activateOverview() : deactivateOverview();
  1033. }
  1034. else {
  1035. isOverview() ? deactivateOverview() : activateOverview();
  1036. }
  1037. }
  1038. /**
  1039. * Checks if the overview is currently active.
  1040. *
  1041. * @return {Boolean} true if the overview is active,
  1042. * false otherwise
  1043. */
  1044. function isOverview() {
  1045. return dom.wrapper.classList.contains( 'overview' );
  1046. }
  1047. /**
  1048. * Checks if the current or specified slide is vertical
  1049. * (nested within another slide).
  1050. *
  1051. * @param {HTMLElement} slide [optional] The slide to check
  1052. * orientation of
  1053. */
  1054. function isVerticalSlide( slide ) {
  1055. // Prefer slide argument, otherwise use current slide
  1056. slide = slide ? slide : currentSlide;
  1057. return slide && slide.parentNode && !!slide.parentNode.nodeName.match( /section/i );
  1058. }
  1059. /**
  1060. * Handling the fullscreen functionality via the fullscreen API
  1061. *
  1062. * @see http://fullscreen.spec.whatwg.org/
  1063. * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
  1064. */
  1065. function enterFullscreen() {
  1066. var element = document.body;
  1067. // Check which implementation is available
  1068. var requestMethod = element.requestFullScreen ||
  1069. element.webkitRequestFullscreen ||
  1070. element.webkitRequestFullScreen ||
  1071. element.mozRequestFullScreen ||
  1072. element.msRequestFullscreen;
  1073. if( requestMethod ) {
  1074. requestMethod.apply( element );
  1075. }
  1076. }
  1077. /**
  1078. * Enters the paused mode which fades everything on screen to
  1079. * black.
  1080. */
  1081. function pause() {
  1082. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1083. cancelAutoSlide();
  1084. dom.wrapper.classList.add( 'paused' );
  1085. if( wasPaused === false ) {
  1086. dispatchEvent( 'paused' );
  1087. }
  1088. }
  1089. /**
  1090. * Exits from the paused mode.
  1091. */
  1092. function resume() {
  1093. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1094. dom.wrapper.classList.remove( 'paused' );
  1095. cueAutoSlide();
  1096. if( wasPaused ) {
  1097. dispatchEvent( 'resumed' );
  1098. }
  1099. }
  1100. /**
  1101. * Toggles the paused mode on and off.
  1102. */
  1103. function togglePause( override ) {
  1104. if( typeof override === 'boolean' ) {
  1105. override ? pause() : resume();
  1106. }
  1107. else {
  1108. isPaused() ? resume() : pause();
  1109. }
  1110. }
  1111. /**
  1112. * Checks if we are currently in the paused mode.
  1113. */
  1114. function isPaused() {
  1115. return dom.wrapper.classList.contains( 'paused' );
  1116. }
  1117. /**
  1118. * Toggles the auto slide mode on and off.
  1119. *
  1120. * @param {Boolean} override Optional flag which sets the desired state.
  1121. * True means autoplay starts, false means it stops.
  1122. */
  1123. function toggleAutoSlide( override ) {
  1124. if( typeof override === 'boolean' ) {
  1125. override ? resumeAutoSlide() : pauseAutoSlide();
  1126. }
  1127. else {
  1128. autoSlidePaused ? resumeAutoSlide() : pauseAutoSlide();
  1129. }
  1130. }
  1131. /**
  1132. * Checks if the auto slide mode is currently on.
  1133. */
  1134. function isAutoSliding() {
  1135. return !!( autoSlide && !autoSlidePaused );
  1136. }
  1137. /**
  1138. * Steps from the current point in the presentation to the
  1139. * slide which matches the specified horizontal and vertical
  1140. * indices.
  1141. *
  1142. * @param {int} h Horizontal index of the target slide
  1143. * @param {int} v Vertical index of the target slide
  1144. * @param {int} f Optional index of a fragment within the
  1145. * target slide to activate
  1146. * @param {int} o Optional origin for use in multimaster environments
  1147. */
  1148. function slide( h, v, f, o ) {
  1149. // Remember where we were at before
  1150. previousSlide = currentSlide;
  1151. // Query all horizontal slides in the deck
  1152. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  1153. // If no vertical index is specified and the upcoming slide is a
  1154. // stack, resume at its previous vertical index
  1155. if( v === undefined ) {
  1156. v = getPreviousVerticalIndex( horizontalSlides[ h ] );
  1157. }
  1158. // If we were on a vertical stack, remember what vertical index
  1159. // it was on so we can resume at the same position when returning
  1160. if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
  1161. setPreviousVerticalIndex( previousSlide.parentNode, indexv );
  1162. }
  1163. // Remember the state before this slide
  1164. var stateBefore = state.concat();
  1165. // Reset the state array
  1166. state.length = 0;
  1167. var indexhBefore = indexh || 0,
  1168. indexvBefore = indexv || 0;
  1169. // Activate and transition to the new slide
  1170. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
  1171. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
  1172. // Update the visibility of slides now that the indices have changed
  1173. updateSlidesVisibility();
  1174. layout();
  1175. // Apply the new state
  1176. stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
  1177. // Check if this state existed on the previous slide. If it
  1178. // did, we will avoid adding it repeatedly
  1179. for( var j = 0; j < stateBefore.length; j++ ) {
  1180. if( stateBefore[j] === state[i] ) {
  1181. stateBefore.splice( j, 1 );
  1182. continue stateLoop;
  1183. }
  1184. }
  1185. document.documentElement.classList.add( state[i] );
  1186. // Dispatch custom event matching the state's name
  1187. dispatchEvent( state[i] );
  1188. }
  1189. // Clean up the remains of the previous state
  1190. while( stateBefore.length ) {
  1191. document.documentElement.classList.remove( stateBefore.pop() );
  1192. }
  1193. // If the overview is active, re-activate it to update positions
  1194. if( isOverview() ) {
  1195. activateOverview();
  1196. }
  1197. // Find the current horizontal slide and any possible vertical slides
  1198. // within it
  1199. var currentHorizontalSlide = horizontalSlides[ indexh ],
  1200. currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
  1201. // Store references to the previous and current slides
  1202. currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
  1203. // Show fragment, if specified
  1204. if( typeof f !== 'undefined' ) {
  1205. navigateFragment( f );
  1206. }
  1207. // Dispatch an event if the slide changed
  1208. var slideChanged = ( indexh !== indexhBefore || indexv !== indexvBefore );
  1209. if( slideChanged ) {
  1210. dispatchEvent( 'slidechanged', {
  1211. 'indexh': indexh,
  1212. 'indexv': indexv,
  1213. 'previousSlide': previousSlide,
  1214. 'currentSlide': currentSlide,
  1215. 'origin': o
  1216. } );
  1217. }
  1218. else {
  1219. // Ensure that the previous slide is never the same as the current
  1220. previousSlide = null;
  1221. }
  1222. // Solves an edge case where the previous slide maintains the
  1223. // 'present' class when navigating between adjacent vertical
  1224. // stacks
  1225. if( previousSlide ) {
  1226. previousSlide.classList.remove( 'present' );
  1227. // Reset all slides upon navigate to home
  1228. // Issue: #285
  1229. if ( document.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
  1230. // Launch async task
  1231. setTimeout( function () {
  1232. var slides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
  1233. for( i in slides ) {
  1234. if( slides[i] ) {
  1235. // Reset stack
  1236. setPreviousVerticalIndex( slides[i], 0 );
  1237. }
  1238. }
  1239. }, 0 );
  1240. }
  1241. }
  1242. // Handle embedded content
  1243. if( slideChanged ) {
  1244. stopEmbeddedContent( previousSlide );
  1245. startEmbeddedContent( currentSlide );
  1246. }
  1247. updateControls();
  1248. updateProgress();
  1249. updateBackground();
  1250. updateParallax();
  1251. updateSlideNumber();
  1252. // Update the URL hash
  1253. writeURL();
  1254. cueAutoSlide();
  1255. }
  1256. /**
  1257. * Syncs the presentation with the current DOM. Useful
  1258. * when new slides or control elements are added or when
  1259. * the configuration has changed.
  1260. */
  1261. function sync() {
  1262. // Subscribe to input
  1263. removeEventListeners();
  1264. addEventListeners();
  1265. // Force a layout to make sure the current config is accounted for
  1266. layout();
  1267. // Reflect the current autoSlide value
  1268. autoSlide = config.autoSlide;
  1269. // Start auto-sliding if it's enabled
  1270. cueAutoSlide();
  1271. // Re-create the slide backgrounds
  1272. createBackgrounds();
  1273. sortAllFragments();
  1274. updateControls();
  1275. updateProgress();
  1276. updateBackground( true );
  1277. updateSlideNumber();
  1278. }
  1279. /**
  1280. * Resets all vertical slides so that only the first
  1281. * is visible.
  1282. */
  1283. function resetVerticalSlides() {
  1284. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1285. horizontalSlides.forEach( function( horizontalSlide ) {
  1286. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1287. verticalSlides.forEach( function( verticalSlide, y ) {
  1288. if( y > 0 ) {
  1289. verticalSlide.classList.remove( 'present' );
  1290. verticalSlide.classList.remove( 'past' );
  1291. verticalSlide.classList.add( 'future' );
  1292. }
  1293. } );
  1294. } );
  1295. }
  1296. /**
  1297. * Sorts and formats all of fragments in the
  1298. * presentation.
  1299. */
  1300. function sortAllFragments() {
  1301. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1302. horizontalSlides.forEach( function( horizontalSlide ) {
  1303. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1304. verticalSlides.forEach( function( verticalSlide, y ) {
  1305. sortFragments( verticalSlide.querySelectorAll( '.fragment' ) );
  1306. } );
  1307. if( verticalSlides.length === 0 ) sortFragments( horizontalSlide.querySelectorAll( '.fragment' ) );
  1308. } );
  1309. }
  1310. /**
  1311. * Updates one dimension of slides by showing the slide
  1312. * with the specified index.
  1313. *
  1314. * @param {String} selector A CSS selector that will fetch
  1315. * the group of slides we are working with
  1316. * @param {Number} index The index of the slide that should be
  1317. * shown
  1318. *
  1319. * @return {Number} The index of the slide that is now shown,
  1320. * might differ from the passed in index if it was out of
  1321. * bounds.
  1322. */
  1323. function updateSlides( selector, index ) {
  1324. // Select all slides and convert the NodeList result to
  1325. // an array
  1326. var slides = toArray( document.querySelectorAll( selector ) ),
  1327. slidesLength = slides.length;
  1328. if( slidesLength ) {
  1329. // Should the index loop?
  1330. if( config.loop ) {
  1331. index %= slidesLength;
  1332. if( index < 0 ) {
  1333. index = slidesLength + index;
  1334. }
  1335. }
  1336. // Enforce max and minimum index bounds
  1337. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  1338. for( var i = 0; i < slidesLength; i++ ) {
  1339. var element = slides[i];
  1340. var reverse = config.rtl && !isVerticalSlide( element );
  1341. element.classList.remove( 'past' );
  1342. element.classList.remove( 'present' );
  1343. element.classList.remove( 'future' );
  1344. // http://www.w3.org/html/wg/drafts/html/master/editing.html#the-hidden-attribute
  1345. element.setAttribute( 'hidden', '' );
  1346. if( i < index ) {
  1347. // Any element previous to index is given the 'past' class
  1348. element.classList.add( reverse ? 'future' : 'past' );
  1349. if( config.fragments ) {
  1350. var pastFragments = toArray( element.querySelectorAll( '.fragment' ) );
  1351. // Show all fragments on prior slides
  1352. while( pastFragments.length ) {
  1353. var pastFragment = pastFragments.pop();
  1354. pastFragment.classList.add( 'visible' );
  1355. pastFragment.classList.remove( 'current-fragment' );
  1356. }
  1357. }
  1358. }
  1359. else if( i > index ) {
  1360. // Any element subsequent to index is given the 'future' class
  1361. element.classList.add( reverse ? 'past' : 'future' );
  1362. if( config.fragments ) {
  1363. var futureFragments = toArray( element.querySelectorAll( '.fragment.visible' ) );
  1364. // No fragments in future slides should be visible ahead of time
  1365. while( futureFragments.length ) {
  1366. var futureFragment = futureFragments.pop();
  1367. futureFragment.classList.remove( 'visible' );
  1368. futureFragment.classList.remove( 'current-fragment' );
  1369. }
  1370. }
  1371. }
  1372. // If this element contains vertical slides
  1373. if( element.querySelector( 'section' ) ) {
  1374. element.classList.add( 'stack' );
  1375. }
  1376. }
  1377. // Mark the current slide as present
  1378. slides[index].classList.add( 'present' );
  1379. slides[index].removeAttribute( 'hidden' );
  1380. // If this slide has a state associated with it, add it
  1381. // onto the current state of the deck
  1382. var slideState = slides[index].getAttribute( 'data-state' );
  1383. if( slideState ) {
  1384. state = state.concat( slideState.split( ' ' ) );
  1385. }
  1386. }
  1387. else {
  1388. // Since there are no slides we can't be anywhere beyond the
  1389. // zeroth index
  1390. index = 0;
  1391. }
  1392. return index;
  1393. }
  1394. /**
  1395. * Optimization method; hide all slides that are far away
  1396. * from the present slide.
  1397. */
  1398. function updateSlidesVisibility() {
  1399. // Select all slides and convert the NodeList result to
  1400. // an array
  1401. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ),
  1402. horizontalSlidesLength = horizontalSlides.length,
  1403. distanceX,
  1404. distanceY;
  1405. if( horizontalSlidesLength ) {
  1406. // The number of steps away from the present slide that will
  1407. // be visible
  1408. var viewDistance = isOverview() ? 10 : config.viewDistance;
  1409. // Limit view distance on weaker devices
  1410. if( isMobileDevice ) {
  1411. viewDistance = isOverview() ? 6 : 1;
  1412. }
  1413. for( var x = 0; x < horizontalSlidesLength; x++ ) {
  1414. var horizontalSlide = horizontalSlides[x];
  1415. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) ),
  1416. verticalSlidesLength = verticalSlides.length;
  1417. // Loops so that it measures 1 between the first and last slides
  1418. distanceX = Math.abs( ( indexh - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0;
  1419. // Show the horizontal slide if it's within the view distance
  1420. horizontalSlide.style.display = distanceX > viewDistance ? 'none' : 'block';
  1421. if( verticalSlidesLength ) {
  1422. var oy = getPreviousVerticalIndex( horizontalSlide );
  1423. for( var y = 0; y < verticalSlidesLength; y++ ) {
  1424. var verticalSlide = verticalSlides[y];
  1425. distanceY = x === indexh ? Math.abs( indexv - y ) : Math.abs( y - oy );
  1426. verticalSlide.style.display = ( distanceX + distanceY ) > viewDistance ? 'none' : 'block';
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. /**
  1433. * Updates the progress bar to reflect the current slide.
  1434. */
  1435. function updateProgress() {
  1436. // Update progress if enabled
  1437. if( config.progress && dom.progress ) {
  1438. dom.progressbar.style.width = getProgress() * window.innerWidth + 'px';
  1439. }
  1440. }
  1441. /**
  1442. * Updates the slide number div to reflect the current slide.
  1443. */
  1444. function updateSlideNumber() {
  1445. // Update slide number if enabled
  1446. if( config.slideNumber && dom.slideNumber) {
  1447. // Display the number of the page using 'indexh - indexv' format
  1448. var indexString = indexh;
  1449. if( indexv > 0 ) {
  1450. indexString += ' - ' + indexv;
  1451. }
  1452. dom.slideNumber.innerHTML = indexString;
  1453. }
  1454. }
  1455. /**
  1456. * Updates the state of all control/navigation arrows.
  1457. */
  1458. function updateControls() {
  1459. var routes = availableRoutes();
  1460. var fragments = availableFragments();
  1461. // Remove the 'enabled' class from all directions
  1462. dom.controlsLeft.concat( dom.controlsRight )
  1463. .concat( dom.controlsUp )
  1464. .concat( dom.controlsDown )
  1465. .concat( dom.controlsPrev )
  1466. .concat( dom.controlsNext ).forEach( function( node ) {
  1467. node.classList.remove( 'enabled' );
  1468. node.classList.remove( 'fragmented' );
  1469. } );
  1470. // Add the 'enabled' class to the available routes
  1471. if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1472. if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1473. if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1474. if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1475. // Prev/next buttons
  1476. if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1477. if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1478. // Highlight fragment directions
  1479. if( currentSlide ) {
  1480. // Always apply fragment decorator to prev/next buttons
  1481. if( fragments.prev ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1482. if( fragments.next ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1483. // Apply fragment decorators to directional buttons based on
  1484. // what slide axis they are in
  1485. if( isVerticalSlide( currentSlide ) ) {
  1486. if( fragments.prev ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1487. if( fragments.next ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1488. }
  1489. else {
  1490. if( fragments.prev ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1491. if( fragments.next ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1492. }
  1493. }
  1494. }
  1495. /**
  1496. * Updates the background elements to reflect the current
  1497. * slide.
  1498. *
  1499. * @param {Boolean} includeAll If true, the backgrounds of
  1500. * all vertical slides (not just the present) will be updated.
  1501. */
  1502. function updateBackground( includeAll ) {
  1503. var currentBackground = null;
  1504. // Reverse past/future classes when in RTL mode
  1505. var horizontalPast = config.rtl ? 'future' : 'past',
  1506. horizontalFuture = config.rtl ? 'past' : 'future';
  1507. // Update the classes of all backgrounds to match the
  1508. // states of their slides (past/present/future)
  1509. toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) {
  1510. if( h < indexh ) {
  1511. backgroundh.className = 'slide-background ' + horizontalPast;
  1512. }
  1513. else if ( h > indexh ) {
  1514. backgroundh.className = 'slide-background ' + horizontalFuture;
  1515. }
  1516. else {
  1517. backgroundh.className = 'slide-background present';
  1518. // Store a reference to the current background element
  1519. currentBackground = backgroundh;
  1520. }
  1521. if( includeAll || h === indexh ) {
  1522. toArray( backgroundh.childNodes ).forEach( function( backgroundv, v ) {
  1523. if( v < indexv ) {
  1524. backgroundv.className = 'slide-background past';
  1525. }
  1526. else if ( v > indexv ) {
  1527. backgroundv.className = 'slide-background future';
  1528. }
  1529. else {
  1530. backgroundv.className = 'slide-background present';
  1531. // Only if this is the present horizontal and vertical slide
  1532. if( h === indexh ) currentBackground = backgroundv;
  1533. }
  1534. } );
  1535. }
  1536. } );
  1537. // Don't transition between identical backgrounds. This
  1538. // prevents unwanted flicker.
  1539. if( currentBackground ) {
  1540. var previousBackgroundHash = previousBackground ? previousBackground.getAttribute( 'data-background-hash' ) : null;
  1541. var currentBackgroundHash = currentBackground.getAttribute( 'data-background-hash' );
  1542. if( currentBackgroundHash && currentBackgroundHash === previousBackgroundHash && currentBackground !== previousBackground ) {
  1543. dom.background.classList.add( 'no-transition' );
  1544. }
  1545. previousBackground = currentBackground;
  1546. }
  1547. // Allow the first background to apply without transition
  1548. setTimeout( function() {
  1549. dom.background.classList.remove( 'no-transition' );
  1550. }, 1 );
  1551. }
  1552. /**
  1553. * Updates the position of the parallax background based
  1554. * on the current slide index.
  1555. */
  1556. function updateParallax() {
  1557. if( config.parallaxBackgroundImage ) {
  1558. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1559. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1560. var backgroundSize = dom.background.style.backgroundSize.split( ' ' ),
  1561. backgroundWidth, backgroundHeight;
  1562. if( backgroundSize.length === 1 ) {
  1563. backgroundWidth = backgroundHeight = parseInt( backgroundSize[0], 10 );
  1564. }
  1565. else {
  1566. backgroundWidth = parseInt( backgroundSize[0], 10 );
  1567. backgroundHeight = parseInt( backgroundSize[1], 10 );
  1568. }
  1569. var slideWidth = dom.background.offsetWidth;
  1570. var horizontalSlideCount = horizontalSlides.length;
  1571. var horizontalOffset = -( backgroundWidth - slideWidth ) / ( horizontalSlideCount-1 ) * indexh;
  1572. var slideHeight = dom.background.offsetHeight;
  1573. var verticalSlideCount = verticalSlides.length;
  1574. var verticalOffset = verticalSlideCount > 1 ? -( backgroundHeight - slideHeight ) / ( verticalSlideCount-1 ) * indexv : 0;
  1575. dom.background.style.backgroundPosition = horizontalOffset + 'px ' + verticalOffset + 'px';
  1576. }
  1577. }
  1578. /**
  1579. * Determine what available routes there are for navigation.
  1580. *
  1581. * @return {Object} containing four booleans: left/right/up/down
  1582. */
  1583. function availableRoutes() {
  1584. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1585. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1586. var routes = {
  1587. left: indexh > 0 || config.loop,
  1588. right: indexh < horizontalSlides.length - 1 || config.loop,
  1589. up: indexv > 0,
  1590. down: indexv < verticalSlides.length - 1
  1591. };
  1592. // reverse horizontal controls for rtl
  1593. if( config.rtl ) {
  1594. var left = routes.left;
  1595. routes.left = routes.right;
  1596. routes.right = left;
  1597. }
  1598. return routes;
  1599. }
  1600. /**
  1601. * Returns an object describing the available fragment
  1602. * directions.
  1603. *
  1604. * @return {Object} two boolean properties: prev/next
  1605. */
  1606. function availableFragments() {
  1607. if( currentSlide && config.fragments ) {
  1608. var fragments = currentSlide.querySelectorAll( '.fragment' );
  1609. var hiddenFragments = currentSlide.querySelectorAll( '.fragment:not(.visible)' );
  1610. return {
  1611. prev: fragments.length - hiddenFragments.length > 0,
  1612. next: !!hiddenFragments.length
  1613. };
  1614. }
  1615. else {
  1616. return { prev: false, next: false };
  1617. }
  1618. }
  1619. /**
  1620. * Start playback of any embedded content inside of
  1621. * the targeted slide.
  1622. */
  1623. function startEmbeddedContent( slide ) {
  1624. if( slide && !isSpeakerNotes() ) {
  1625. // HTML5 media elements
  1626. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1627. if( el.hasAttribute( 'data-autoplay' ) ) {
  1628. el.play();
  1629. }
  1630. } );
  1631. // iframe embeds
  1632. toArray( slide.querySelectorAll( 'iframe' ) ).forEach( function( el ) {
  1633. el.contentWindow.postMessage( 'slide:start', '*' );
  1634. });
  1635. // YouTube embeds
  1636. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  1637. if( el.hasAttribute( 'data-autoplay' ) ) {
  1638. el.contentWindow.postMessage( '{"event":"command","func":"playVideo","args":""}', '*' );
  1639. }
  1640. });
  1641. }
  1642. }
  1643. /**
  1644. * Stop playback of any embedded content inside of
  1645. * the targeted slide.
  1646. */
  1647. function stopEmbeddedContent( slide ) {
  1648. if( slide ) {
  1649. // HTML5 media elements
  1650. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1651. if( !el.hasAttribute( 'data-ignore' ) ) {
  1652. el.pause();
  1653. }
  1654. } );
  1655. // iframe embeds
  1656. toArray( slide.querySelectorAll( 'iframe' ) ).forEach( function( el ) {
  1657. el.contentWindow.postMessage( 'slide:stop', '*' );
  1658. });
  1659. // YouTube embeds
  1660. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  1661. if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
  1662. el.contentWindow.postMessage( '{"event":"command","func":"pauseVideo","args":""}', '*' );
  1663. }
  1664. });
  1665. }
  1666. }
  1667. /**
  1668. * Returns a value ranging from 0-1 that represents
  1669. * how far into the presentation we have navigated.
  1670. */
  1671. function getProgress() {
  1672. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1673. // The number of past and total slides
  1674. var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  1675. var pastCount = 0;
  1676. // Step through all slides and count the past ones
  1677. mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
  1678. var horizontalSlide = horizontalSlides[i];
  1679. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1680. for( var j = 0; j < verticalSlides.length; j++ ) {
  1681. // Stop as soon as we arrive at the present
  1682. if( verticalSlides[j].classList.contains( 'present' ) ) {
  1683. break mainLoop;
  1684. }
  1685. pastCount++;
  1686. }
  1687. // Stop as soon as we arrive at the present
  1688. if( horizontalSlide.classList.contains( 'present' ) ) {
  1689. break;
  1690. }
  1691. // Don't count the wrapping section for vertical slides
  1692. if( horizontalSlide.classList.contains( 'stack' ) === false ) {
  1693. pastCount++;
  1694. }
  1695. }
  1696. if( currentSlide ) {
  1697. var allFragments = currentSlide.querySelectorAll( '.fragment' );
  1698. // If there are fragments in the current slide those should be
  1699. // accounted for in the progress.
  1700. if( allFragments.length > 0 ) {
  1701. var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
  1702. // This value represents how big a portion of the slide progress
  1703. // that is made up by its fragments (0-1)
  1704. var fragmentWeight = 0.9;
  1705. // Add fragment progress to the past slide count
  1706. pastCount += ( visibleFragments.length / allFragments.length ) * fragmentWeight;
  1707. }
  1708. }
  1709. return pastCount / ( totalCount - 1 );
  1710. }
  1711. /**
  1712. * Checks if this presentation is running inside of the
  1713. * speaker notes window.
  1714. */
  1715. function isSpeakerNotes() {
  1716. return !!window.location.search.match( /receiver/gi );
  1717. }
  1718. /**
  1719. * Reads the current URL (hash) and navigates accordingly.
  1720. */
  1721. function readURL() {
  1722. var hash = window.location.hash;
  1723. // Attempt to parse the hash as either an index or name
  1724. var bits = hash.slice( 2 ).split( '/' ),
  1725. name = hash.replace( /#|\//gi, '' );
  1726. // If the first bit is invalid and there is a name we can
  1727. // assume that this is a named link
  1728. if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
  1729. var element;
  1730. try {
  1731. // Find the slide with the specified name
  1732. element = document.querySelector( '#' + name );
  1733. }
  1734. catch( e ) {
  1735. // If the ID is an invalid selector a harmless SyntaxError
  1736. // may be thrown here.
  1737. }
  1738. if( element ) {
  1739. // Find the position of the named slide and navigate to it
  1740. var indices = Reveal.getIndices( element );
  1741. slide( indices.h, indices.v );
  1742. }
  1743. // If the slide doesn't exist, navigate to the current slide
  1744. else {
  1745. slide( indexh || 0, indexv || 0 );
  1746. }
  1747. }
  1748. else {
  1749. // Read the index components of the hash
  1750. var h = parseInt( bits[0], 10 ) || 0,
  1751. v = parseInt( bits[1], 10 ) || 0;
  1752. if( h !== indexh || v !== indexv ) {
  1753. slide( h, v );
  1754. }
  1755. }
  1756. }
  1757. /**
  1758. * Updates the page URL (hash) to reflect the current
  1759. * state.
  1760. *
  1761. * @param {Number} delay The time in ms to wait before
  1762. * writing the hash
  1763. */
  1764. function writeURL( delay ) {
  1765. if( config.history ) {
  1766. // Make sure there's never more than one timeout running
  1767. clearTimeout( writeURLTimeout );
  1768. // If a delay is specified, timeout this call
  1769. if( typeof delay === 'number' ) {
  1770. writeURLTimeout = setTimeout( writeURL, delay );
  1771. }
  1772. else {
  1773. var url = '/';
  1774. // Attempt to create a named link based on the slide's ID
  1775. var id = currentSlide.getAttribute( 'id' );
  1776. if( id ) {
  1777. id = id.toLowerCase();
  1778. id = id.replace( /[^a-zA-Z0-9\-\_\:\.]/g, '' );
  1779. }
  1780. // If the current slide has an ID, use that as a named link
  1781. if( currentSlide && typeof id === 'string' && id.length ) {
  1782. url = '/' + id;
  1783. }
  1784. // Otherwise use the /h/v index
  1785. else {
  1786. if( indexh > 0 || indexv > 0 ) url += indexh;
  1787. if( indexv > 0 ) url += '/' + indexv;
  1788. }
  1789. window.location.hash = url;
  1790. }
  1791. }
  1792. }
  1793. /**
  1794. * Retrieves the h/v location of the current, or specified,
  1795. * slide.
  1796. *
  1797. * @param {HTMLElement} slide If specified, the returned
  1798. * index will be for this slide rather than the currently
  1799. * active one
  1800. *
  1801. * @return {Object} { h: <int>, v: <int>, f: <int> }
  1802. */
  1803. function getIndices( slide ) {
  1804. // By default, return the current indices
  1805. var h = indexh,
  1806. v = indexv,
  1807. f;
  1808. // If a slide is specified, return the indices of that slide
  1809. if( slide ) {
  1810. var isVertical = isVerticalSlide( slide );
  1811. var slideh = isVertical ? slide.parentNode : slide;
  1812. // Select all horizontal slides
  1813. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1814. // Now that we know which the horizontal slide is, get its index
  1815. h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
  1816. // If this is a vertical slide, grab the vertical index
  1817. if( isVertical ) {
  1818. v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
  1819. }
  1820. }
  1821. if( !slide && currentSlide ) {
  1822. var hasFragments = currentSlide.querySelectorAll( '.fragment' ).length > 0;
  1823. if( hasFragments ) {
  1824. var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
  1825. f = visibleFragments.length - 1;
  1826. }
  1827. }
  1828. return { h: h, v: v, f: f };
  1829. }
  1830. /**
  1831. * Retrieves the total number of slides in this presentation.
  1832. */
  1833. function getTotalSlides() {
  1834. return document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  1835. }
  1836. /**
  1837. * Retrieves the current state of the presentation as
  1838. * an object. This state can then be restored at any
  1839. * time.
  1840. */
  1841. function getState() {
  1842. var indices = getIndices();
  1843. return {
  1844. indexh: indices.h,
  1845. indexv: indices.v,
  1846. indexf: indices.f,
  1847. paused: isPaused(),
  1848. overview: isOverview()
  1849. };
  1850. }
  1851. /**
  1852. * Restores the presentation to the given state.
  1853. *
  1854. * @param {Object} state As generated by getState()
  1855. */
  1856. function setState( state ) {
  1857. if( typeof state === 'object' ) {
  1858. slide( deserialize( state.indexh ), deserialize( state.indexv ), deserialize( state.indexf ) );
  1859. togglePause( deserialize( state.paused ) );
  1860. toggleOverview( deserialize( state.overview ) );
  1861. }
  1862. }
  1863. /**
  1864. * Return a sorted fragments list, ordered by an increasing
  1865. * "data-fragment-index" attribute.
  1866. *
  1867. * Fragments will be revealed in the order that they are returned by
  1868. * this function, so you can use the index attributes to control the
  1869. * order of fragment appearance.
  1870. *
  1871. * To maintain a sensible default fragment order, fragments are presumed
  1872. * to be passed in document order. This function adds a "fragment-index"
  1873. * attribute to each node if such an attribute is not already present,
  1874. * and sets that attribute to an integer value which is the position of
  1875. * the fragment within the fragments list.
  1876. */
  1877. function sortFragments( fragments ) {
  1878. fragments = toArray( fragments );
  1879. var ordered = [],
  1880. unordered = [],
  1881. sorted = [];
  1882. // Group ordered and unordered elements
  1883. fragments.forEach( function( fragment, i ) {
  1884. if( fragment.hasAttribute( 'data-fragment-index' ) ) {
  1885. var index = parseInt( fragment.getAttribute( 'data-fragment-index' ), 10 );
  1886. if( !ordered[index] ) {
  1887. ordered[index] = [];
  1888. }
  1889. ordered[index].push( fragment );
  1890. }
  1891. else {
  1892. unordered.push( [ fragment ] );
  1893. }
  1894. } );
  1895. // Append fragments without explicit indices in their
  1896. // DOM order
  1897. ordered = ordered.concat( unordered );
  1898. // Manually count the index up per group to ensure there
  1899. // are no gaps
  1900. var index = 0;
  1901. // Push all fragments in their sorted order to an array,
  1902. // this flattens the groups
  1903. ordered.forEach( function( group ) {
  1904. group.forEach( function( fragment ) {
  1905. sorted.push( fragment );
  1906. fragment.setAttribute( 'data-fragment-index', index );
  1907. } );
  1908. index ++;
  1909. } );
  1910. return sorted;
  1911. }
  1912. /**
  1913. * Navigate to the specified slide fragment.
  1914. *
  1915. * @param {Number} index The index of the fragment that
  1916. * should be shown, -1 means all are invisible
  1917. * @param {Number} offset Integer offset to apply to the
  1918. * fragment index
  1919. *
  1920. * @return {Boolean} true if a change was made in any
  1921. * fragments visibility as part of this call
  1922. */
  1923. function navigateFragment( index, offset ) {
  1924. if( currentSlide && config.fragments ) {
  1925. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
  1926. if( fragments.length ) {
  1927. // If no index is specified, find the current
  1928. if( typeof index !== 'number' ) {
  1929. var lastVisibleFragment = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) ).pop();
  1930. if( lastVisibleFragment ) {
  1931. index = parseInt( lastVisibleFragment.getAttribute( 'data-fragment-index' ) || 0, 10 );
  1932. }
  1933. else {
  1934. index = -1;
  1935. }
  1936. }
  1937. // If an offset is specified, apply it to the index
  1938. if( typeof offset === 'number' ) {
  1939. index += offset;
  1940. }
  1941. var fragmentsShown = [],
  1942. fragmentsHidden = [];
  1943. toArray( fragments ).forEach( function( element, i ) {
  1944. if( element.hasAttribute( 'data-fragment-index' ) ) {
  1945. i = parseInt( element.getAttribute( 'data-fragment-index' ), 10 );
  1946. }
  1947. // Visible fragments
  1948. if( i <= index ) {
  1949. if( !element.classList.contains( 'visible' ) ) fragmentsShown.push( element );
  1950. element.classList.add( 'visible' );
  1951. element.classList.remove( 'current-fragment' );
  1952. if( i === index ) {
  1953. element.classList.add( 'current-fragment' );
  1954. }
  1955. }
  1956. // Hidden fragments
  1957. else {
  1958. if( element.classList.contains( 'visible' ) ) fragmentsHidden.push( element );
  1959. element.classList.remove( 'visible' );
  1960. element.classList.remove( 'current-fragment' );
  1961. }
  1962. } );
  1963. if( fragmentsHidden.length ) {
  1964. dispatchEvent( 'fragmenthidden', { fragment: fragmentsHidden[0], fragments: fragmentsHidden } );
  1965. }
  1966. if( fragmentsShown.length ) {
  1967. dispatchEvent( 'fragmentshown', { fragment: fragmentsShown[0], fragments: fragmentsShown } );
  1968. }
  1969. updateControls();
  1970. updateProgress();
  1971. return !!( fragmentsShown.length || fragmentsHidden.length );
  1972. }
  1973. }
  1974. return false;
  1975. }
  1976. /**
  1977. * Navigate to the next slide fragment.
  1978. *
  1979. * @return {Boolean} true if there was a next fragment,
  1980. * false otherwise
  1981. */
  1982. function nextFragment() {
  1983. return navigateFragment( null, 1 );
  1984. }
  1985. /**
  1986. * Navigate to the previous slide fragment.
  1987. *
  1988. * @return {Boolean} true if there was a previous fragment,
  1989. * false otherwise
  1990. */
  1991. function previousFragment() {
  1992. return navigateFragment( null, -1 );
  1993. }
  1994. /**
  1995. * Cues a new automated slide if enabled in the config.
  1996. */
  1997. function cueAutoSlide() {
  1998. cancelAutoSlide();
  1999. if( currentSlide ) {
  2000. var currentFragment = currentSlide.querySelector( '.current-fragment' );
  2001. var fragmentAutoSlide = currentFragment ? currentFragment.getAttribute( 'data-autoslide' ) : null;
  2002. var parentAutoSlide = currentSlide.parentNode ? currentSlide.parentNode.getAttribute( 'data-autoslide' ) : null;
  2003. var slideAutoSlide = currentSlide.getAttribute( 'data-autoslide' );
  2004. // Pick value in the following priority order:
  2005. // 1. Current fragment's data-autoslide
  2006. // 2. Current slide's data-autoslide
  2007. // 3. Parent slide's data-autoslide
  2008. // 4. Global autoSlide setting
  2009. if( fragmentAutoSlide ) {
  2010. autoSlide = parseInt( fragmentAutoSlide, 10 );
  2011. }
  2012. else if( slideAutoSlide ) {
  2013. autoSlide = parseInt( slideAutoSlide, 10 );
  2014. }
  2015. else if( parentAutoSlide ) {
  2016. autoSlide = parseInt( parentAutoSlide, 10 );
  2017. }
  2018. else {
  2019. autoSlide = config.autoSlide;
  2020. }
  2021. // If there are media elements with data-autoplay,
  2022. // automatically set the autoSlide duration to the
  2023. // length of that media
  2024. toArray( currentSlide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  2025. if( el.hasAttribute( 'data-autoplay' ) ) {
  2026. if( autoSlide && el.duration * 1000 > autoSlide ) {
  2027. autoSlide = ( el.duration * 1000 ) + 1000;
  2028. }
  2029. }
  2030. } );
  2031. // Cue the next auto-slide if:
  2032. // - There is an autoSlide value
  2033. // - Auto-sliding isn't paused by the user
  2034. // - The presentation isn't paused
  2035. // - The overview isn't active
  2036. // - The presentation isn't over
  2037. if( autoSlide && !autoSlidePaused && !isPaused() && !isOverview() && ( !Reveal.isLastSlide() || config.loop === true ) ) {
  2038. autoSlideTimeout = setTimeout( navigateNext, autoSlide );
  2039. autoSlideStartTime = Date.now();
  2040. }
  2041. if( autoSlidePlayer ) {
  2042. autoSlidePlayer.setPlaying( autoSlideTimeout !== -1 );
  2043. }
  2044. }
  2045. }
  2046. /**
  2047. * Cancels any ongoing request to auto-slide.
  2048. */
  2049. function cancelAutoSlide() {
  2050. clearTimeout( autoSlideTimeout );
  2051. autoSlideTimeout = -1;
  2052. }
  2053. function pauseAutoSlide() {
  2054. autoSlidePaused = true;
  2055. dispatchEvent( 'autoslidepaused' );
  2056. clearTimeout( autoSlideTimeout );
  2057. if( autoSlidePlayer ) {
  2058. autoSlidePlayer.setPlaying( false );
  2059. }
  2060. }
  2061. function resumeAutoSlide() {
  2062. autoSlidePaused = false;
  2063. dispatchEvent( 'autoslideresumed' );
  2064. cueAutoSlide();
  2065. }
  2066. function navigateLeft() {
  2067. // Reverse for RTL
  2068. if( config.rtl ) {
  2069. if( ( isOverview() || nextFragment() === false ) && availableRoutes().left ) {
  2070. slide( indexh + 1 );
  2071. }
  2072. }
  2073. // Normal navigation
  2074. else if( ( isOverview() || previousFragment() === false ) && availableRoutes().left ) {
  2075. slide( indexh - 1 );
  2076. }
  2077. }
  2078. function navigateRight() {
  2079. // Reverse for RTL
  2080. if( config.rtl ) {
  2081. if( ( isOverview() || previousFragment() === false ) && availableRoutes().right ) {
  2082. slide( indexh - 1 );
  2083. }
  2084. }
  2085. // Normal navigation
  2086. else if( ( isOverview() || nextFragment() === false ) && availableRoutes().right ) {
  2087. slide( indexh + 1 );
  2088. }
  2089. }
  2090. function navigateUp() {
  2091. // Prioritize hiding fragments
  2092. if( ( isOverview() || previousFragment() === false ) && availableRoutes().up ) {
  2093. slide( indexh, indexv - 1 );
  2094. }
  2095. }
  2096. function navigateDown() {
  2097. // Prioritize revealing fragments
  2098. if( ( isOverview() || nextFragment() === false ) && availableRoutes().down ) {
  2099. slide( indexh, indexv + 1 );
  2100. }
  2101. }
  2102. /**
  2103. * Navigates backwards, prioritized in the following order:
  2104. * 1) Previous fragment
  2105. * 2) Previous vertical slide
  2106. * 3) Previous horizontal slide
  2107. */
  2108. function navigatePrev() {
  2109. // Prioritize revealing fragments
  2110. if( previousFragment() === false ) {
  2111. if( availableRoutes().up ) {
  2112. navigateUp();
  2113. }
  2114. else {
  2115. // Fetch the previous horizontal slide, if there is one
  2116. var previousSlide = document.querySelector( HORIZONTAL_SLIDES_SELECTOR + '.past:nth-child(' + indexh + ')' );
  2117. if( previousSlide ) {
  2118. var v = ( previousSlide.querySelectorAll( 'section' ).length - 1 ) || undefined;
  2119. var h = indexh - 1;
  2120. slide( h, v );
  2121. }
  2122. }
  2123. }
  2124. }
  2125. /**
  2126. * Same as #navigatePrev() but navigates forwards.
  2127. */
  2128. function navigateNext() {
  2129. // Prioritize revealing fragments
  2130. if( nextFragment() === false ) {
  2131. availableRoutes().down ? navigateDown() : navigateRight();
  2132. }
  2133. // If auto-sliding is enabled we need to cue up
  2134. // another timeout
  2135. cueAutoSlide();
  2136. }
  2137. // --------------------------------------------------------------------//
  2138. // ----------------------------- EVENTS -------------------------------//
  2139. // --------------------------------------------------------------------//
  2140. /**
  2141. * Called by all event handlers that are based on user
  2142. * input.
  2143. */
  2144. function onUserInput( event ) {
  2145. if( config.autoSlideStoppable ) {
  2146. pauseAutoSlide();
  2147. }
  2148. }
  2149. /**
  2150. * Handler for the document level 'keydown' event.
  2151. */
  2152. function onDocumentKeyDown( event ) {
  2153. // Remember if auto-sliding was paused so we can toggle it
  2154. var autoSlideWasPaused = autoSlidePaused;
  2155. onUserInput( event );
  2156. // Check if there's a focused element that could be using
  2157. // the keyboard
  2158. var activeElement = document.activeElement;
  2159. var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) );
  2160. // Disregard the event if there's a focused element or a
  2161. // keyboard modifier key is present
  2162. if( hasFocus || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
  2163. // While paused only allow "unpausing" keyboard events (b and .)
  2164. if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) {
  2165. return false;
  2166. }
  2167. var triggered = false;
  2168. // 1. User defined key bindings
  2169. if( typeof config.keyboard === 'object' ) {
  2170. for( var key in config.keyboard ) {
  2171. // Check if this binding matches the pressed key
  2172. if( parseInt( key, 10 ) === event.keyCode ) {
  2173. var value = config.keyboard[ key ];
  2174. // Callback function
  2175. if( typeof value === 'function' ) {
  2176. value.apply( null, [ event ] );
  2177. }
  2178. // String shortcuts to reveal.js API
  2179. else if( typeof value === 'string' && typeof Reveal[ value ] === 'function' ) {
  2180. Reveal[ value ].call();
  2181. }
  2182. triggered = true;
  2183. }
  2184. }
  2185. }
  2186. // 2. System defined key bindings
  2187. if( triggered === false ) {
  2188. // Assume true and try to prove false
  2189. triggered = true;
  2190. switch( event.keyCode ) {
  2191. // p, page up
  2192. case 80: case 33: navigatePrev(); break;
  2193. // n, page down
  2194. case 78: case 34: navigateNext(); break;
  2195. // h, left
  2196. case 72: case 37: navigateLeft(); break;
  2197. // l, right
  2198. case 76: case 39: navigateRight(); break;
  2199. // k, up
  2200. case 75: case 38: navigateUp(); break;
  2201. // j, down
  2202. case 74: case 40: navigateDown(); break;
  2203. // home
  2204. case 36: slide( 0 ); break;
  2205. // end
  2206. case 35: slide( Number.MAX_VALUE ); break;
  2207. // space
  2208. case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
  2209. // return
  2210. case 13: isOverview() ? deactivateOverview() : triggered = false; break;
  2211. // two-spot, semicolon, b, period, Logitech presenter tools "black screen" button
  2212. case 58: case 59: case 66: case 190: case 191: togglePause(); break;
  2213. // f
  2214. case 70: enterFullscreen(); break;
  2215. // a
  2216. case 65: if ( config.autoSlideStoppable ) toggleAutoSlide( autoSlideWasPaused ); break;
  2217. default:
  2218. triggered = false;
  2219. }
  2220. }
  2221. // If the input resulted in a triggered action we should prevent
  2222. // the browsers default behavior
  2223. if( triggered ) {
  2224. event.preventDefault();
  2225. }
  2226. // ESC or O key
  2227. else if ( ( event.keyCode === 27 || event.keyCode === 79 ) && features.transforms3d ) {
  2228. if( dom.preview ) {
  2229. closePreview();
  2230. }
  2231. else {
  2232. toggleOverview();
  2233. }
  2234. event.preventDefault();
  2235. }
  2236. // If auto-sliding is enabled we need to cue up
  2237. // another timeout
  2238. cueAutoSlide();
  2239. }
  2240. /**
  2241. * Handler for the 'touchstart' event, enables support for
  2242. * swipe and pinch gestures.
  2243. */
  2244. function onTouchStart( event ) {
  2245. touch.startX = event.touches[0].clientX;
  2246. touch.startY = event.touches[0].clientY;
  2247. touch.startCount = event.touches.length;
  2248. // If there's two touches we need to memorize the distance
  2249. // between those two points to detect pinching
  2250. if( event.touches.length === 2 && config.overview ) {
  2251. touch.startSpan = distanceBetween( {
  2252. x: event.touches[1].clientX,
  2253. y: event.touches[1].clientY
  2254. }, {
  2255. x: touch.startX,
  2256. y: touch.startY
  2257. } );
  2258. }
  2259. }
  2260. /**
  2261. * Handler for the 'touchmove' event.
  2262. */
  2263. function onTouchMove( event ) {
  2264. // Each touch should only trigger one action
  2265. if( !touch.captured ) {
  2266. onUserInput( event );
  2267. var currentX = event.touches[0].clientX;
  2268. var currentY = event.touches[0].clientY;
  2269. // If the touch started with two points and still has
  2270. // two active touches; test for the pinch gesture
  2271. if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
  2272. // The current distance in pixels between the two touch points
  2273. var currentSpan = distanceBetween( {
  2274. x: event.touches[1].clientX,
  2275. y: event.touches[1].clientY
  2276. }, {
  2277. x: touch.startX,
  2278. y: touch.startY
  2279. } );
  2280. // If the span is larger than the desire amount we've got
  2281. // ourselves a pinch
  2282. if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
  2283. touch.captured = true;
  2284. if( currentSpan < touch.startSpan ) {
  2285. activateOverview();
  2286. }
  2287. else {
  2288. deactivateOverview();
  2289. }
  2290. }
  2291. event.preventDefault();
  2292. }
  2293. // There was only one touch point, look for a swipe
  2294. else if( event.touches.length === 1 && touch.startCount !== 2 ) {
  2295. var deltaX = currentX - touch.startX,
  2296. deltaY = currentY - touch.startY;
  2297. if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  2298. touch.captured = true;
  2299. navigateLeft();
  2300. }
  2301. else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  2302. touch.captured = true;
  2303. navigateRight();
  2304. }
  2305. else if( deltaY > touch.threshold ) {
  2306. touch.captured = true;
  2307. navigateUp();
  2308. }
  2309. else if( deltaY < -touch.threshold ) {
  2310. touch.captured = true;
  2311. navigateDown();
  2312. }
  2313. // If we're embedded, only block touch events if they have
  2314. // triggered an action
  2315. if( config.embedded ) {
  2316. if( touch.captured || isVerticalSlide( currentSlide ) ) {
  2317. event.preventDefault();
  2318. }
  2319. }
  2320. // Not embedded? Block them all to avoid needless tossing
  2321. // around of the viewport in iOS
  2322. else {
  2323. event.preventDefault();
  2324. }
  2325. }
  2326. }
  2327. // There's a bug with swiping on some Android devices unless
  2328. // the default action is always prevented
  2329. else if( navigator.userAgent.match( /android/gi ) ) {
  2330. event.preventDefault();
  2331. }
  2332. }
  2333. /**
  2334. * Handler for the 'touchend' event.
  2335. */
  2336. function onTouchEnd( event ) {
  2337. touch.captured = false;
  2338. }
  2339. /**
  2340. * Convert pointer down to touch start.
  2341. */
  2342. function onPointerDown( event ) {
  2343. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  2344. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  2345. onTouchStart( event );
  2346. }
  2347. }
  2348. /**
  2349. * Convert pointer move to touch move.
  2350. */
  2351. function onPointerMove( event ) {
  2352. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  2353. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  2354. onTouchMove( event );
  2355. }
  2356. }
  2357. /**
  2358. * Convert pointer up to touch end.
  2359. */
  2360. function onPointerUp( event ) {
  2361. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  2362. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  2363. onTouchEnd( event );
  2364. }
  2365. }
  2366. /**
  2367. * Handles mouse wheel scrolling, throttled to avoid skipping
  2368. * multiple slides.
  2369. */
  2370. function onDocumentMouseScroll( event ) {
  2371. if( Date.now() - lastMouseWheelStep > 600 ) {
  2372. lastMouseWheelStep = Date.now();
  2373. var delta = event.detail || -event.wheelDelta;
  2374. if( delta > 0 ) {
  2375. navigateNext();
  2376. }
  2377. else {
  2378. navigatePrev();
  2379. }
  2380. }
  2381. }
  2382. /**
  2383. * Clicking on the progress bar results in a navigation to the
  2384. * closest approximate horizontal slide using this equation:
  2385. *
  2386. * ( clickX / presentationWidth ) * numberOfSlides
  2387. */
  2388. function onProgressClicked( event ) {
  2389. onUserInput( event );
  2390. event.preventDefault();
  2391. var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
  2392. var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
  2393. slide( slideIndex );
  2394. }
  2395. /**
  2396. * Event handler for navigation control buttons.
  2397. */
  2398. function onNavigateLeftClicked( event ) { event.preventDefault(); onUserInput(); navigateLeft(); }
  2399. function onNavigateRightClicked( event ) { event.preventDefault(); onUserInput(); navigateRight(); }
  2400. function onNavigateUpClicked( event ) { event.preventDefault(); onUserInput(); navigateUp(); }
  2401. function onNavigateDownClicked( event ) { event.preventDefault(); onUserInput(); navigateDown(); }
  2402. function onNavigatePrevClicked( event ) { event.preventDefault(); onUserInput(); navigatePrev(); }
  2403. function onNavigateNextClicked( event ) { event.preventDefault(); onUserInput(); navigateNext(); }
  2404. /**
  2405. * Handler for the window level 'hashchange' event.
  2406. */
  2407. function onWindowHashChange( event ) {
  2408. readURL();
  2409. }
  2410. /**
  2411. * Handler for the window level 'resize' event.
  2412. */
  2413. function onWindowResize( event ) {
  2414. layout();
  2415. }
  2416. /**
  2417. * Handle for the window level 'visibilitychange' event.
  2418. */
  2419. function onPageVisibilityChange( event ) {
  2420. var isHidden = document.webkitHidden ||
  2421. document.msHidden ||
  2422. document.hidden;
  2423. // If, after clicking a link or similar and we're coming back,
  2424. // focus the document.body to ensure we can use keyboard shortcuts
  2425. if( isHidden === false && document.activeElement !== document.body ) {
  2426. document.activeElement.blur();
  2427. document.body.focus();
  2428. }
  2429. }
  2430. /**
  2431. * Invoked when a slide is and we're in the overview.
  2432. */
  2433. function onOverviewSlideClicked( event ) {
  2434. // TODO There's a bug here where the event listeners are not
  2435. // removed after deactivating the overview.
  2436. if( eventsAreBound && isOverview() ) {
  2437. event.preventDefault();
  2438. var element = event.target;
  2439. while( element && !element.nodeName.match( /section/gi ) ) {
  2440. element = element.parentNode;
  2441. }
  2442. if( element && !element.classList.contains( 'disabled' ) ) {
  2443. deactivateOverview();
  2444. if( element.nodeName.match( /section/gi ) ) {
  2445. var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
  2446. v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
  2447. slide( h, v );
  2448. }
  2449. }
  2450. }
  2451. }
  2452. /**
  2453. * Handles clicks on links that are set to preview in the
  2454. * iframe overlay.
  2455. */
  2456. function onPreviewLinkClicked( event ) {
  2457. var url = event.target.getAttribute( 'href' );
  2458. if( url ) {
  2459. openPreview( url );
  2460. event.preventDefault();
  2461. }
  2462. }
  2463. /**
  2464. * Handles click on the auto-sliding controls element.
  2465. */
  2466. function onAutoSlidePlayerClick( event ) {
  2467. // Replay
  2468. if( Reveal.isLastSlide() && config.loop === false ) {
  2469. slide( 0, 0 );
  2470. resumeAutoSlide();
  2471. }
  2472. // Resume
  2473. else if( autoSlidePaused ) {
  2474. resumeAutoSlide();
  2475. }
  2476. // Pause
  2477. else {
  2478. pauseAutoSlide();
  2479. }
  2480. }
  2481. // --------------------------------------------------------------------//
  2482. // ------------------------ PLAYBACK COMPONENT ------------------------//
  2483. // --------------------------------------------------------------------//
  2484. /**
  2485. * Constructor for the playback component, which displays
  2486. * play/pause/progress controls.
  2487. *
  2488. * @param {HTMLElement} container The component will append
  2489. * itself to this
  2490. * @param {Function} progressCheck A method which will be
  2491. * called frequently to get the current progress on a range
  2492. * of 0-1
  2493. */
  2494. function Playback( container, progressCheck ) {
  2495. // Cosmetics
  2496. this.diameter = 50;
  2497. this.thickness = 3;
  2498. // Flags if we are currently playing
  2499. this.playing = false;
  2500. // Current progress on a 0-1 range
  2501. this.progress = 0;
  2502. // Used to loop the animation smoothly
  2503. this.progressOffset = 1;
  2504. this.container = container;
  2505. this.progressCheck = progressCheck;
  2506. this.canvas = document.createElement( 'canvas' );
  2507. this.canvas.className = 'playback';
  2508. this.canvas.width = this.diameter;
  2509. this.canvas.height = this.diameter;
  2510. this.context = this.canvas.getContext( '2d' );
  2511. this.container.appendChild( this.canvas );
  2512. this.render();
  2513. }
  2514. Playback.prototype.setPlaying = function( value ) {
  2515. var wasPlaying = this.playing;
  2516. this.playing = value;
  2517. // Start repainting if we weren't already
  2518. if( !wasPlaying && this.playing ) {
  2519. this.animate();
  2520. }
  2521. else {
  2522. this.render();
  2523. }
  2524. };
  2525. Playback.prototype.animate = function() {
  2526. var progressBefore = this.progress;
  2527. this.progress = this.progressCheck();
  2528. // When we loop, offset the progress so that it eases
  2529. // smoothly rather than immediately resetting
  2530. if( progressBefore > 0.8 && this.progress < 0.2 ) {
  2531. this.progressOffset = this.progress;
  2532. }
  2533. this.render();
  2534. if( this.playing ) {
  2535. features.requestAnimationFrameMethod.call( window, this.animate.bind( this ) );
  2536. }
  2537. };
  2538. /**
  2539. * Renders the current progress and playback state.
  2540. */
  2541. Playback.prototype.render = function() {
  2542. var progress = this.playing ? this.progress : 0,
  2543. radius = ( this.diameter / 2 ) - this.thickness,
  2544. x = this.diameter / 2,
  2545. y = this.diameter / 2,
  2546. iconSize = 14;
  2547. // Ease towards 1
  2548. this.progressOffset += ( 1 - this.progressOffset ) * 0.1;
  2549. var endAngle = ( - Math.PI / 2 ) + ( progress * ( Math.PI * 2 ) );
  2550. var startAngle = ( - Math.PI / 2 ) + ( this.progressOffset * ( Math.PI * 2 ) );
  2551. this.context.save();
  2552. this.context.clearRect( 0, 0, this.diameter, this.diameter );
  2553. // Solid background color
  2554. this.context.beginPath();
  2555. this.context.arc( x, y, radius + 2, 0, Math.PI * 2, false );
  2556. this.context.fillStyle = 'rgba( 0, 0, 0, 0.4 )';
  2557. this.context.fill();
  2558. // Draw progress track
  2559. this.context.beginPath();
  2560. this.context.arc( x, y, radius, 0, Math.PI * 2, false );
  2561. this.context.lineWidth = this.thickness;
  2562. this.context.strokeStyle = '#666';
  2563. this.context.stroke();
  2564. if( this.playing ) {
  2565. // Draw progress on top of track
  2566. this.context.beginPath();
  2567. this.context.arc( x, y, radius, startAngle, endAngle, false );
  2568. this.context.lineWidth = this.thickness;
  2569. this.context.strokeStyle = '#fff';
  2570. this.context.stroke();
  2571. }
  2572. this.context.translate( x - ( iconSize / 2 ), y - ( iconSize / 2 ) );
  2573. // Draw play/pause icons
  2574. if( this.playing ) {
  2575. this.context.fillStyle = '#fff';
  2576. this.context.fillRect( 0, 0, iconSize / 2 - 2, iconSize );
  2577. this.context.fillRect( iconSize / 2 + 2, 0, iconSize / 2 - 2, iconSize );
  2578. }
  2579. else {
  2580. this.context.beginPath();
  2581. this.context.translate( 2, 0 );
  2582. this.context.moveTo( 0, 0 );
  2583. this.context.lineTo( iconSize - 2, iconSize / 2 );
  2584. this.context.lineTo( 0, iconSize );
  2585. this.context.fillStyle = '#fff';
  2586. this.context.fill();
  2587. }
  2588. this.context.restore();
  2589. };
  2590. Playback.prototype.on = function( type, listener ) {
  2591. this.canvas.addEventListener( type, listener, false );
  2592. };
  2593. Playback.prototype.off = function( type, listener ) {
  2594. this.canvas.removeEventListener( type, listener, false );
  2595. };
  2596. Playback.prototype.destroy = function() {
  2597. this.playing = false;
  2598. if( this.canvas.parentNode ) {
  2599. this.container.removeChild( this.canvas );
  2600. }
  2601. };
  2602. // --------------------------------------------------------------------//
  2603. // ------------------------------- API --------------------------------//
  2604. // --------------------------------------------------------------------//
  2605. return {
  2606. initialize: initialize,
  2607. configure: configure,
  2608. sync: sync,
  2609. // Navigation methods
  2610. slide: slide,
  2611. left: navigateLeft,
  2612. right: navigateRight,
  2613. up: navigateUp,
  2614. down: navigateDown,
  2615. prev: navigatePrev,
  2616. next: navigateNext,
  2617. // Fragment methods
  2618. navigateFragment: navigateFragment,
  2619. prevFragment: previousFragment,
  2620. nextFragment: nextFragment,
  2621. // Deprecated aliases
  2622. navigateTo: slide,
  2623. navigateLeft: navigateLeft,
  2624. navigateRight: navigateRight,
  2625. navigateUp: navigateUp,
  2626. navigateDown: navigateDown,
  2627. navigatePrev: navigatePrev,
  2628. navigateNext: navigateNext,
  2629. // Forces an update in slide layout
  2630. layout: layout,
  2631. // Returns an object with the available routes as booleans (left/right/top/bottom)
  2632. availableRoutes: availableRoutes,
  2633. // Returns an object with the available fragments as booleans (prev/next)
  2634. availableFragments: availableFragments,
  2635. // Toggles the overview mode on/off
  2636. toggleOverview: toggleOverview,
  2637. // Toggles the "black screen" mode on/off
  2638. togglePause: togglePause,
  2639. // Toggles the auto slide mode on/off
  2640. toggleAutoSlide: toggleAutoSlide,
  2641. // State checks
  2642. isOverview: isOverview,
  2643. isPaused: isPaused,
  2644. isAutoSliding: isAutoSliding,
  2645. // Adds or removes all internal event listeners (such as keyboard)
  2646. addEventListeners: addEventListeners,
  2647. removeEventListeners: removeEventListeners,
  2648. // Facility for persisting and restoring the presentation state
  2649. getState: getState,
  2650. setState: setState,
  2651. // Presentation progress on range of 0-1
  2652. getProgress: getProgress,
  2653. // Returns the indices of the current, or specified, slide
  2654. getIndices: getIndices,
  2655. getTotalSlides: getTotalSlides,
  2656. // Returns the slide at the specified index, y is optional
  2657. getSlide: function( x, y ) {
  2658. var horizontalSlide = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
  2659. var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
  2660. if( typeof y !== 'undefined' ) {
  2661. return verticalSlides ? verticalSlides[ y ] : undefined;
  2662. }
  2663. return horizontalSlide;
  2664. },
  2665. // Returns the previous slide element, may be null
  2666. getPreviousSlide: function() {
  2667. return previousSlide;
  2668. },
  2669. // Returns the current slide element
  2670. getCurrentSlide: function() {
  2671. return currentSlide;
  2672. },
  2673. // Returns the current scale of the presentation content
  2674. getScale: function() {
  2675. return scale;
  2676. },
  2677. // Returns the current configuration object
  2678. getConfig: function() {
  2679. return config;
  2680. },
  2681. // Helper method, retrieves query string as a key/value hash
  2682. getQueryHash: function() {
  2683. var query = {};
  2684. location.search.replace( /[A-Z0-9]+?=([\w\.%-]*)/gi, function(a) {
  2685. query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
  2686. } );
  2687. // Basic deserialization
  2688. for( var i in query ) {
  2689. var value = query[ i ];
  2690. query[ i ] = deserialize( unescape( value ) );
  2691. }
  2692. return query;
  2693. },
  2694. // Returns true if we're currently on the first slide
  2695. isFirstSlide: function() {
  2696. return document.querySelector( SLIDES_SELECTOR + '.past' ) == null ? true : false;
  2697. },
  2698. // Returns true if we're currently on the last slide
  2699. isLastSlide: function() {
  2700. if( currentSlide ) {
  2701. // Does this slide has next a sibling?
  2702. if( currentSlide.nextElementSibling ) return false;
  2703. // If it's vertical, does its parent have a next sibling?
  2704. if( isVerticalSlide( currentSlide ) && currentSlide.parentNode.nextElementSibling ) return false;
  2705. return true;
  2706. }
  2707. return false;
  2708. },
  2709. // Checks if reveal.js has been loaded and is ready for use
  2710. isReady: function() {
  2711. return loaded;
  2712. },
  2713. // Forward event binding to the reveal DOM element
  2714. addEventListener: function( type, listener, useCapture ) {
  2715. if( 'addEventListener' in window ) {
  2716. ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
  2717. }
  2718. },
  2719. removeEventListener: function( type, listener, useCapture ) {
  2720. if( 'addEventListener' in window ) {
  2721. ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
  2722. }
  2723. }
  2724. };
  2725. })();