reveal.js 94 KB

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