reveal.js 132 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866
  1. /*!
  2. * reveal.js
  3. * http://lab.hakim.se/reveal-js
  4. * MIT licensed
  5. *
  6. * Copyright (C) 2016 Hakim El Hattab, http://hakim.se
  7. */
  8. (function( root, factory ) {
  9. if( typeof define === 'function' && define.amd ) {
  10. // AMD. Register as an anonymous module.
  11. define( function() {
  12. root.Reveal = factory();
  13. return root.Reveal;
  14. } );
  15. } else if( typeof exports === 'object' ) {
  16. // Node. Does not work with strict CommonJS.
  17. module.exports = factory();
  18. } else {
  19. // Browser globals.
  20. root.Reveal = factory();
  21. }
  22. }( this, function() {
  23. 'use strict';
  24. var Reveal;
  25. // The reveal.js version
  26. var VERSION = '3.3.0';
  27. var SLIDES_SELECTOR = '.slides section',
  28. HORIZONTAL_SLIDES_SELECTOR = '.slides>section',
  29. VERTICAL_SLIDES_SELECTOR = '.slides>section.present>section',
  30. HOME_SLIDE_SELECTOR = '.slides>section:first-of-type',
  31. UA = navigator.userAgent,
  32. // Configuration defaults, can be overridden at initialization time
  33. config = {
  34. // The "normal" size of the presentation, aspect ratio will be preserved
  35. // when the presentation is scaled to fit different resolutions
  36. width: 960,
  37. height: 700,
  38. // Factor of the display size that should remain empty around the content
  39. margin: 0.04,
  40. // Bounds for smallest/largest possible scale to apply to content
  41. minScale: 0.2,
  42. maxScale: 2.0,
  43. // Display controls in the bottom right corner
  44. controls: true,
  45. // Display a presentation progress bar
  46. progress: true,
  47. // Display the page number of the current slide
  48. slideNumber: false,
  49. // Push each slide change to the browser history
  50. history: false,
  51. // Enable keyboard shortcuts for navigation
  52. keyboard: true,
  53. // Optional function that blocks keyboard events when retuning false
  54. keyboardCondition: null,
  55. // Enable the slide overview mode
  56. overview: true,
  57. // Vertical centering of slides
  58. center: true,
  59. // Enables touch navigation on devices with touch input
  60. touch: true,
  61. // Loop the presentation
  62. loop: false,
  63. // Change the presentation direction to be RTL
  64. rtl: false,
  65. // Randomizes the order of slides each time the presentation loads
  66. shuffle: false,
  67. // Turns fragments on and off globally
  68. fragments: true,
  69. // Flags if the presentation is running in an embedded mode,
  70. // i.e. contained within a limited portion of the screen
  71. embedded: false,
  72. // Flags if we should show a help overlay when the question-mark
  73. // key is pressed
  74. help: true,
  75. // Flags if it should be possible to pause the presentation (blackout)
  76. pause: true,
  77. // Flags if speaker notes should be visible to all viewers
  78. showNotes: false,
  79. // Number of milliseconds between automatically proceeding to the
  80. // next slide, disabled when set to 0, this value can be overwritten
  81. // by using a data-autoslide attribute on your slides
  82. autoSlide: 0,
  83. // Stop auto-sliding after user input
  84. autoSlideStoppable: true,
  85. // Use this method for navigation when auto-sliding (defaults to navigateNext)
  86. autoSlideMethod: null,
  87. // Enable slide navigation via mouse wheel
  88. mouseWheel: false,
  89. // Apply a 3D roll to links on hover
  90. rollingLinks: false,
  91. // Hides the address bar on mobile devices
  92. hideAddressBar: true,
  93. // Opens links in an iframe preview overlay
  94. previewLinks: false,
  95. // Exposes the reveal.js API through window.postMessage
  96. postMessage: true,
  97. // Dispatches all reveal.js events to the parent window through postMessage
  98. postMessageEvents: false,
  99. // Focuses body when page changes visibility to ensure keyboard shortcuts work
  100. focusBodyOnPageVisibilityChange: true,
  101. // Transition style
  102. transition: 'slide', // none/fade/slide/convex/concave/zoom
  103. // Transition speed
  104. transitionSpeed: 'default', // default/fast/slow
  105. // Transition style for full page slide backgrounds
  106. backgroundTransition: 'fade', // none/fade/slide/convex/concave/zoom
  107. // Parallax background image
  108. parallaxBackgroundImage: '', // CSS syntax, e.g. "a.jpg"
  109. // Parallax background size
  110. parallaxBackgroundSize: '', // CSS syntax, e.g. "3000px 2000px"
  111. // Amount of pixels to move the parallax background per slide step
  112. parallaxBackgroundHorizontal: null,
  113. parallaxBackgroundVertical: null,
  114. // The maximum number of pages a single slide can expand onto when printing
  115. // to PDF, unlimited by default
  116. pdfMaxPagesPerSlide: Number.POSITIVE_INFINITY,
  117. // Number of slides away from the current that are visible
  118. viewDistance: 3,
  119. // Script dependencies to load
  120. dependencies: []
  121. },
  122. // Flags if Reveal.initialize() has been called
  123. initialized = false,
  124. // Flags if reveal.js is loaded (has dispatched the 'ready' event)
  125. loaded = false,
  126. // Flags if the overview mode is currently active
  127. overview = false,
  128. // Holds the dimensions of our overview slides, including margins
  129. overviewSlideWidth = null,
  130. overviewSlideHeight = null,
  131. // The horizontal and vertical index of the currently active slide
  132. indexh,
  133. indexv,
  134. // The previous and current slide HTML elements
  135. previousSlide,
  136. currentSlide,
  137. previousBackground,
  138. // Slides may hold a data-state attribute which we pick up and apply
  139. // as a class to the body. This list contains the combined state of
  140. // all current slides.
  141. state = [],
  142. // The current scale of the presentation (see width/height config)
  143. scale = 1,
  144. // CSS transform that is currently applied to the slides container,
  145. // split into two groups
  146. slidesTransform = { layout: '', overview: '' },
  147. // Cached references to DOM elements
  148. dom = {},
  149. // Features supported by the browser, see #checkCapabilities()
  150. features = {},
  151. // Client is a mobile device, see #checkCapabilities()
  152. isMobileDevice,
  153. // Client is a desktop Chrome, see #checkCapabilities()
  154. isChrome,
  155. // Throttles mouse wheel navigation
  156. lastMouseWheelStep = 0,
  157. // Delays updates to the URL due to a Chrome thumbnailer bug
  158. writeURLTimeout = 0,
  159. // Flags if the interaction event listeners are bound
  160. eventsAreBound = false,
  161. // The current auto-slide duration
  162. autoSlide = 0,
  163. // Auto slide properties
  164. autoSlidePlayer,
  165. autoSlideTimeout = 0,
  166. autoSlideStartTime = -1,
  167. autoSlidePaused = false,
  168. // Holds information about the currently ongoing touch input
  169. touch = {
  170. startX: 0,
  171. startY: 0,
  172. startSpan: 0,
  173. startCount: 0,
  174. captured: false,
  175. threshold: 40
  176. },
  177. // Holds information about the keyboard shortcuts
  178. keyboardShortcuts = {
  179. 'N , SPACE': 'Next slide',
  180. 'P': 'Previous slide',
  181. '← , H': 'Navigate left',
  182. '→ , L': 'Navigate right',
  183. '↑ , K': 'Navigate up',
  184. '↓ , J': 'Navigate down',
  185. 'Home': 'First slide',
  186. 'End': 'Last slide',
  187. 'B , .': 'Pause',
  188. 'F': 'Fullscreen',
  189. 'ESC, O': 'Slide overview'
  190. };
  191. /**
  192. * Starts up the presentation if the client is capable.
  193. */
  194. function initialize( options ) {
  195. // Make sure we only initialize once
  196. if( initialized === true ) return;
  197. initialized = true;
  198. checkCapabilities();
  199. if( !features.transforms2d && !features.transforms3d ) {
  200. document.body.setAttribute( 'class', 'no-transforms' );
  201. // Since JS won't be running any further, we load all lazy
  202. // loading elements upfront
  203. var images = toArray( document.getElementsByTagName( 'img' ) ),
  204. iframes = toArray( document.getElementsByTagName( 'iframe' ) );
  205. var lazyLoadable = images.concat( iframes );
  206. for( var i = 0, len = lazyLoadable.length; i < len; i++ ) {
  207. var element = lazyLoadable[i];
  208. if( element.getAttribute( 'data-src' ) ) {
  209. element.setAttribute( 'src', element.getAttribute( 'data-src' ) );
  210. element.removeAttribute( 'data-src' );
  211. }
  212. }
  213. // If the browser doesn't support core features we won't be
  214. // using JavaScript to control the presentation
  215. return;
  216. }
  217. // Cache references to key DOM elements
  218. dom.wrapper = document.querySelector( '.reveal' );
  219. dom.slides = document.querySelector( '.reveal .slides' );
  220. // Force a layout when the whole page, incl fonts, has loaded
  221. window.addEventListener( 'load', layout, false );
  222. var query = Reveal.getQueryHash();
  223. // Do not accept new dependencies via query config to avoid
  224. // the potential of malicious script injection
  225. if( typeof query['dependencies'] !== 'undefined' ) delete query['dependencies'];
  226. // Copy options over to our config object
  227. extend( config, options );
  228. extend( config, query );
  229. // Hide the address bar in mobile browsers
  230. hideAddressBar();
  231. // Loads the dependencies and continues to #start() once done
  232. load();
  233. }
  234. /**
  235. * Inspect the client to see what it's capable of, this
  236. * should only happens once per runtime.
  237. */
  238. function checkCapabilities() {
  239. isMobileDevice = /(iphone|ipod|ipad|android)/gi.test( UA );
  240. isChrome = /chrome/i.test( UA ) && !/edge/i.test( UA );
  241. var testElement = document.createElement( 'div' );
  242. features.transforms3d = 'WebkitPerspective' in testElement.style ||
  243. 'MozPerspective' in testElement.style ||
  244. 'msPerspective' in testElement.style ||
  245. 'OPerspective' in testElement.style ||
  246. 'perspective' in testElement.style;
  247. features.transforms2d = 'WebkitTransform' in testElement.style ||
  248. 'MozTransform' in testElement.style ||
  249. 'msTransform' in testElement.style ||
  250. 'OTransform' in testElement.style ||
  251. 'transform' in testElement.style;
  252. features.requestAnimationFrameMethod = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
  253. features.requestAnimationFrame = typeof features.requestAnimationFrameMethod === 'function';
  254. features.canvas = !!document.createElement( 'canvas' ).getContext;
  255. // Transitions in the overview are disabled in desktop and
  256. // Safari due to lag
  257. features.overviewTransitions = !/Version\/[\d\.]+.*Safari/.test( UA );
  258. // Flags if we should use zoom instead of transform to scale
  259. // up slides. Zoom produces crisper results but has a lot of
  260. // xbrowser quirks so we only use it in whitelsited browsers.
  261. features.zoom = 'zoom' in testElement.style && !isMobileDevice &&
  262. ( isChrome || /Version\/[\d\.]+.*Safari/.test( UA ) );
  263. }
  264. /**
  265. * Loads the dependencies of reveal.js. Dependencies are
  266. * defined via the configuration option 'dependencies'
  267. * and will be loaded prior to starting/binding reveal.js.
  268. * Some dependencies may have an 'async' flag, if so they
  269. * will load after reveal.js has been started up.
  270. */
  271. function load() {
  272. var scripts = [],
  273. scriptsAsync = [],
  274. scriptsToPreload = 0;
  275. // Called once synchronous scripts finish loading
  276. function proceed() {
  277. if( scriptsAsync.length ) {
  278. // Load asynchronous scripts
  279. head.js.apply( null, scriptsAsync );
  280. }
  281. start();
  282. }
  283. function loadScript( s ) {
  284. head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], function() {
  285. // Extension may contain callback functions
  286. if( typeof s.callback === 'function' ) {
  287. s.callback.apply( this );
  288. }
  289. if( --scriptsToPreload === 0 ) {
  290. proceed();
  291. }
  292. });
  293. }
  294. for( var i = 0, len = config.dependencies.length; i < len; i++ ) {
  295. var s = config.dependencies[i];
  296. // Load if there's no condition or the condition is truthy
  297. if( !s.condition || s.condition() ) {
  298. if( s.async ) {
  299. scriptsAsync.push( s.src );
  300. }
  301. else {
  302. scripts.push( s.src );
  303. }
  304. loadScript( s );
  305. }
  306. }
  307. if( scripts.length ) {
  308. scriptsToPreload = scripts.length;
  309. // Load synchronous scripts
  310. head.js.apply( null, scripts );
  311. }
  312. else {
  313. proceed();
  314. }
  315. }
  316. /**
  317. * Starts up reveal.js by binding input events and navigating
  318. * to the current URL deeplink if there is one.
  319. */
  320. function start() {
  321. // Make sure we've got all the DOM elements we need
  322. setupDOM();
  323. // Listen to messages posted to this window
  324. setupPostMessage();
  325. // Prevent the slides from being scrolled out of view
  326. setupScrollPrevention();
  327. // Resets all vertical slides so that only the first is visible
  328. resetVerticalSlides();
  329. // Updates the presentation to match the current configuration values
  330. configure();
  331. // Read the initial hash
  332. readURL();
  333. // Update all backgrounds
  334. updateBackground( true );
  335. // Notify listeners that the presentation is ready but use a 1ms
  336. // timeout to ensure it's not fired synchronously after #initialize()
  337. setTimeout( function() {
  338. // Enable transitions now that we're loaded
  339. dom.slides.classList.remove( 'no-transition' );
  340. loaded = true;
  341. dispatchEvent( 'ready', {
  342. 'indexh': indexh,
  343. 'indexv': indexv,
  344. 'currentSlide': currentSlide
  345. } );
  346. }, 1 );
  347. // Special setup and config is required when printing to PDF
  348. if( isPrintingPDF() ) {
  349. removeEventListeners();
  350. // The document needs to have loaded for the PDF layout
  351. // measurements to be accurate
  352. if( document.readyState === 'complete' ) {
  353. setupPDF();
  354. }
  355. else {
  356. window.addEventListener( 'load', setupPDF );
  357. }
  358. }
  359. }
  360. /**
  361. * Finds and stores references to DOM elements which are
  362. * required by the presentation. If a required element is
  363. * not found, it is created.
  364. */
  365. function setupDOM() {
  366. // Prevent transitions while we're loading
  367. dom.slides.classList.add( 'no-transition' );
  368. // Background element
  369. dom.background = createSingletonNode( dom.wrapper, 'div', 'backgrounds', null );
  370. // Progress bar
  371. dom.progress = createSingletonNode( dom.wrapper, 'div', 'progress', '<span></span>' );
  372. dom.progressbar = dom.progress.querySelector( 'span' );
  373. // Arrow controls
  374. createSingletonNode( dom.wrapper, 'aside', 'controls',
  375. '<button class="navigate-left" aria-label="previous slide"></button>' +
  376. '<button class="navigate-right" aria-label="next slide"></button>' +
  377. '<button class="navigate-up" aria-label="above slide"></button>' +
  378. '<button class="navigate-down" aria-label="below slide"></button>' );
  379. // Slide number
  380. dom.slideNumber = createSingletonNode( dom.wrapper, 'div', 'slide-number', '' );
  381. // Element containing notes that are visible to the audience
  382. dom.speakerNotes = createSingletonNode( dom.wrapper, 'div', 'speaker-notes', null );
  383. dom.speakerNotes.setAttribute( 'data-prevent-swipe', '' );
  384. dom.speakerNotes.setAttribute( 'tabindex', '0' );
  385. // Overlay graphic which is displayed during the paused mode
  386. createSingletonNode( dom.wrapper, 'div', 'pause-overlay', null );
  387. // Cache references to elements
  388. dom.controls = document.querySelector( '.reveal .controls' );
  389. dom.theme = document.querySelector( '#theme' );
  390. dom.wrapper.setAttribute( 'role', 'application' );
  391. // There can be multiple instances of controls throughout the page
  392. dom.controlsLeft = toArray( document.querySelectorAll( '.navigate-left' ) );
  393. dom.controlsRight = toArray( document.querySelectorAll( '.navigate-right' ) );
  394. dom.controlsUp = toArray( document.querySelectorAll( '.navigate-up' ) );
  395. dom.controlsDown = toArray( document.querySelectorAll( '.navigate-down' ) );
  396. dom.controlsPrev = toArray( document.querySelectorAll( '.navigate-prev' ) );
  397. dom.controlsNext = toArray( document.querySelectorAll( '.navigate-next' ) );
  398. dom.statusDiv = createStatusDiv();
  399. }
  400. /**
  401. * Creates a hidden div with role aria-live to announce the
  402. * current slide content. Hide the div off-screen to make it
  403. * available only to Assistive Technologies.
  404. *
  405. * @return {HTMLElement}
  406. */
  407. function createStatusDiv() {
  408. var statusDiv = document.getElementById( 'aria-status-div' );
  409. if( !statusDiv ) {
  410. statusDiv = document.createElement( 'div' );
  411. statusDiv.style.position = 'absolute';
  412. statusDiv.style.height = '1px';
  413. statusDiv.style.width = '1px';
  414. statusDiv.style.overflow = 'hidden';
  415. statusDiv.style.clip = 'rect( 1px, 1px, 1px, 1px )';
  416. statusDiv.setAttribute( 'id', 'aria-status-div' );
  417. statusDiv.setAttribute( 'aria-live', 'polite' );
  418. statusDiv.setAttribute( 'aria-atomic','true' );
  419. dom.wrapper.appendChild( statusDiv );
  420. }
  421. return statusDiv;
  422. }
  423. /**
  424. * Configures the presentation for printing to a static
  425. * PDF.
  426. */
  427. function setupPDF() {
  428. var slideSize = getComputedSlideSize( window.innerWidth, window.innerHeight );
  429. // Dimensions of the PDF pages
  430. var pageWidth = Math.floor( slideSize.width * ( 1 + config.margin ) ),
  431. pageHeight = Math.floor( slideSize.height * ( 1 + config.margin ) );
  432. // Dimensions of slides within the pages
  433. var slideWidth = slideSize.width,
  434. slideHeight = slideSize.height;
  435. // Let the browser know what page size we want to print
  436. injectStyleSheet( '@page{size:'+ pageWidth +'px '+ pageHeight +'px; margin: 0;}' );
  437. // Limit the size of certain elements to the dimensions of the slide
  438. injectStyleSheet( '.reveal section>img, .reveal section>video, .reveal section>iframe{max-width: '+ slideWidth +'px; max-height:'+ slideHeight +'px}' );
  439. document.body.classList.add( 'print-pdf' );
  440. document.body.style.width = pageWidth + 'px';
  441. document.body.style.height = pageHeight + 'px';
  442. // Add each slide's index as attributes on itself, we need these
  443. // indices to generate slide numbers below
  444. toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).forEach( function( hslide, h ) {
  445. hslide.setAttribute( 'data-index-h', h );
  446. if( hslide.classList.contains( 'stack' ) ) {
  447. toArray( hslide.querySelectorAll( 'section' ) ).forEach( function( vslide, v ) {
  448. vslide.setAttribute( 'data-index-h', h );
  449. vslide.setAttribute( 'data-index-v', v );
  450. } );
  451. }
  452. } );
  453. // Slide and slide background layout
  454. toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
  455. // Vertical stacks are not centred since their section
  456. // children will be
  457. if( slide.classList.contains( 'stack' ) === false ) {
  458. // Center the slide inside of the page, giving the slide some margin
  459. var left = ( pageWidth - slideWidth ) / 2,
  460. top = ( pageHeight - slideHeight ) / 2;
  461. var contentHeight = slide.scrollHeight;
  462. var numberOfPages = Math.max( Math.ceil( contentHeight / pageHeight ), 1 );
  463. // Adhere to configured pages per slide limit
  464. numberOfPages = Math.min( numberOfPages, config.pdfMaxPagesPerSlide );
  465. // Center slides vertically
  466. if( numberOfPages === 1 && config.center || slide.classList.contains( 'center' ) ) {
  467. top = Math.max( ( pageHeight - contentHeight ) / 2, 0 );
  468. }
  469. // Wrap the slide in a page element and hide its overflow
  470. // so that no page ever flows onto another
  471. var page = document.createElement( 'div' );
  472. page.className = 'pdf-page';
  473. page.style.height = ( pageHeight * numberOfPages ) + 'px';
  474. slide.parentNode.insertBefore( page, slide );
  475. page.appendChild( slide );
  476. // Position the slide inside of the page
  477. slide.style.left = left + 'px';
  478. slide.style.top = top + 'px';
  479. slide.style.width = slideWidth + 'px';
  480. if( slide.slideBackgroundElement ) {
  481. page.insertBefore( slide.slideBackgroundElement, slide );
  482. }
  483. // Inject notes if `showNotes` is enabled
  484. if( config.showNotes ) {
  485. // Are there notes for this slide?
  486. var notes = getSlideNotes( slide );
  487. if( notes ) {
  488. var notesSpacing = 8;
  489. var notesLayout = typeof config.showNotes === 'string' ? config.showNotes : 'inline';
  490. var notesElement = document.createElement( 'div' );
  491. notesElement.classList.add( 'speaker-notes' );
  492. notesElement.classList.add( 'speaker-notes-pdf' );
  493. notesElement.setAttribute( 'data-layout', notesLayout );
  494. notesElement.innerHTML = notes;
  495. if( notesLayout === 'separate-page' ) {
  496. page.parentNode.insertBefore( notesElement, page.nextSibling );
  497. }
  498. else {
  499. notesElement.style.left = notesSpacing + 'px';
  500. notesElement.style.bottom = notesSpacing + 'px';
  501. notesElement.style.width = ( pageWidth - notesSpacing*2 ) + 'px';
  502. page.appendChild( notesElement );
  503. }
  504. }
  505. }
  506. // Inject slide numbers if `slideNumbers` are enabled
  507. if( config.slideNumber ) {
  508. var slideNumberH = parseInt( slide.getAttribute( 'data-index-h' ), 10 ) + 1,
  509. slideNumberV = parseInt( slide.getAttribute( 'data-index-v' ), 10 ) + 1;
  510. var numberElement = document.createElement( 'div' );
  511. numberElement.classList.add( 'slide-number' );
  512. numberElement.classList.add( 'slide-number-pdf' );
  513. numberElement.innerHTML = formatSlideNumber( slideNumberH, '.', slideNumberV );
  514. page.appendChild( numberElement );
  515. }
  516. }
  517. } );
  518. // Show all fragments
  519. toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ' .fragment' ) ).forEach( function( fragment ) {
  520. fragment.classList.add( 'visible' );
  521. } );
  522. }
  523. /**
  524. * This is an unfortunate necessity. Some actions – such as
  525. * an input field being focused in an iframe or using the
  526. * keyboard to expand text selection beyond the bounds of
  527. * a slide – can trigger our content to be pushed out of view.
  528. * This scrolling can not be prevented by hiding overflow in
  529. * CSS (we already do) so we have to resort to repeatedly
  530. * checking if the slides have been offset :(
  531. */
  532. function setupScrollPrevention() {
  533. setInterval( function() {
  534. if( dom.wrapper.scrollTop !== 0 || dom.wrapper.scrollLeft !== 0 ) {
  535. dom.wrapper.scrollTop = 0;
  536. dom.wrapper.scrollLeft = 0;
  537. }
  538. }, 1000 );
  539. }
  540. /**
  541. * Creates an HTML element and returns a reference to it.
  542. * If the element already exists the existing instance will
  543. * be returned.
  544. *
  545. * @param {HTMLElement} container
  546. * @param {string} tagname
  547. * @param {string} classname
  548. * @param {string} innerHTML
  549. *
  550. * @return {HTMLElement}
  551. */
  552. function createSingletonNode( container, tagname, classname, innerHTML ) {
  553. // Find all nodes matching the description
  554. var nodes = container.querySelectorAll( '.' + classname );
  555. // Check all matches to find one which is a direct child of
  556. // the specified container
  557. for( var i = 0; i < nodes.length; i++ ) {
  558. var testNode = nodes[i];
  559. if( testNode.parentNode === container ) {
  560. return testNode;
  561. }
  562. }
  563. // If no node was found, create it now
  564. var node = document.createElement( tagname );
  565. node.classList.add( classname );
  566. if( typeof innerHTML === 'string' ) {
  567. node.innerHTML = innerHTML;
  568. }
  569. container.appendChild( node );
  570. return node;
  571. }
  572. /**
  573. * Creates the slide background elements and appends them
  574. * to the background container. One element is created per
  575. * slide no matter if the given slide has visible background.
  576. */
  577. function createBackgrounds() {
  578. var printMode = isPrintingPDF();
  579. // Clear prior backgrounds
  580. dom.background.innerHTML = '';
  581. dom.background.classList.add( 'no-transition' );
  582. // Iterate over all horizontal slides
  583. toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).forEach( function( slideh ) {
  584. var backgroundStack = createBackground( slideh, dom.background );
  585. // Iterate over all vertical slides
  586. toArray( slideh.querySelectorAll( 'section' ) ).forEach( function( slidev ) {
  587. createBackground( slidev, backgroundStack );
  588. backgroundStack.classList.add( 'stack' );
  589. } );
  590. } );
  591. // Add parallax background if specified
  592. if( config.parallaxBackgroundImage ) {
  593. dom.background.style.backgroundImage = 'url("' + config.parallaxBackgroundImage + '")';
  594. dom.background.style.backgroundSize = config.parallaxBackgroundSize;
  595. // Make sure the below properties are set on the element - these properties are
  596. // needed for proper transitions to be set on the element via CSS. To remove
  597. // annoying background slide-in effect when the presentation starts, apply
  598. // these properties after short time delay
  599. setTimeout( function() {
  600. dom.wrapper.classList.add( 'has-parallax-background' );
  601. }, 1 );
  602. }
  603. else {
  604. dom.background.style.backgroundImage = '';
  605. dom.wrapper.classList.remove( 'has-parallax-background' );
  606. }
  607. }
  608. /**
  609. * Creates a background for the given slide.
  610. *
  611. * @param {HTMLElement} slide
  612. * @param {HTMLElement} container The element that the background
  613. * should be appended to
  614. * @return {HTMLElement} New background div
  615. */
  616. function createBackground( slide, container ) {
  617. var data = {
  618. background: slide.getAttribute( 'data-background' ),
  619. backgroundSize: slide.getAttribute( 'data-background-size' ),
  620. backgroundImage: slide.getAttribute( 'data-background-image' ),
  621. backgroundVideo: slide.getAttribute( 'data-background-video' ),
  622. backgroundIframe: slide.getAttribute( 'data-background-iframe' ),
  623. backgroundColor: slide.getAttribute( 'data-background-color' ),
  624. backgroundRepeat: slide.getAttribute( 'data-background-repeat' ),
  625. backgroundPosition: slide.getAttribute( 'data-background-position' ),
  626. backgroundTransition: slide.getAttribute( 'data-background-transition' )
  627. };
  628. var element = document.createElement( 'div' );
  629. // Carry over custom classes from the slide to the background
  630. element.className = 'slide-background ' + slide.className.replace( /present|past|future/, '' );
  631. if( data.background ) {
  632. // Auto-wrap image urls in url(...)
  633. if( /^(http|file|\/\/)/gi.test( data.background ) || /\.(svg|png|jpg|jpeg|gif|bmp)$/gi.test( data.background ) ) {
  634. slide.setAttribute( 'data-background-image', data.background );
  635. }
  636. else {
  637. element.style.background = data.background;
  638. }
  639. }
  640. // Create a hash for this combination of background settings.
  641. // This is used to determine when two slide backgrounds are
  642. // the same.
  643. if( data.background || data.backgroundColor || data.backgroundImage || data.backgroundVideo || data.backgroundIframe ) {
  644. element.setAttribute( 'data-background-hash', data.background +
  645. data.backgroundSize +
  646. data.backgroundImage +
  647. data.backgroundVideo +
  648. data.backgroundIframe +
  649. data.backgroundColor +
  650. data.backgroundRepeat +
  651. data.backgroundPosition +
  652. data.backgroundTransition );
  653. }
  654. // Additional and optional background properties
  655. if( data.backgroundSize ) element.style.backgroundSize = data.backgroundSize;
  656. if( data.backgroundColor ) element.style.backgroundColor = data.backgroundColor;
  657. if( data.backgroundRepeat ) element.style.backgroundRepeat = data.backgroundRepeat;
  658. if( data.backgroundPosition ) element.style.backgroundPosition = data.backgroundPosition;
  659. if( data.backgroundTransition ) element.setAttribute( 'data-background-transition', data.backgroundTransition );
  660. container.appendChild( element );
  661. // If backgrounds are being recreated, clear old classes
  662. slide.classList.remove( 'has-dark-background' );
  663. slide.classList.remove( 'has-light-background' );
  664. slide.slideBackgroundElement = element;
  665. // If this slide has a background color, add a class that
  666. // signals if it is light or dark. If the slide has no background
  667. // color, no class will be set
  668. var computedBackgroundColor = window.getComputedStyle( element ).backgroundColor;
  669. if( computedBackgroundColor ) {
  670. var rgb = colorToRgb( computedBackgroundColor );
  671. // Ignore fully transparent backgrounds. Some browsers return
  672. // rgba(0,0,0,0) when reading the computed background color of
  673. // an element with no background
  674. if( rgb && rgb.a !== 0 ) {
  675. if( colorBrightness( computedBackgroundColor ) < 128 ) {
  676. slide.classList.add( 'has-dark-background' );
  677. }
  678. else {
  679. slide.classList.add( 'has-light-background' );
  680. }
  681. }
  682. }
  683. return element;
  684. }
  685. /**
  686. * Registers a listener to postMessage events, this makes it
  687. * possible to call all reveal.js API methods from another
  688. * window. For example:
  689. *
  690. * revealWindow.postMessage( JSON.stringify({
  691. * method: 'slide',
  692. * args: [ 2 ]
  693. * }), '*' );
  694. */
  695. function setupPostMessage() {
  696. if( config.postMessage ) {
  697. window.addEventListener( 'message', function ( event ) {
  698. var data = event.data;
  699. // Make sure we're dealing with JSON
  700. if( typeof data === 'string' && data.charAt( 0 ) === '{' && data.charAt( data.length - 1 ) === '}' ) {
  701. data = JSON.parse( data );
  702. // Check if the requested method can be found
  703. if( data.method && typeof Reveal[data.method] === 'function' ) {
  704. Reveal[data.method].apply( Reveal, data.args );
  705. }
  706. }
  707. }, false );
  708. }
  709. }
  710. /**
  711. * Applies the configuration settings from the config
  712. * object. May be called multiple times.
  713. *
  714. * @param {object} options
  715. */
  716. function configure( options ) {
  717. var numberOfSlides = dom.wrapper.querySelectorAll( SLIDES_SELECTOR ).length;
  718. dom.wrapper.classList.remove( config.transition );
  719. // New config options may be passed when this method
  720. // is invoked through the API after initialization
  721. if( typeof options === 'object' ) extend( config, options );
  722. // Force linear transition based on browser capabilities
  723. if( features.transforms3d === false ) config.transition = 'linear';
  724. dom.wrapper.classList.add( config.transition );
  725. dom.wrapper.setAttribute( 'data-transition-speed', config.transitionSpeed );
  726. dom.wrapper.setAttribute( 'data-background-transition', config.backgroundTransition );
  727. dom.controls.style.display = config.controls ? 'block' : 'none';
  728. dom.progress.style.display = config.progress ? 'block' : 'none';
  729. dom.slideNumber.style.display = config.slideNumber && !isPrintingPDF() ? 'block' : 'none';
  730. if( config.shuffle ) {
  731. shuffle();
  732. }
  733. if( config.rtl ) {
  734. dom.wrapper.classList.add( 'rtl' );
  735. }
  736. else {
  737. dom.wrapper.classList.remove( 'rtl' );
  738. }
  739. if( config.center ) {
  740. dom.wrapper.classList.add( 'center' );
  741. }
  742. else {
  743. dom.wrapper.classList.remove( 'center' );
  744. }
  745. // Exit the paused mode if it was configured off
  746. if( config.pause === false ) {
  747. resume();
  748. }
  749. if( config.showNotes ) {
  750. dom.speakerNotes.classList.add( 'visible' );
  751. dom.speakerNotes.setAttribute( 'data-layout', typeof config.showNotes === 'string' ? config.showNotes : 'inline' );
  752. }
  753. else {
  754. dom.speakerNotes.classList.remove( 'visible' );
  755. }
  756. if( config.mouseWheel ) {
  757. document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  758. document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
  759. }
  760. else {
  761. document.removeEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  762. document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
  763. }
  764. // Rolling 3D links
  765. if( config.rollingLinks ) {
  766. enableRollingLinks();
  767. }
  768. else {
  769. disableRollingLinks();
  770. }
  771. // Iframe link previews
  772. if( config.previewLinks ) {
  773. enablePreviewLinks();
  774. }
  775. else {
  776. disablePreviewLinks();
  777. enablePreviewLinks( '[data-preview-link]' );
  778. }
  779. // Remove existing auto-slide controls
  780. if( autoSlidePlayer ) {
  781. autoSlidePlayer.destroy();
  782. autoSlidePlayer = null;
  783. }
  784. // Generate auto-slide controls if needed
  785. if( numberOfSlides > 1 && config.autoSlide && config.autoSlideStoppable && features.canvas && features.requestAnimationFrame ) {
  786. autoSlidePlayer = new Playback( dom.wrapper, function() {
  787. return Math.min( Math.max( ( Date.now() - autoSlideStartTime ) / autoSlide, 0 ), 1 );
  788. } );
  789. autoSlidePlayer.on( 'click', onAutoSlidePlayerClick );
  790. autoSlidePaused = false;
  791. }
  792. // When fragments are turned off they should be visible
  793. if( config.fragments === false ) {
  794. toArray( dom.slides.querySelectorAll( '.fragment' ) ).forEach( function( element ) {
  795. element.classList.add( 'visible' );
  796. element.classList.remove( 'current-fragment' );
  797. } );
  798. }
  799. sync();
  800. }
  801. /**
  802. * Binds all event listeners.
  803. */
  804. function addEventListeners() {
  805. eventsAreBound = true;
  806. window.addEventListener( 'hashchange', onWindowHashChange, false );
  807. window.addEventListener( 'resize', onWindowResize, false );
  808. if( config.touch ) {
  809. dom.wrapper.addEventListener( 'touchstart', onTouchStart, false );
  810. dom.wrapper.addEventListener( 'touchmove', onTouchMove, false );
  811. dom.wrapper.addEventListener( 'touchend', onTouchEnd, false );
  812. // Support pointer-style touch interaction as well
  813. if( window.navigator.pointerEnabled ) {
  814. // IE 11 uses un-prefixed version of pointer events
  815. dom.wrapper.addEventListener( 'pointerdown', onPointerDown, false );
  816. dom.wrapper.addEventListener( 'pointermove', onPointerMove, false );
  817. dom.wrapper.addEventListener( 'pointerup', onPointerUp, false );
  818. }
  819. else if( window.navigator.msPointerEnabled ) {
  820. // IE 10 uses prefixed version of pointer events
  821. dom.wrapper.addEventListener( 'MSPointerDown', onPointerDown, false );
  822. dom.wrapper.addEventListener( 'MSPointerMove', onPointerMove, false );
  823. dom.wrapper.addEventListener( 'MSPointerUp', onPointerUp, false );
  824. }
  825. }
  826. if( config.keyboard ) {
  827. document.addEventListener( 'keydown', onDocumentKeyDown, false );
  828. document.addEventListener( 'keypress', onDocumentKeyPress, false );
  829. }
  830. if( config.progress && dom.progress ) {
  831. dom.progress.addEventListener( 'click', onProgressClicked, false );
  832. }
  833. if( config.focusBodyOnPageVisibilityChange ) {
  834. var visibilityChange;
  835. if( 'hidden' in document ) {
  836. visibilityChange = 'visibilitychange';
  837. }
  838. else if( 'msHidden' in document ) {
  839. visibilityChange = 'msvisibilitychange';
  840. }
  841. else if( 'webkitHidden' in document ) {
  842. visibilityChange = 'webkitvisibilitychange';
  843. }
  844. if( visibilityChange ) {
  845. document.addEventListener( visibilityChange, onPageVisibilityChange, false );
  846. }
  847. }
  848. // Listen to both touch and click events, in case the device
  849. // supports both
  850. var pointerEvents = [ 'touchstart', 'click' ];
  851. // Only support touch for Android, fixes double navigations in
  852. // stock browser
  853. if( UA.match( /android/gi ) ) {
  854. pointerEvents = [ 'touchstart' ];
  855. }
  856. pointerEvents.forEach( function( eventName ) {
  857. dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } );
  858. dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } );
  859. dom.controlsUp.forEach( function( el ) { el.addEventListener( eventName, onNavigateUpClicked, false ); } );
  860. dom.controlsDown.forEach( function( el ) { el.addEventListener( eventName, onNavigateDownClicked, false ); } );
  861. dom.controlsPrev.forEach( function( el ) { el.addEventListener( eventName, onNavigatePrevClicked, false ); } );
  862. dom.controlsNext.forEach( function( el ) { el.addEventListener( eventName, onNavigateNextClicked, false ); } );
  863. } );
  864. }
  865. /**
  866. * Unbinds all event listeners.
  867. */
  868. function removeEventListeners() {
  869. eventsAreBound = false;
  870. document.removeEventListener( 'keydown', onDocumentKeyDown, false );
  871. document.removeEventListener( 'keypress', onDocumentKeyPress, false );
  872. window.removeEventListener( 'hashchange', onWindowHashChange, false );
  873. window.removeEventListener( 'resize', onWindowResize, false );
  874. dom.wrapper.removeEventListener( 'touchstart', onTouchStart, false );
  875. dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false );
  876. dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false );
  877. // IE11
  878. if( window.navigator.pointerEnabled ) {
  879. dom.wrapper.removeEventListener( 'pointerdown', onPointerDown, false );
  880. dom.wrapper.removeEventListener( 'pointermove', onPointerMove, false );
  881. dom.wrapper.removeEventListener( 'pointerup', onPointerUp, false );
  882. }
  883. // IE10
  884. else if( window.navigator.msPointerEnabled ) {
  885. dom.wrapper.removeEventListener( 'MSPointerDown', onPointerDown, false );
  886. dom.wrapper.removeEventListener( 'MSPointerMove', onPointerMove, false );
  887. dom.wrapper.removeEventListener( 'MSPointerUp', onPointerUp, false );
  888. }
  889. if ( config.progress && dom.progress ) {
  890. dom.progress.removeEventListener( 'click', onProgressClicked, false );
  891. }
  892. [ 'touchstart', 'click' ].forEach( function( eventName ) {
  893. dom.controlsLeft.forEach( function( el ) { el.removeEventListener( eventName, onNavigateLeftClicked, false ); } );
  894. dom.controlsRight.forEach( function( el ) { el.removeEventListener( eventName, onNavigateRightClicked, false ); } );
  895. dom.controlsUp.forEach( function( el ) { el.removeEventListener( eventName, onNavigateUpClicked, false ); } );
  896. dom.controlsDown.forEach( function( el ) { el.removeEventListener( eventName, onNavigateDownClicked, false ); } );
  897. dom.controlsPrev.forEach( function( el ) { el.removeEventListener( eventName, onNavigatePrevClicked, false ); } );
  898. dom.controlsNext.forEach( function( el ) { el.removeEventListener( eventName, onNavigateNextClicked, false ); } );
  899. } );
  900. }
  901. /**
  902. * Extend object a with the properties of object b.
  903. * If there's a conflict, object b takes precedence.
  904. *
  905. * @param {object} a
  906. * @param {object} b
  907. */
  908. function extend( a, b ) {
  909. for( var i in b ) {
  910. a[ i ] = b[ i ];
  911. }
  912. }
  913. /**
  914. * Converts the target object to an array.
  915. *
  916. * @param {object} o
  917. * @return {object[]}
  918. */
  919. function toArray( o ) {
  920. return Array.prototype.slice.call( o );
  921. }
  922. /**
  923. * Utility for deserializing a value.
  924. *
  925. * @param {*} value
  926. * @return {*}
  927. */
  928. function deserialize( value ) {
  929. if( typeof value === 'string' ) {
  930. if( value === 'null' ) return null;
  931. else if( value === 'true' ) return true;
  932. else if( value === 'false' ) return false;
  933. else if( value.match( /^\d+$/ ) ) return parseFloat( value );
  934. }
  935. return value;
  936. }
  937. /**
  938. * Measures the distance in pixels between point a
  939. * and point b.
  940. *
  941. * @param {object} a point with x/y properties
  942. * @param {object} b point with x/y properties
  943. *
  944. * @return {number}
  945. */
  946. function distanceBetween( a, b ) {
  947. var dx = a.x - b.x,
  948. dy = a.y - b.y;
  949. return Math.sqrt( dx*dx + dy*dy );
  950. }
  951. /**
  952. * Applies a CSS transform to the target element.
  953. *
  954. * @param {HTMLElement} element
  955. * @param {string} transform
  956. */
  957. function transformElement( element, transform ) {
  958. element.style.WebkitTransform = transform;
  959. element.style.MozTransform = transform;
  960. element.style.msTransform = transform;
  961. element.style.transform = transform;
  962. }
  963. /**
  964. * Applies CSS transforms to the slides container. The container
  965. * is transformed from two separate sources: layout and the overview
  966. * mode.
  967. *
  968. * @param {object} transforms
  969. */
  970. function transformSlides( transforms ) {
  971. // Pick up new transforms from arguments
  972. if( typeof transforms.layout === 'string' ) slidesTransform.layout = transforms.layout;
  973. if( typeof transforms.overview === 'string' ) slidesTransform.overview = transforms.overview;
  974. // Apply the transforms to the slides container
  975. if( slidesTransform.layout ) {
  976. transformElement( dom.slides, slidesTransform.layout + ' ' + slidesTransform.overview );
  977. }
  978. else {
  979. transformElement( dom.slides, slidesTransform.overview );
  980. }
  981. }
  982. /**
  983. * Injects the given CSS styles into the DOM.
  984. *
  985. * @param {string} value
  986. */
  987. function injectStyleSheet( value ) {
  988. var tag = document.createElement( 'style' );
  989. tag.type = 'text/css';
  990. if( tag.styleSheet ) {
  991. tag.styleSheet.cssText = value;
  992. }
  993. else {
  994. tag.appendChild( document.createTextNode( value ) );
  995. }
  996. document.getElementsByTagName( 'head' )[0].appendChild( tag );
  997. }
  998. /**
  999. * Converts various color input formats to an {r:0,g:0,b:0} object.
  1000. *
  1001. * @param {string} color The string representation of a color
  1002. * @example
  1003. * colorToRgb('#000');
  1004. * @example
  1005. * colorToRgb('#000000');
  1006. * @example
  1007. * colorToRgb('rgb(0,0,0)');
  1008. * @example
  1009. * colorToRgb('rgba(0,0,0)');
  1010. *
  1011. * @return {{r: number, g: number, b: number, [a]: number}|null}
  1012. */
  1013. function colorToRgb( color ) {
  1014. var hex3 = color.match( /^#([0-9a-f]{3})$/i );
  1015. if( hex3 && hex3[1] ) {
  1016. hex3 = hex3[1];
  1017. return {
  1018. r: parseInt( hex3.charAt( 0 ), 16 ) * 0x11,
  1019. g: parseInt( hex3.charAt( 1 ), 16 ) * 0x11,
  1020. b: parseInt( hex3.charAt( 2 ), 16 ) * 0x11
  1021. };
  1022. }
  1023. var hex6 = color.match( /^#([0-9a-f]{6})$/i );
  1024. if( hex6 && hex6[1] ) {
  1025. hex6 = hex6[1];
  1026. return {
  1027. r: parseInt( hex6.substr( 0, 2 ), 16 ),
  1028. g: parseInt( hex6.substr( 2, 2 ), 16 ),
  1029. b: parseInt( hex6.substr( 4, 2 ), 16 )
  1030. };
  1031. }
  1032. var rgb = color.match( /^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i );
  1033. if( rgb ) {
  1034. return {
  1035. r: parseInt( rgb[1], 10 ),
  1036. g: parseInt( rgb[2], 10 ),
  1037. b: parseInt( rgb[3], 10 )
  1038. };
  1039. }
  1040. var rgba = color.match( /^rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\,\s*([\d]+|[\d]*.[\d]+)\s*\)$/i );
  1041. if( rgba ) {
  1042. return {
  1043. r: parseInt( rgba[1], 10 ),
  1044. g: parseInt( rgba[2], 10 ),
  1045. b: parseInt( rgba[3], 10 ),
  1046. a: parseFloat( rgba[4] )
  1047. };
  1048. }
  1049. return null;
  1050. }
  1051. /**
  1052. * Calculates brightness on a scale of 0-255.
  1053. *
  1054. * @param {string} color See colorToRgb for supported formats.
  1055. * @see {@link colorToRgb}
  1056. */
  1057. function colorBrightness( color ) {
  1058. if( typeof color === 'string' ) color = colorToRgb( color );
  1059. if( color ) {
  1060. return ( color.r * 299 + color.g * 587 + color.b * 114 ) / 1000;
  1061. }
  1062. return null;
  1063. }
  1064. /**
  1065. * Returns the remaining height within the parent of the
  1066. * target element.
  1067. *
  1068. * remaining height = [ configured parent height ] - [ current parent height ]
  1069. *
  1070. * @param {HTMLElement} element
  1071. * @param {number} [height]
  1072. */
  1073. function getRemainingHeight( element, height ) {
  1074. height = height || 0;
  1075. if( element ) {
  1076. var newHeight, oldHeight = element.style.height;
  1077. // Change the .stretch element height to 0 in order find the height of all
  1078. // the other elements
  1079. element.style.height = '0px';
  1080. newHeight = height - element.parentNode.offsetHeight;
  1081. // Restore the old height, just in case
  1082. element.style.height = oldHeight + 'px';
  1083. return newHeight;
  1084. }
  1085. return height;
  1086. }
  1087. /**
  1088. * Checks if this instance is being used to print a PDF.
  1089. */
  1090. function isPrintingPDF() {
  1091. return ( /print-pdf/gi ).test( window.location.search );
  1092. }
  1093. /**
  1094. * Hides the address bar if we're on a mobile device.
  1095. */
  1096. function hideAddressBar() {
  1097. if( config.hideAddressBar && isMobileDevice ) {
  1098. // Events that should trigger the address bar to hide
  1099. window.addEventListener( 'load', removeAddressBar, false );
  1100. window.addEventListener( 'orientationchange', removeAddressBar, false );
  1101. }
  1102. }
  1103. /**
  1104. * Causes the address bar to hide on mobile devices,
  1105. * more vertical space ftw.
  1106. */
  1107. function removeAddressBar() {
  1108. setTimeout( function() {
  1109. window.scrollTo( 0, 1 );
  1110. }, 10 );
  1111. }
  1112. /**
  1113. * Dispatches an event of the specified type from the
  1114. * reveal DOM element.
  1115. */
  1116. function dispatchEvent( type, args ) {
  1117. var event = document.createEvent( 'HTMLEvents', 1, 2 );
  1118. event.initEvent( type, true, true );
  1119. extend( event, args );
  1120. dom.wrapper.dispatchEvent( event );
  1121. // If we're in an iframe, post each reveal.js event to the
  1122. // parent window. Used by the notes plugin
  1123. if( config.postMessageEvents && window.parent !== window.self ) {
  1124. window.parent.postMessage( JSON.stringify({ namespace: 'reveal', eventName: type, state: getState() }), '*' );
  1125. }
  1126. }
  1127. /**
  1128. * Wrap all links in 3D goodness.
  1129. */
  1130. function enableRollingLinks() {
  1131. if( features.transforms3d && !( 'msPerspective' in document.body.style ) ) {
  1132. var anchors = dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ' a' );
  1133. for( var i = 0, len = anchors.length; i < len; i++ ) {
  1134. var anchor = anchors[i];
  1135. if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
  1136. var span = document.createElement('span');
  1137. span.setAttribute('data-title', anchor.text);
  1138. span.innerHTML = anchor.innerHTML;
  1139. anchor.classList.add( 'roll' );
  1140. anchor.innerHTML = '';
  1141. anchor.appendChild(span);
  1142. }
  1143. }
  1144. }
  1145. }
  1146. /**
  1147. * Unwrap all 3D links.
  1148. */
  1149. function disableRollingLinks() {
  1150. var anchors = dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
  1151. for( var i = 0, len = anchors.length; i < len; i++ ) {
  1152. var anchor = anchors[i];
  1153. var span = anchor.querySelector( 'span' );
  1154. if( span ) {
  1155. anchor.classList.remove( 'roll' );
  1156. anchor.innerHTML = span.innerHTML;
  1157. }
  1158. }
  1159. }
  1160. /**
  1161. * Bind preview frame links.
  1162. *
  1163. * @param {string} [selector=a] - selector for anchors
  1164. */
  1165. function enablePreviewLinks( selector ) {
  1166. var anchors = toArray( document.querySelectorAll( selector ? selector : 'a' ) );
  1167. anchors.forEach( function( element ) {
  1168. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  1169. element.addEventListener( 'click', onPreviewLinkClicked, false );
  1170. }
  1171. } );
  1172. }
  1173. /**
  1174. * Unbind preview frame links.
  1175. */
  1176. function disablePreviewLinks() {
  1177. var anchors = toArray( document.querySelectorAll( 'a' ) );
  1178. anchors.forEach( function( element ) {
  1179. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  1180. element.removeEventListener( 'click', onPreviewLinkClicked, false );
  1181. }
  1182. } );
  1183. }
  1184. /**
  1185. * Opens a preview window for the target URL.
  1186. *
  1187. * @param {string} url - url for preview iframe src
  1188. */
  1189. function showPreview( url ) {
  1190. closeOverlay();
  1191. dom.overlay = document.createElement( 'div' );
  1192. dom.overlay.classList.add( 'overlay' );
  1193. dom.overlay.classList.add( 'overlay-preview' );
  1194. dom.wrapper.appendChild( dom.overlay );
  1195. dom.overlay.innerHTML = [
  1196. '<header>',
  1197. '<a class="close" href="#"><span class="icon"></span></a>',
  1198. '<a class="external" href="'+ url +'" target="_blank"><span class="icon"></span></a>',
  1199. '</header>',
  1200. '<div class="spinner"></div>',
  1201. '<div class="viewport">',
  1202. '<iframe src="'+ url +'"></iframe>',
  1203. '</div>'
  1204. ].join('');
  1205. dom.overlay.querySelector( 'iframe' ).addEventListener( 'load', function( event ) {
  1206. dom.overlay.classList.add( 'loaded' );
  1207. }, false );
  1208. dom.overlay.querySelector( '.close' ).addEventListener( 'click', function( event ) {
  1209. closeOverlay();
  1210. event.preventDefault();
  1211. }, false );
  1212. dom.overlay.querySelector( '.external' ).addEventListener( 'click', function( event ) {
  1213. closeOverlay();
  1214. }, false );
  1215. setTimeout( function() {
  1216. dom.overlay.classList.add( 'visible' );
  1217. }, 1 );
  1218. }
  1219. /**
  1220. * Opens an overlay window with help material.
  1221. */
  1222. function showHelp() {
  1223. if( config.help ) {
  1224. closeOverlay();
  1225. dom.overlay = document.createElement( 'div' );
  1226. dom.overlay.classList.add( 'overlay' );
  1227. dom.overlay.classList.add( 'overlay-help' );
  1228. dom.wrapper.appendChild( dom.overlay );
  1229. var html = '<p class="title">Keyboard Shortcuts</p><br/>';
  1230. html += '<table><th>KEY</th><th>ACTION</th>';
  1231. for( var key in keyboardShortcuts ) {
  1232. html += '<tr><td>' + key + '</td><td>' + keyboardShortcuts[ key ] + '</td></tr>';
  1233. }
  1234. html += '</table>';
  1235. dom.overlay.innerHTML = [
  1236. '<header>',
  1237. '<a class="close" href="#"><span class="icon"></span></a>',
  1238. '</header>',
  1239. '<div class="viewport">',
  1240. '<div class="viewport-inner">'+ html +'</div>',
  1241. '</div>'
  1242. ].join('');
  1243. dom.overlay.querySelector( '.close' ).addEventListener( 'click', function( event ) {
  1244. closeOverlay();
  1245. event.preventDefault();
  1246. }, false );
  1247. setTimeout( function() {
  1248. dom.overlay.classList.add( 'visible' );
  1249. }, 1 );
  1250. }
  1251. }
  1252. /**
  1253. * Closes any currently open overlay.
  1254. */
  1255. function closeOverlay() {
  1256. if( dom.overlay ) {
  1257. dom.overlay.parentNode.removeChild( dom.overlay );
  1258. dom.overlay = null;
  1259. }
  1260. }
  1261. /**
  1262. * Applies JavaScript-controlled layout rules to the
  1263. * presentation.
  1264. */
  1265. function layout() {
  1266. if( dom.wrapper && !isPrintingPDF() ) {
  1267. var size = getComputedSlideSize();
  1268. // Layout the contents of the slides
  1269. layoutSlideContents( config.width, config.height );
  1270. dom.slides.style.width = size.width + 'px';
  1271. dom.slides.style.height = size.height + 'px';
  1272. // Determine scale of content to fit within available space
  1273. scale = Math.min( size.presentationWidth / size.width, size.presentationHeight / size.height );
  1274. // Respect max/min scale settings
  1275. scale = Math.max( scale, config.minScale );
  1276. scale = Math.min( scale, config.maxScale );
  1277. // Don't apply any scaling styles if scale is 1
  1278. if( scale === 1 ) {
  1279. dom.slides.style.zoom = '';
  1280. dom.slides.style.left = '';
  1281. dom.slides.style.top = '';
  1282. dom.slides.style.bottom = '';
  1283. dom.slides.style.right = '';
  1284. transformSlides( { layout: '' } );
  1285. }
  1286. else {
  1287. // Prefer zoom for scaling up so that content remains crisp.
  1288. // Don't use zoom to scale down since that can lead to shifts
  1289. // in text layout/line breaks.
  1290. if( scale > 1 && features.zoom ) {
  1291. dom.slides.style.zoom = scale;
  1292. dom.slides.style.left = '';
  1293. dom.slides.style.top = '';
  1294. dom.slides.style.bottom = '';
  1295. dom.slides.style.right = '';
  1296. transformSlides( { layout: '' } );
  1297. }
  1298. // Apply scale transform as a fallback
  1299. else {
  1300. dom.slides.style.zoom = '';
  1301. dom.slides.style.left = '50%';
  1302. dom.slides.style.top = '50%';
  1303. dom.slides.style.bottom = 'auto';
  1304. dom.slides.style.right = 'auto';
  1305. transformSlides( { layout: 'translate(-50%, -50%) scale('+ scale +')' } );
  1306. }
  1307. }
  1308. // Select all slides, vertical and horizontal
  1309. var slides = toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) );
  1310. for( var i = 0, len = slides.length; i < len; i++ ) {
  1311. var slide = slides[ i ];
  1312. // Don't bother updating invisible slides
  1313. if( slide.style.display === 'none' ) {
  1314. continue;
  1315. }
  1316. if( config.center || slide.classList.contains( 'center' ) ) {
  1317. // Vertical stacks are not centred since their section
  1318. // children will be
  1319. if( slide.classList.contains( 'stack' ) ) {
  1320. slide.style.top = 0;
  1321. }
  1322. else {
  1323. slide.style.top = Math.max( ( size.height - slide.scrollHeight ) / 2, 0 ) + 'px';
  1324. }
  1325. }
  1326. else {
  1327. slide.style.top = '';
  1328. }
  1329. }
  1330. updateProgress();
  1331. updateParallax();
  1332. }
  1333. }
  1334. /**
  1335. * Applies layout logic to the contents of all slides in
  1336. * the presentation.
  1337. *
  1338. * @param {string|number} width
  1339. * @param {string|number} height
  1340. */
  1341. function layoutSlideContents( width, height ) {
  1342. // Handle sizing of elements with the 'stretch' class
  1343. toArray( dom.slides.querySelectorAll( 'section > .stretch' ) ).forEach( function( element ) {
  1344. // Determine how much vertical space we can use
  1345. var remainingHeight = getRemainingHeight( element, height );
  1346. // Consider the aspect ratio of media elements
  1347. if( /(img|video)/gi.test( element.nodeName ) ) {
  1348. var nw = element.naturalWidth || element.videoWidth,
  1349. nh = element.naturalHeight || element.videoHeight;
  1350. var es = Math.min( width / nw, remainingHeight / nh );
  1351. element.style.width = ( nw * es ) + 'px';
  1352. element.style.height = ( nh * es ) + 'px';
  1353. }
  1354. else {
  1355. element.style.width = width + 'px';
  1356. element.style.height = remainingHeight + 'px';
  1357. }
  1358. } );
  1359. }
  1360. /**
  1361. * Calculates the computed pixel size of our slides. These
  1362. * values are based on the width and height configuration
  1363. * options.
  1364. *
  1365. * @param {number} [presentationWidth=dom.wrapper.offsetWidth]
  1366. * @param {number} [presentationHeight=dom.wrapper.offsetHeight]
  1367. */
  1368. function getComputedSlideSize( presentationWidth, presentationHeight ) {
  1369. var size = {
  1370. // Slide size
  1371. width: config.width,
  1372. height: config.height,
  1373. // Presentation size
  1374. presentationWidth: presentationWidth || dom.wrapper.offsetWidth,
  1375. presentationHeight: presentationHeight || dom.wrapper.offsetHeight
  1376. };
  1377. // Reduce available space by margin
  1378. size.presentationWidth -= ( size.presentationWidth * config.margin );
  1379. size.presentationHeight -= ( size.presentationHeight * config.margin );
  1380. // Slide width may be a percentage of available width
  1381. if( typeof size.width === 'string' && /%$/.test( size.width ) ) {
  1382. size.width = parseInt( size.width, 10 ) / 100 * size.presentationWidth;
  1383. }
  1384. // Slide height may be a percentage of available height
  1385. if( typeof size.height === 'string' && /%$/.test( size.height ) ) {
  1386. size.height = parseInt( size.height, 10 ) / 100 * size.presentationHeight;
  1387. }
  1388. return size;
  1389. }
  1390. /**
  1391. * Stores the vertical index of a stack so that the same
  1392. * vertical slide can be selected when navigating to and
  1393. * from the stack.
  1394. *
  1395. * @param {HTMLElement} stack The vertical stack element
  1396. * @param {string|number} [v=0] Index to memorize
  1397. */
  1398. function setPreviousVerticalIndex( stack, v ) {
  1399. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
  1400. stack.setAttribute( 'data-previous-indexv', v || 0 );
  1401. }
  1402. }
  1403. /**
  1404. * Retrieves the vertical index which was stored using
  1405. * #setPreviousVerticalIndex() or 0 if no previous index
  1406. * exists.
  1407. *
  1408. * @param {HTMLElement} stack The vertical stack element
  1409. */
  1410. function getPreviousVerticalIndex( stack ) {
  1411. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
  1412. // Prefer manually defined start-indexv
  1413. var attributeName = stack.hasAttribute( 'data-start-indexv' ) ? 'data-start-indexv' : 'data-previous-indexv';
  1414. return parseInt( stack.getAttribute( attributeName ) || 0, 10 );
  1415. }
  1416. return 0;
  1417. }
  1418. /**
  1419. * Displays the overview of slides (quick nav) by scaling
  1420. * down and arranging all slide elements.
  1421. */
  1422. function activateOverview() {
  1423. // Only proceed if enabled in config
  1424. if( config.overview && !isOverview() ) {
  1425. overview = true;
  1426. dom.wrapper.classList.add( 'overview' );
  1427. dom.wrapper.classList.remove( 'overview-deactivating' );
  1428. if( features.overviewTransitions ) {
  1429. setTimeout( function() {
  1430. dom.wrapper.classList.add( 'overview-animated' );
  1431. }, 1 );
  1432. }
  1433. // Don't auto-slide while in overview mode
  1434. cancelAutoSlide();
  1435. // Move the backgrounds element into the slide container to
  1436. // that the same scaling is applied
  1437. dom.slides.appendChild( dom.background );
  1438. // Clicking on an overview slide navigates to it
  1439. toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
  1440. if( !slide.classList.contains( 'stack' ) ) {
  1441. slide.addEventListener( 'click', onOverviewSlideClicked, true );
  1442. }
  1443. } );
  1444. // Calculate slide sizes
  1445. var margin = 70;
  1446. var slideSize = getComputedSlideSize();
  1447. overviewSlideWidth = slideSize.width + margin;
  1448. overviewSlideHeight = slideSize.height + margin;
  1449. // Reverse in RTL mode
  1450. if( config.rtl ) {
  1451. overviewSlideWidth = -overviewSlideWidth;
  1452. }
  1453. updateSlidesVisibility();
  1454. layoutOverview();
  1455. updateOverview();
  1456. layout();
  1457. // Notify observers of the overview showing
  1458. dispatchEvent( 'overviewshown', {
  1459. 'indexh': indexh,
  1460. 'indexv': indexv,
  1461. 'currentSlide': currentSlide
  1462. } );
  1463. }
  1464. }
  1465. /**
  1466. * Uses CSS transforms to position all slides in a grid for
  1467. * display inside of the overview mode.
  1468. */
  1469. function layoutOverview() {
  1470. // Layout slides
  1471. toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).forEach( function( hslide, h ) {
  1472. hslide.setAttribute( 'data-index-h', h );
  1473. transformElement( hslide, 'translate3d(' + ( h * overviewSlideWidth ) + 'px, 0, 0)' );
  1474. if( hslide.classList.contains( 'stack' ) ) {
  1475. toArray( hslide.querySelectorAll( 'section' ) ).forEach( function( vslide, v ) {
  1476. vslide.setAttribute( 'data-index-h', h );
  1477. vslide.setAttribute( 'data-index-v', v );
  1478. transformElement( vslide, 'translate3d(0, ' + ( v * overviewSlideHeight ) + 'px, 0)' );
  1479. } );
  1480. }
  1481. } );
  1482. // Layout slide backgrounds
  1483. toArray( dom.background.childNodes ).forEach( function( hbackground, h ) {
  1484. transformElement( hbackground, 'translate3d(' + ( h * overviewSlideWidth ) + 'px, 0, 0)' );
  1485. toArray( hbackground.querySelectorAll( '.slide-background' ) ).forEach( function( vbackground, v ) {
  1486. transformElement( vbackground, 'translate3d(0, ' + ( v * overviewSlideHeight ) + 'px, 0)' );
  1487. } );
  1488. } );
  1489. }
  1490. /**
  1491. * Moves the overview viewport to the current slides.
  1492. * Called each time the current slide changes.
  1493. */
  1494. function updateOverview() {
  1495. transformSlides( {
  1496. overview: [
  1497. 'translateX('+ ( -indexh * overviewSlideWidth ) +'px)',
  1498. 'translateY('+ ( -indexv * overviewSlideHeight ) +'px)',
  1499. 'translateZ('+ ( window.innerWidth < 400 ? -1000 : -2500 ) +'px)'
  1500. ].join( ' ' )
  1501. } );
  1502. }
  1503. /**
  1504. * Exits the slide overview and enters the currently
  1505. * active slide.
  1506. */
  1507. function deactivateOverview() {
  1508. // Only proceed if enabled in config
  1509. if( config.overview ) {
  1510. overview = false;
  1511. dom.wrapper.classList.remove( 'overview' );
  1512. dom.wrapper.classList.remove( 'overview-animated' );
  1513. // Temporarily add a class so that transitions can do different things
  1514. // depending on whether they are exiting/entering overview, or just
  1515. // moving from slide to slide
  1516. dom.wrapper.classList.add( 'overview-deactivating' );
  1517. setTimeout( function () {
  1518. dom.wrapper.classList.remove( 'overview-deactivating' );
  1519. }, 1 );
  1520. // Move the background element back out
  1521. dom.wrapper.appendChild( dom.background );
  1522. // Clean up changes made to slides
  1523. toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
  1524. transformElement( slide, '' );
  1525. slide.removeEventListener( 'click', onOverviewSlideClicked, true );
  1526. } );
  1527. // Clean up changes made to backgrounds
  1528. toArray( dom.background.querySelectorAll( '.slide-background' ) ).forEach( function( background ) {
  1529. transformElement( background, '' );
  1530. } );
  1531. transformSlides( { overview: '' } );
  1532. slide( indexh, indexv );
  1533. layout();
  1534. cueAutoSlide();
  1535. // Notify observers of the overview hiding
  1536. dispatchEvent( 'overviewhidden', {
  1537. 'indexh': indexh,
  1538. 'indexv': indexv,
  1539. 'currentSlide': currentSlide
  1540. } );
  1541. }
  1542. }
  1543. /**
  1544. * Toggles the slide overview mode on and off.
  1545. *
  1546. * @param {Boolean} [override] Flag which overrides the
  1547. * toggle logic and forcibly sets the desired state. True means
  1548. * overview is open, false means it's closed.
  1549. */
  1550. function toggleOverview( override ) {
  1551. if( typeof override === 'boolean' ) {
  1552. override ? activateOverview() : deactivateOverview();
  1553. }
  1554. else {
  1555. isOverview() ? deactivateOverview() : activateOverview();
  1556. }
  1557. }
  1558. /**
  1559. * Checks if the overview is currently active.
  1560. *
  1561. * @return {Boolean} true if the overview is active,
  1562. * false otherwise
  1563. */
  1564. function isOverview() {
  1565. return overview;
  1566. }
  1567. /**
  1568. * Checks if the current or specified slide is vertical
  1569. * (nested within another slide).
  1570. *
  1571. * @param {HTMLElement} [slide=currentSlide] The slide to check
  1572. * orientation of
  1573. * @return {Boolean}
  1574. */
  1575. function isVerticalSlide( slide ) {
  1576. // Prefer slide argument, otherwise use current slide
  1577. slide = slide ? slide : currentSlide;
  1578. return slide && slide.parentNode && !!slide.parentNode.nodeName.match( /section/i );
  1579. }
  1580. /**
  1581. * Handling the fullscreen functionality via the fullscreen API
  1582. *
  1583. * @see http://fullscreen.spec.whatwg.org/
  1584. * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
  1585. */
  1586. function enterFullscreen() {
  1587. var element = document.documentElement;
  1588. // Check which implementation is available
  1589. var requestMethod = element.requestFullscreen ||
  1590. element.webkitRequestFullscreen ||
  1591. element.webkitRequestFullScreen ||
  1592. element.mozRequestFullScreen ||
  1593. element.msRequestFullscreen;
  1594. if( requestMethod ) {
  1595. requestMethod.apply( element );
  1596. }
  1597. }
  1598. /**
  1599. * Enters the paused mode which fades everything on screen to
  1600. * black.
  1601. */
  1602. function pause() {
  1603. if( config.pause ) {
  1604. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1605. cancelAutoSlide();
  1606. dom.wrapper.classList.add( 'paused' );
  1607. if( wasPaused === false ) {
  1608. dispatchEvent( 'paused' );
  1609. }
  1610. }
  1611. }
  1612. /**
  1613. * Exits from the paused mode.
  1614. */
  1615. function resume() {
  1616. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1617. dom.wrapper.classList.remove( 'paused' );
  1618. cueAutoSlide();
  1619. if( wasPaused ) {
  1620. dispatchEvent( 'resumed' );
  1621. }
  1622. }
  1623. /**
  1624. * Toggles the paused mode on and off.
  1625. */
  1626. function togglePause( override ) {
  1627. if( typeof override === 'boolean' ) {
  1628. override ? pause() : resume();
  1629. }
  1630. else {
  1631. isPaused() ? resume() : pause();
  1632. }
  1633. }
  1634. /**
  1635. * Checks if we are currently in the paused mode.
  1636. *
  1637. * @return {Boolean}
  1638. */
  1639. function isPaused() {
  1640. return dom.wrapper.classList.contains( 'paused' );
  1641. }
  1642. /**
  1643. * Toggles the auto slide mode on and off.
  1644. *
  1645. * @param {Boolean} [override] Flag which sets the desired state.
  1646. * True means autoplay starts, false means it stops.
  1647. */
  1648. function toggleAutoSlide( override ) {
  1649. if( typeof override === 'boolean' ) {
  1650. override ? resumeAutoSlide() : pauseAutoSlide();
  1651. }
  1652. else {
  1653. autoSlidePaused ? resumeAutoSlide() : pauseAutoSlide();
  1654. }
  1655. }
  1656. /**
  1657. * Checks if the auto slide mode is currently on.
  1658. *
  1659. * @return {Boolean}
  1660. */
  1661. function isAutoSliding() {
  1662. return !!( autoSlide && !autoSlidePaused );
  1663. }
  1664. /**
  1665. * Steps from the current point in the presentation to the
  1666. * slide which matches the specified horizontal and vertical
  1667. * indices.
  1668. *
  1669. * @param {number} [h=indexh] Horizontal index of the target slide
  1670. * @param {number} [v=indexv] Vertical index of the target slide
  1671. * @param {number} [f] Index of a fragment within the
  1672. * target slide to activate
  1673. * @param {number} [o] Origin for use in multimaster environments
  1674. */
  1675. function slide( h, v, f, o ) {
  1676. // Remember where we were at before
  1677. previousSlide = currentSlide;
  1678. // Query all horizontal slides in the deck
  1679. var horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  1680. // If no vertical index is specified and the upcoming slide is a
  1681. // stack, resume at its previous vertical index
  1682. if( v === undefined && !isOverview() ) {
  1683. v = getPreviousVerticalIndex( horizontalSlides[ h ] );
  1684. }
  1685. // If we were on a vertical stack, remember what vertical index
  1686. // it was on so we can resume at the same position when returning
  1687. if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
  1688. setPreviousVerticalIndex( previousSlide.parentNode, indexv );
  1689. }
  1690. // Remember the state before this slide
  1691. var stateBefore = state.concat();
  1692. // Reset the state array
  1693. state.length = 0;
  1694. var indexhBefore = indexh || 0,
  1695. indexvBefore = indexv || 0;
  1696. // Activate and transition to the new slide
  1697. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
  1698. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
  1699. // Update the visibility of slides now that the indices have changed
  1700. updateSlidesVisibility();
  1701. layout();
  1702. // Apply the new state
  1703. stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
  1704. // Check if this state existed on the previous slide. If it
  1705. // did, we will avoid adding it repeatedly
  1706. for( var j = 0; j < stateBefore.length; j++ ) {
  1707. if( stateBefore[j] === state[i] ) {
  1708. stateBefore.splice( j, 1 );
  1709. continue stateLoop;
  1710. }
  1711. }
  1712. document.documentElement.classList.add( state[i] );
  1713. // Dispatch custom event matching the state's name
  1714. dispatchEvent( state[i] );
  1715. }
  1716. // Clean up the remains of the previous state
  1717. while( stateBefore.length ) {
  1718. document.documentElement.classList.remove( stateBefore.pop() );
  1719. }
  1720. // Update the overview if it's currently active
  1721. if( isOverview() ) {
  1722. updateOverview();
  1723. }
  1724. // Find the current horizontal slide and any possible vertical slides
  1725. // within it
  1726. var currentHorizontalSlide = horizontalSlides[ indexh ],
  1727. currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
  1728. // Store references to the previous and current slides
  1729. currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
  1730. // Show fragment, if specified
  1731. if( typeof f !== 'undefined' ) {
  1732. navigateFragment( f );
  1733. }
  1734. // Dispatch an event if the slide changed
  1735. var slideChanged = ( indexh !== indexhBefore || indexv !== indexvBefore );
  1736. if( slideChanged ) {
  1737. dispatchEvent( 'slidechanged', {
  1738. 'indexh': indexh,
  1739. 'indexv': indexv,
  1740. 'previousSlide': previousSlide,
  1741. 'currentSlide': currentSlide,
  1742. 'origin': o
  1743. } );
  1744. }
  1745. else {
  1746. // Ensure that the previous slide is never the same as the current
  1747. previousSlide = null;
  1748. }
  1749. // Solves an edge case where the previous slide maintains the
  1750. // 'present' class when navigating between adjacent vertical
  1751. // stacks
  1752. if( previousSlide ) {
  1753. previousSlide.classList.remove( 'present' );
  1754. previousSlide.setAttribute( 'aria-hidden', 'true' );
  1755. // Reset all slides upon navigate to home
  1756. // Issue: #285
  1757. if ( dom.wrapper.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
  1758. // Launch async task
  1759. setTimeout( function () {
  1760. var slides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
  1761. for( i in slides ) {
  1762. if( slides[i] ) {
  1763. // Reset stack
  1764. setPreviousVerticalIndex( slides[i], 0 );
  1765. }
  1766. }
  1767. }, 0 );
  1768. }
  1769. }
  1770. // Handle embedded content
  1771. if( slideChanged || !previousSlide ) {
  1772. stopEmbeddedContent( previousSlide );
  1773. startEmbeddedContent( currentSlide );
  1774. }
  1775. // Announce the current slide contents, for screen readers
  1776. dom.statusDiv.textContent = currentSlide.textContent;
  1777. updateControls();
  1778. updateProgress();
  1779. updateBackground();
  1780. updateParallax();
  1781. updateSlideNumber();
  1782. updateNotes();
  1783. // Update the URL hash
  1784. writeURL();
  1785. cueAutoSlide();
  1786. }
  1787. /**
  1788. * Syncs the presentation with the current DOM. Useful
  1789. * when new slides or control elements are added or when
  1790. * the configuration has changed.
  1791. */
  1792. function sync() {
  1793. // Subscribe to input
  1794. removeEventListeners();
  1795. addEventListeners();
  1796. // Force a layout to make sure the current config is accounted for
  1797. layout();
  1798. // Reflect the current autoSlide value
  1799. autoSlide = config.autoSlide;
  1800. // Start auto-sliding if it's enabled
  1801. cueAutoSlide();
  1802. // Re-create the slide backgrounds
  1803. createBackgrounds();
  1804. // Write the current hash to the URL
  1805. writeURL();
  1806. sortAllFragments();
  1807. updateControls();
  1808. updateProgress();
  1809. updateBackground( true );
  1810. updateSlideNumber();
  1811. updateSlidesVisibility();
  1812. updateNotes();
  1813. formatEmbeddedContent();
  1814. startEmbeddedContent( currentSlide );
  1815. if( isOverview() ) {
  1816. layoutOverview();
  1817. }
  1818. }
  1819. /**
  1820. * Resets all vertical slides so that only the first
  1821. * is visible.
  1822. */
  1823. function resetVerticalSlides() {
  1824. var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1825. horizontalSlides.forEach( function( horizontalSlide ) {
  1826. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1827. verticalSlides.forEach( function( verticalSlide, y ) {
  1828. if( y > 0 ) {
  1829. verticalSlide.classList.remove( 'present' );
  1830. verticalSlide.classList.remove( 'past' );
  1831. verticalSlide.classList.add( 'future' );
  1832. verticalSlide.setAttribute( 'aria-hidden', 'true' );
  1833. }
  1834. } );
  1835. } );
  1836. }
  1837. /**
  1838. * Sorts and formats all of fragments in the
  1839. * presentation.
  1840. */
  1841. function sortAllFragments() {
  1842. var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1843. horizontalSlides.forEach( function( horizontalSlide ) {
  1844. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1845. verticalSlides.forEach( function( verticalSlide, y ) {
  1846. sortFragments( verticalSlide.querySelectorAll( '.fragment' ) );
  1847. } );
  1848. if( verticalSlides.length === 0 ) sortFragments( horizontalSlide.querySelectorAll( '.fragment' ) );
  1849. } );
  1850. }
  1851. /**
  1852. * Randomly shuffles all slides in the deck.
  1853. */
  1854. function shuffle() {
  1855. var slides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1856. slides.forEach( function( slide ) {
  1857. // Insert this slide next to another random slide. This may
  1858. // cause the slide to insert before itself but that's fine.
  1859. dom.slides.insertBefore( slide, slides[ Math.floor( Math.random() * slides.length ) ] );
  1860. } );
  1861. }
  1862. /**
  1863. * Updates one dimension of slides by showing the slide
  1864. * with the specified index.
  1865. *
  1866. * @param {string} selector A CSS selector that will fetch
  1867. * the group of slides we are working with
  1868. * @param {number} index The index of the slide that should be
  1869. * shown
  1870. *
  1871. * @return {number} The index of the slide that is now shown,
  1872. * might differ from the passed in index if it was out of
  1873. * bounds.
  1874. */
  1875. function updateSlides( selector, index ) {
  1876. // Select all slides and convert the NodeList result to
  1877. // an array
  1878. var slides = toArray( dom.wrapper.querySelectorAll( selector ) ),
  1879. slidesLength = slides.length;
  1880. var printMode = isPrintingPDF();
  1881. if( slidesLength ) {
  1882. // Should the index loop?
  1883. if( config.loop ) {
  1884. index %= slidesLength;
  1885. if( index < 0 ) {
  1886. index = slidesLength + index;
  1887. }
  1888. }
  1889. // Enforce max and minimum index bounds
  1890. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  1891. for( var i = 0; i < slidesLength; i++ ) {
  1892. var element = slides[i];
  1893. var reverse = config.rtl && !isVerticalSlide( element );
  1894. element.classList.remove( 'past' );
  1895. element.classList.remove( 'present' );
  1896. element.classList.remove( 'future' );
  1897. // http://www.w3.org/html/wg/drafts/html/master/editing.html#the-hidden-attribute
  1898. element.setAttribute( 'hidden', '' );
  1899. element.setAttribute( 'aria-hidden', 'true' );
  1900. // If this element contains vertical slides
  1901. if( element.querySelector( 'section' ) ) {
  1902. element.classList.add( 'stack' );
  1903. }
  1904. // If we're printing static slides, all slides are "present"
  1905. if( printMode ) {
  1906. element.classList.add( 'present' );
  1907. continue;
  1908. }
  1909. if( i < index ) {
  1910. // Any element previous to index is given the 'past' class
  1911. element.classList.add( reverse ? 'future' : 'past' );
  1912. if( config.fragments ) {
  1913. var pastFragments = toArray( element.querySelectorAll( '.fragment' ) );
  1914. // Show all fragments on prior slides
  1915. while( pastFragments.length ) {
  1916. var pastFragment = pastFragments.pop();
  1917. pastFragment.classList.add( 'visible' );
  1918. pastFragment.classList.remove( 'current-fragment' );
  1919. }
  1920. }
  1921. }
  1922. else if( i > index ) {
  1923. // Any element subsequent to index is given the 'future' class
  1924. element.classList.add( reverse ? 'past' : 'future' );
  1925. if( config.fragments ) {
  1926. var futureFragments = toArray( element.querySelectorAll( '.fragment.visible' ) );
  1927. // No fragments in future slides should be visible ahead of time
  1928. while( futureFragments.length ) {
  1929. var futureFragment = futureFragments.pop();
  1930. futureFragment.classList.remove( 'visible' );
  1931. futureFragment.classList.remove( 'current-fragment' );
  1932. }
  1933. }
  1934. }
  1935. }
  1936. // Mark the current slide as present
  1937. slides[index].classList.add( 'present' );
  1938. slides[index].removeAttribute( 'hidden' );
  1939. slides[index].removeAttribute( 'aria-hidden' );
  1940. // If this slide has a state associated with it, add it
  1941. // onto the current state of the deck
  1942. var slideState = slides[index].getAttribute( 'data-state' );
  1943. if( slideState ) {
  1944. state = state.concat( slideState.split( ' ' ) );
  1945. }
  1946. }
  1947. else {
  1948. // Since there are no slides we can't be anywhere beyond the
  1949. // zeroth index
  1950. index = 0;
  1951. }
  1952. return index;
  1953. }
  1954. /**
  1955. * Optimization method; hide all slides that are far away
  1956. * from the present slide.
  1957. */
  1958. function updateSlidesVisibility() {
  1959. // Select all slides and convert the NodeList result to
  1960. // an array
  1961. var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ),
  1962. horizontalSlidesLength = horizontalSlides.length,
  1963. distanceX,
  1964. distanceY;
  1965. if( horizontalSlidesLength && typeof indexh !== 'undefined' ) {
  1966. // The number of steps away from the present slide that will
  1967. // be visible
  1968. var viewDistance = isOverview() ? 10 : config.viewDistance;
  1969. // Limit view distance on weaker devices
  1970. if( isMobileDevice ) {
  1971. viewDistance = isOverview() ? 6 : 2;
  1972. }
  1973. // All slides need to be visible when exporting to PDF
  1974. if( isPrintingPDF() ) {
  1975. viewDistance = Number.MAX_VALUE;
  1976. }
  1977. for( var x = 0; x < horizontalSlidesLength; x++ ) {
  1978. var horizontalSlide = horizontalSlides[x];
  1979. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) ),
  1980. verticalSlidesLength = verticalSlides.length;
  1981. // Determine how far away this slide is from the present
  1982. distanceX = Math.abs( ( indexh || 0 ) - x ) || 0;
  1983. // If the presentation is looped, distance should measure
  1984. // 1 between the first and last slides
  1985. if( config.loop ) {
  1986. distanceX = Math.abs( ( ( indexh || 0 ) - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0;
  1987. }
  1988. // Show the horizontal slide if it's within the view distance
  1989. if( distanceX < viewDistance ) {
  1990. showSlide( horizontalSlide );
  1991. }
  1992. else {
  1993. hideSlide( horizontalSlide );
  1994. }
  1995. if( verticalSlidesLength ) {
  1996. var oy = getPreviousVerticalIndex( horizontalSlide );
  1997. for( var y = 0; y < verticalSlidesLength; y++ ) {
  1998. var verticalSlide = verticalSlides[y];
  1999. distanceY = x === ( indexh || 0 ) ? Math.abs( ( indexv || 0 ) - y ) : Math.abs( y - oy );
  2000. if( distanceX + distanceY < viewDistance ) {
  2001. showSlide( verticalSlide );
  2002. }
  2003. else {
  2004. hideSlide( verticalSlide );
  2005. }
  2006. }
  2007. }
  2008. }
  2009. }
  2010. }
  2011. /**
  2012. * Pick up notes from the current slide and display them
  2013. * to the viewer.
  2014. *
  2015. * @see {@link config.showNotes}
  2016. */
  2017. function updateNotes() {
  2018. if( config.showNotes && dom.speakerNotes && currentSlide && !isPrintingPDF() ) {
  2019. dom.speakerNotes.innerHTML = getSlideNotes() || '';
  2020. }
  2021. }
  2022. /**
  2023. * Updates the progress bar to reflect the current slide.
  2024. */
  2025. function updateProgress() {
  2026. // Update progress if enabled
  2027. if( config.progress && dom.progressbar ) {
  2028. dom.progressbar.style.width = getProgress() * dom.wrapper.offsetWidth + 'px';
  2029. }
  2030. }
  2031. /**
  2032. * Updates the slide number div to reflect the current slide.
  2033. *
  2034. * The following slide number formats are available:
  2035. * "h.v": horizontal . vertical slide number (default)
  2036. * "h/v": horizontal / vertical slide number
  2037. * "c": flattened slide number
  2038. * "c/t": flattened slide number / total slides
  2039. */
  2040. function updateSlideNumber() {
  2041. // Update slide number if enabled
  2042. if( config.slideNumber && dom.slideNumber ) {
  2043. var value = [];
  2044. var format = 'h.v';
  2045. // Check if a custom number format is available
  2046. if( typeof config.slideNumber === 'string' ) {
  2047. format = config.slideNumber;
  2048. }
  2049. switch( format ) {
  2050. case 'c':
  2051. value.push( getSlidePastCount() + 1 );
  2052. break;
  2053. case 'c/t':
  2054. value.push( getSlidePastCount() + 1, '/', getTotalSlides() );
  2055. break;
  2056. case 'h/v':
  2057. value.push( indexh + 1 );
  2058. if( isVerticalSlide() ) value.push( '/', indexv + 1 );
  2059. break;
  2060. default:
  2061. value.push( indexh + 1 );
  2062. if( isVerticalSlide() ) value.push( '.', indexv + 1 );
  2063. }
  2064. dom.slideNumber.innerHTML = formatSlideNumber( value[0], value[1], value[2] );
  2065. }
  2066. }
  2067. /**
  2068. * Applies HTML formatting to a slide number before it's
  2069. * written to the DOM.
  2070. *
  2071. * @param {number} a Current slide
  2072. * @param {string} delimiter Character to separate slide numbers
  2073. * @param {(number|*)} b Total slides
  2074. * @return {string} HTML string fragment
  2075. */
  2076. function formatSlideNumber( a, delimiter, b ) {
  2077. if( typeof b === 'number' && !isNaN( b ) ) {
  2078. return '<span class="slide-number-a">'+ a +'</span>' +
  2079. '<span class="slide-number-delimiter">'+ delimiter +'</span>' +
  2080. '<span class="slide-number-b">'+ b +'</span>';
  2081. }
  2082. else {
  2083. return '<span class="slide-number-a">'+ a +'</span>';
  2084. }
  2085. }
  2086. /**
  2087. * Updates the state of all control/navigation arrows.
  2088. */
  2089. function updateControls() {
  2090. var routes = availableRoutes();
  2091. var fragments = availableFragments();
  2092. // Remove the 'enabled' class from all directions
  2093. dom.controlsLeft.concat( dom.controlsRight )
  2094. .concat( dom.controlsUp )
  2095. .concat( dom.controlsDown )
  2096. .concat( dom.controlsPrev )
  2097. .concat( dom.controlsNext ).forEach( function( node ) {
  2098. node.classList.remove( 'enabled' );
  2099. node.classList.remove( 'fragmented' );
  2100. // Set 'disabled' attribute on all directions
  2101. node.setAttribute( 'disabled', 'disabled' );
  2102. } );
  2103. // Add the 'enabled' class to the available routes; remove 'disabled' attribute to enable buttons
  2104. if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2105. if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2106. if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2107. if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2108. // Prev/next buttons
  2109. if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2110. if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2111. // Highlight fragment directions
  2112. if( currentSlide ) {
  2113. // Always apply fragment decorator to prev/next buttons
  2114. if( fragments.prev ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2115. if( fragments.next ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2116. // Apply fragment decorators to directional buttons based on
  2117. // what slide axis they are in
  2118. if( isVerticalSlide( currentSlide ) ) {
  2119. if( fragments.prev ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2120. if( fragments.next ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2121. }
  2122. else {
  2123. if( fragments.prev ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2124. if( fragments.next ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); el.removeAttribute( 'disabled' ); } );
  2125. }
  2126. }
  2127. }
  2128. /**
  2129. * Updates the background elements to reflect the current
  2130. * slide.
  2131. *
  2132. * @param {boolean} includeAll If true, the backgrounds of
  2133. * all vertical slides (not just the present) will be updated.
  2134. */
  2135. function updateBackground( includeAll ) {
  2136. var currentBackground = null;
  2137. // Reverse past/future classes when in RTL mode
  2138. var horizontalPast = config.rtl ? 'future' : 'past',
  2139. horizontalFuture = config.rtl ? 'past' : 'future';
  2140. // Update the classes of all backgrounds to match the
  2141. // states of their slides (past/present/future)
  2142. toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) {
  2143. backgroundh.classList.remove( 'past' );
  2144. backgroundh.classList.remove( 'present' );
  2145. backgroundh.classList.remove( 'future' );
  2146. if( h < indexh ) {
  2147. backgroundh.classList.add( horizontalPast );
  2148. }
  2149. else if ( h > indexh ) {
  2150. backgroundh.classList.add( horizontalFuture );
  2151. }
  2152. else {
  2153. backgroundh.classList.add( 'present' );
  2154. // Store a reference to the current background element
  2155. currentBackground = backgroundh;
  2156. }
  2157. if( includeAll || h === indexh ) {
  2158. toArray( backgroundh.querySelectorAll( '.slide-background' ) ).forEach( function( backgroundv, v ) {
  2159. backgroundv.classList.remove( 'past' );
  2160. backgroundv.classList.remove( 'present' );
  2161. backgroundv.classList.remove( 'future' );
  2162. if( v < indexv ) {
  2163. backgroundv.classList.add( 'past' );
  2164. }
  2165. else if ( v > indexv ) {
  2166. backgroundv.classList.add( 'future' );
  2167. }
  2168. else {
  2169. backgroundv.classList.add( 'present' );
  2170. // Only if this is the present horizontal and vertical slide
  2171. if( h === indexh ) currentBackground = backgroundv;
  2172. }
  2173. } );
  2174. }
  2175. } );
  2176. // Stop any currently playing video background
  2177. if( previousBackground ) {
  2178. var previousVideo = previousBackground.querySelector( 'video' );
  2179. if( previousVideo ) previousVideo.pause();
  2180. }
  2181. if( currentBackground ) {
  2182. // Start video playback
  2183. var currentVideo = currentBackground.querySelector( 'video' );
  2184. if( currentVideo ) {
  2185. var startVideo = function() {
  2186. currentVideo.currentTime = 0;
  2187. currentVideo.play();
  2188. currentVideo.removeEventListener( 'loadeddata', startVideo );
  2189. };
  2190. if( currentVideo.readyState > 1 ) {
  2191. startVideo();
  2192. }
  2193. else {
  2194. currentVideo.addEventListener( 'loadeddata', startVideo );
  2195. }
  2196. }
  2197. var backgroundImageURL = currentBackground.style.backgroundImage || '';
  2198. // Restart GIFs (doesn't work in Firefox)
  2199. if( /\.gif/i.test( backgroundImageURL ) ) {
  2200. currentBackground.style.backgroundImage = '';
  2201. window.getComputedStyle( currentBackground ).opacity;
  2202. currentBackground.style.backgroundImage = backgroundImageURL;
  2203. }
  2204. // Don't transition between identical backgrounds. This
  2205. // prevents unwanted flicker.
  2206. var previousBackgroundHash = previousBackground ? previousBackground.getAttribute( 'data-background-hash' ) : null;
  2207. var currentBackgroundHash = currentBackground.getAttribute( 'data-background-hash' );
  2208. if( currentBackgroundHash && currentBackgroundHash === previousBackgroundHash && currentBackground !== previousBackground ) {
  2209. dom.background.classList.add( 'no-transition' );
  2210. }
  2211. previousBackground = currentBackground;
  2212. }
  2213. // If there's a background brightness flag for this slide,
  2214. // bubble it to the .reveal container
  2215. if( currentSlide ) {
  2216. [ 'has-light-background', 'has-dark-background' ].forEach( function( classToBubble ) {
  2217. if( currentSlide.classList.contains( classToBubble ) ) {
  2218. dom.wrapper.classList.add( classToBubble );
  2219. }
  2220. else {
  2221. dom.wrapper.classList.remove( classToBubble );
  2222. }
  2223. } );
  2224. }
  2225. // Allow the first background to apply without transition
  2226. setTimeout( function() {
  2227. dom.background.classList.remove( 'no-transition' );
  2228. }, 1 );
  2229. }
  2230. /**
  2231. * Updates the position of the parallax background based
  2232. * on the current slide index.
  2233. */
  2234. function updateParallax() {
  2235. if( config.parallaxBackgroundImage ) {
  2236. var horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  2237. verticalSlides = dom.wrapper.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  2238. var backgroundSize = dom.background.style.backgroundSize.split( ' ' ),
  2239. backgroundWidth, backgroundHeight;
  2240. if( backgroundSize.length === 1 ) {
  2241. backgroundWidth = backgroundHeight = parseInt( backgroundSize[0], 10 );
  2242. }
  2243. else {
  2244. backgroundWidth = parseInt( backgroundSize[0], 10 );
  2245. backgroundHeight = parseInt( backgroundSize[1], 10 );
  2246. }
  2247. var slideWidth = dom.background.offsetWidth,
  2248. horizontalSlideCount = horizontalSlides.length,
  2249. horizontalOffsetMultiplier,
  2250. horizontalOffset;
  2251. if( typeof config.parallaxBackgroundHorizontal === 'number' ) {
  2252. horizontalOffsetMultiplier = config.parallaxBackgroundHorizontal;
  2253. }
  2254. else {
  2255. horizontalOffsetMultiplier = horizontalSlideCount > 1 ? ( backgroundWidth - slideWidth ) / ( horizontalSlideCount-1 ) : 0;
  2256. }
  2257. horizontalOffset = horizontalOffsetMultiplier * indexh * -1;
  2258. var slideHeight = dom.background.offsetHeight,
  2259. verticalSlideCount = verticalSlides.length,
  2260. verticalOffsetMultiplier,
  2261. verticalOffset;
  2262. if( typeof config.parallaxBackgroundVertical === 'number' ) {
  2263. verticalOffsetMultiplier = config.parallaxBackgroundVertical;
  2264. }
  2265. else {
  2266. verticalOffsetMultiplier = ( backgroundHeight - slideHeight ) / ( verticalSlideCount-1 );
  2267. }
  2268. verticalOffset = verticalSlideCount > 0 ? verticalOffsetMultiplier * indexv : 0;
  2269. dom.background.style.backgroundPosition = horizontalOffset + 'px ' + -verticalOffset + 'px';
  2270. }
  2271. }
  2272. /**
  2273. * Called when the given slide is within the configured view
  2274. * distance. Shows the slide element and loads any content
  2275. * that is set to load lazily (data-src).
  2276. *
  2277. * @param {HTMLElement} slide Slide to show
  2278. */
  2279. function showSlide( slide ) {
  2280. // Show the slide element
  2281. slide.style.display = 'block';
  2282. // Media elements with data-src attributes
  2283. toArray( slide.querySelectorAll( 'img[data-src], video[data-src], audio[data-src]' ) ).forEach( function( element ) {
  2284. element.setAttribute( 'src', element.getAttribute( 'data-src' ) );
  2285. element.removeAttribute( 'data-src' );
  2286. } );
  2287. // Media elements with <source> children
  2288. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( media ) {
  2289. var sources = 0;
  2290. toArray( media.querySelectorAll( 'source[data-src]' ) ).forEach( function( source ) {
  2291. source.setAttribute( 'src', source.getAttribute( 'data-src' ) );
  2292. source.removeAttribute( 'data-src' );
  2293. sources += 1;
  2294. } );
  2295. // If we rewrote sources for this video/audio element, we need
  2296. // to manually tell it to load from its new origin
  2297. if( sources > 0 ) {
  2298. media.load();
  2299. }
  2300. } );
  2301. // Show the corresponding background element
  2302. var indices = getIndices( slide );
  2303. var background = getSlideBackground( indices.h, indices.v );
  2304. if( background ) {
  2305. background.style.display = 'block';
  2306. // If the background contains media, load it
  2307. if( background.hasAttribute( 'data-loaded' ) === false ) {
  2308. background.setAttribute( 'data-loaded', 'true' );
  2309. var backgroundImage = slide.getAttribute( 'data-background-image' ),
  2310. backgroundVideo = slide.getAttribute( 'data-background-video' ),
  2311. backgroundVideoLoop = slide.hasAttribute( 'data-background-video-loop' ),
  2312. backgroundVideoMuted = slide.hasAttribute( 'data-background-video-muted' ),
  2313. backgroundIframe = slide.getAttribute( 'data-background-iframe' );
  2314. // Images
  2315. if( backgroundImage ) {
  2316. background.style.backgroundImage = 'url('+ backgroundImage +')';
  2317. }
  2318. // Videos
  2319. else if ( backgroundVideo && !isSpeakerNotes() ) {
  2320. var video = document.createElement( 'video' );
  2321. if( backgroundVideoLoop ) {
  2322. video.setAttribute( 'loop', '' );
  2323. }
  2324. if( backgroundVideoMuted ) {
  2325. video.muted = true;
  2326. }
  2327. // Support comma separated lists of video sources
  2328. backgroundVideo.split( ',' ).forEach( function( source ) {
  2329. video.innerHTML += '<source src="'+ source +'">';
  2330. } );
  2331. background.appendChild( video );
  2332. }
  2333. // Iframes
  2334. else if( backgroundIframe ) {
  2335. var iframe = document.createElement( 'iframe' );
  2336. iframe.setAttribute( 'src', backgroundIframe );
  2337. iframe.style.width = '100%';
  2338. iframe.style.height = '100%';
  2339. iframe.style.maxHeight = '100%';
  2340. iframe.style.maxWidth = '100%';
  2341. background.appendChild( iframe );
  2342. }
  2343. }
  2344. }
  2345. }
  2346. /**
  2347. * Called when the given slide is moved outside of the
  2348. * configured view distance.
  2349. *
  2350. * @param {HTMLElement} slide
  2351. */
  2352. function hideSlide( slide ) {
  2353. // Hide the slide element
  2354. slide.style.display = 'none';
  2355. // Hide the corresponding background element
  2356. var indices = getIndices( slide );
  2357. var background = getSlideBackground( indices.h, indices.v );
  2358. if( background ) {
  2359. background.style.display = 'none';
  2360. }
  2361. }
  2362. /**
  2363. * Determine what available routes there are for navigation.
  2364. *
  2365. * @return {{left: boolean, right: boolean, up: boolean, down: boolean}}
  2366. */
  2367. function availableRoutes() {
  2368. var horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  2369. verticalSlides = dom.wrapper.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  2370. var routes = {
  2371. left: indexh > 0 || config.loop,
  2372. right: indexh < horizontalSlides.length - 1 || config.loop,
  2373. up: indexv > 0,
  2374. down: indexv < verticalSlides.length - 1
  2375. };
  2376. // reverse horizontal controls for rtl
  2377. if( config.rtl ) {
  2378. var left = routes.left;
  2379. routes.left = routes.right;
  2380. routes.right = left;
  2381. }
  2382. return routes;
  2383. }
  2384. /**
  2385. * Returns an object describing the available fragment
  2386. * directions.
  2387. *
  2388. * @return {{prev: boolean, next: boolean}}
  2389. */
  2390. function availableFragments() {
  2391. if( currentSlide && config.fragments ) {
  2392. var fragments = currentSlide.querySelectorAll( '.fragment' );
  2393. var hiddenFragments = currentSlide.querySelectorAll( '.fragment:not(.visible)' );
  2394. return {
  2395. prev: fragments.length - hiddenFragments.length > 0,
  2396. next: !!hiddenFragments.length
  2397. };
  2398. }
  2399. else {
  2400. return { prev: false, next: false };
  2401. }
  2402. }
  2403. /**
  2404. * Enforces origin-specific format rules for embedded media.
  2405. */
  2406. function formatEmbeddedContent() {
  2407. var _appendParamToIframeSource = function( sourceAttribute, sourceURL, param ) {
  2408. toArray( dom.slides.querySelectorAll( 'iframe['+ sourceAttribute +'*="'+ sourceURL +'"]' ) ).forEach( function( el ) {
  2409. var src = el.getAttribute( sourceAttribute );
  2410. if( src && src.indexOf( param ) === -1 ) {
  2411. el.setAttribute( sourceAttribute, src + ( !/\?/.test( src ) ? '?' : '&' ) + param );
  2412. }
  2413. });
  2414. };
  2415. // YouTube frames must include "?enablejsapi=1"
  2416. _appendParamToIframeSource( 'src', 'youtube.com/embed/', 'enablejsapi=1' );
  2417. _appendParamToIframeSource( 'data-src', 'youtube.com/embed/', 'enablejsapi=1' );
  2418. // Vimeo frames must include "?api=1"
  2419. _appendParamToIframeSource( 'src', 'player.vimeo.com/', 'api=1' );
  2420. _appendParamToIframeSource( 'data-src', 'player.vimeo.com/', 'api=1' );
  2421. }
  2422. /**
  2423. * Start playback of any embedded content inside of
  2424. * the targeted slide.
  2425. *
  2426. * @param {HTMLElement} slide
  2427. */
  2428. function startEmbeddedContent( slide ) {
  2429. if( slide && !isSpeakerNotes() ) {
  2430. // Restart GIFs
  2431. toArray( slide.querySelectorAll( 'img[src$=".gif"]' ) ).forEach( function( el ) {
  2432. // Setting the same unchanged source like this was confirmed
  2433. // to work in Chrome, FF & Safari
  2434. el.setAttribute( 'src', el.getAttribute( 'src' ) );
  2435. } );
  2436. // HTML5 media elements
  2437. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  2438. if( el.hasAttribute( 'data-autoplay' ) && typeof el.play === 'function' ) {
  2439. el.play();
  2440. }
  2441. } );
  2442. // Normal iframes
  2443. toArray( slide.querySelectorAll( 'iframe[src]' ) ).forEach( function( el ) {
  2444. startEmbeddedIframe( { target: el } );
  2445. } );
  2446. // Lazy loading iframes
  2447. toArray( slide.querySelectorAll( 'iframe[data-src]' ) ).forEach( function( el ) {
  2448. if( el.getAttribute( 'src' ) !== el.getAttribute( 'data-src' ) ) {
  2449. el.removeEventListener( 'load', startEmbeddedIframe ); // remove first to avoid dupes
  2450. el.addEventListener( 'load', startEmbeddedIframe );
  2451. el.setAttribute( 'src', el.getAttribute( 'data-src' ) );
  2452. }
  2453. } );
  2454. }
  2455. }
  2456. /**
  2457. * "Starts" the content of an embedded iframe using the
  2458. * postMessage API.
  2459. *
  2460. * @param {object} event - postMessage API event
  2461. */
  2462. function startEmbeddedIframe( event ) {
  2463. var iframe = event.target;
  2464. // YouTube postMessage API
  2465. if( /youtube\.com\/embed\//.test( iframe.getAttribute( 'src' ) ) && iframe.hasAttribute( 'data-autoplay' ) ) {
  2466. iframe.contentWindow.postMessage( '{"event":"command","func":"playVideo","args":""}', '*' );
  2467. }
  2468. // Vimeo postMessage API
  2469. else if( /player\.vimeo\.com\//.test( iframe.getAttribute( 'src' ) ) && iframe.hasAttribute( 'data-autoplay' ) ) {
  2470. iframe.contentWindow.postMessage( '{"method":"play"}', '*' );
  2471. }
  2472. // Generic postMessage API
  2473. else {
  2474. iframe.contentWindow.postMessage( 'slide:start', '*' );
  2475. }
  2476. }
  2477. /**
  2478. * Stop playback of any embedded content inside of
  2479. * the targeted slide.
  2480. *
  2481. * @param {HTMLElement} slide
  2482. */
  2483. function stopEmbeddedContent( slide ) {
  2484. if( slide && slide.parentNode ) {
  2485. // HTML5 media elements
  2486. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  2487. if( !el.hasAttribute( 'data-ignore' ) && typeof el.pause === 'function' ) {
  2488. el.pause();
  2489. }
  2490. } );
  2491. // Generic postMessage API for non-lazy loaded iframes
  2492. toArray( slide.querySelectorAll( 'iframe' ) ).forEach( function( el ) {
  2493. el.contentWindow.postMessage( 'slide:stop', '*' );
  2494. el.removeEventListener( 'load', startEmbeddedIframe );
  2495. });
  2496. // YouTube postMessage API
  2497. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  2498. if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
  2499. el.contentWindow.postMessage( '{"event":"command","func":"pauseVideo","args":""}', '*' );
  2500. }
  2501. });
  2502. // Vimeo postMessage API
  2503. toArray( slide.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( function( el ) {
  2504. if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
  2505. el.contentWindow.postMessage( '{"method":"pause"}', '*' );
  2506. }
  2507. });
  2508. // Lazy loading iframes
  2509. toArray( slide.querySelectorAll( 'iframe[data-src]' ) ).forEach( function( el ) {
  2510. // Only removing the src doesn't actually unload the frame
  2511. // in all browsers (Firefox) so we set it to blank first
  2512. el.setAttribute( 'src', 'about:blank' );
  2513. el.removeAttribute( 'src' );
  2514. } );
  2515. }
  2516. }
  2517. /**
  2518. * Returns the number of past slides. This can be used as a global
  2519. * flattened index for slides.
  2520. *
  2521. * @return {number} Past slide count
  2522. */
  2523. function getSlidePastCount() {
  2524. var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  2525. // The number of past slides
  2526. var pastCount = 0;
  2527. // Step through all slides and count the past ones
  2528. mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
  2529. var horizontalSlide = horizontalSlides[i];
  2530. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  2531. for( var j = 0; j < verticalSlides.length; j++ ) {
  2532. // Stop as soon as we arrive at the present
  2533. if( verticalSlides[j].classList.contains( 'present' ) ) {
  2534. break mainLoop;
  2535. }
  2536. pastCount++;
  2537. }
  2538. // Stop as soon as we arrive at the present
  2539. if( horizontalSlide.classList.contains( 'present' ) ) {
  2540. break;
  2541. }
  2542. // Don't count the wrapping section for vertical slides
  2543. if( horizontalSlide.classList.contains( 'stack' ) === false ) {
  2544. pastCount++;
  2545. }
  2546. }
  2547. return pastCount;
  2548. }
  2549. /**
  2550. * Returns a value ranging from 0-1 that represents
  2551. * how far into the presentation we have navigated.
  2552. *
  2553. * @return {number}
  2554. */
  2555. function getProgress() {
  2556. // The number of past and total slides
  2557. var totalCount = getTotalSlides();
  2558. var pastCount = getSlidePastCount();
  2559. if( currentSlide ) {
  2560. var allFragments = currentSlide.querySelectorAll( '.fragment' );
  2561. // If there are fragments in the current slide those should be
  2562. // accounted for in the progress.
  2563. if( allFragments.length > 0 ) {
  2564. var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
  2565. // This value represents how big a portion of the slide progress
  2566. // that is made up by its fragments (0-1)
  2567. var fragmentWeight = 0.9;
  2568. // Add fragment progress to the past slide count
  2569. pastCount += ( visibleFragments.length / allFragments.length ) * fragmentWeight;
  2570. }
  2571. }
  2572. return pastCount / ( totalCount - 1 );
  2573. }
  2574. /**
  2575. * Checks if this presentation is running inside of the
  2576. * speaker notes window.
  2577. *
  2578. * @return {boolean}
  2579. */
  2580. function isSpeakerNotes() {
  2581. return !!window.location.search.match( /receiver/gi );
  2582. }
  2583. /**
  2584. * Reads the current URL (hash) and navigates accordingly.
  2585. */
  2586. function readURL() {
  2587. var hash = window.location.hash;
  2588. // Attempt to parse the hash as either an index or name
  2589. var bits = hash.slice( 2 ).split( '/' ),
  2590. name = hash.replace( /#|\//gi, '' );
  2591. // If the first bit is invalid and there is a name we can
  2592. // assume that this is a named link
  2593. if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
  2594. var element;
  2595. // Ensure the named link is a valid HTML ID attribute
  2596. if( /^[a-zA-Z][\w:.-]*$/.test( name ) ) {
  2597. // Find the slide with the specified ID
  2598. element = document.getElementById( name );
  2599. }
  2600. if( element ) {
  2601. // Find the position of the named slide and navigate to it
  2602. var indices = Reveal.getIndices( element );
  2603. slide( indices.h, indices.v );
  2604. }
  2605. // If the slide doesn't exist, navigate to the current slide
  2606. else {
  2607. slide( indexh || 0, indexv || 0 );
  2608. }
  2609. }
  2610. else {
  2611. // Read the index components of the hash
  2612. var h = parseInt( bits[0], 10 ) || 0,
  2613. v = parseInt( bits[1], 10 ) || 0;
  2614. if( h !== indexh || v !== indexv ) {
  2615. slide( h, v );
  2616. }
  2617. }
  2618. }
  2619. /**
  2620. * Updates the page URL (hash) to reflect the current
  2621. * state.
  2622. *
  2623. * @param {number} delay The time in ms to wait before
  2624. * writing the hash
  2625. */
  2626. function writeURL( delay ) {
  2627. if( config.history ) {
  2628. // Make sure there's never more than one timeout running
  2629. clearTimeout( writeURLTimeout );
  2630. // If a delay is specified, timeout this call
  2631. if( typeof delay === 'number' ) {
  2632. writeURLTimeout = setTimeout( writeURL, delay );
  2633. }
  2634. else if( currentSlide ) {
  2635. var url = '/';
  2636. // Attempt to create a named link based on the slide's ID
  2637. var id = currentSlide.getAttribute( 'id' );
  2638. if( id ) {
  2639. id = id.replace( /[^a-zA-Z0-9\-\_\:\.]/g, '' );
  2640. }
  2641. // If the current slide has an ID, use that as a named link
  2642. if( typeof id === 'string' && id.length ) {
  2643. url = '/' + id;
  2644. }
  2645. // Otherwise use the /h/v index
  2646. else {
  2647. if( indexh > 0 || indexv > 0 ) url += indexh;
  2648. if( indexv > 0 ) url += '/' + indexv;
  2649. }
  2650. window.location.hash = url;
  2651. }
  2652. }
  2653. }
  2654. /**
  2655. * Retrieves the h/v location and fragment of the current,
  2656. * or specified, slide.
  2657. *
  2658. * @param {HTMLElement} [slide] If specified, the returned
  2659. * index will be for this slide rather than the currently
  2660. * active one
  2661. *
  2662. * @return {{h: number, v: number, f: number}}
  2663. */
  2664. function getIndices( slide ) {
  2665. // By default, return the current indices
  2666. var h = indexh,
  2667. v = indexv,
  2668. f;
  2669. // If a slide is specified, return the indices of that slide
  2670. if( slide ) {
  2671. var isVertical = isVerticalSlide( slide );
  2672. var slideh = isVertical ? slide.parentNode : slide;
  2673. // Select all horizontal slides
  2674. var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  2675. // Now that we know which the horizontal slide is, get its index
  2676. h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
  2677. // Assume we're not vertical
  2678. v = undefined;
  2679. // If this is a vertical slide, grab the vertical index
  2680. if( isVertical ) {
  2681. v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
  2682. }
  2683. }
  2684. if( !slide && currentSlide ) {
  2685. var hasFragments = currentSlide.querySelectorAll( '.fragment' ).length > 0;
  2686. if( hasFragments ) {
  2687. var currentFragment = currentSlide.querySelector( '.current-fragment' );
  2688. if( currentFragment && currentFragment.hasAttribute( 'data-fragment-index' ) ) {
  2689. f = parseInt( currentFragment.getAttribute( 'data-fragment-index' ), 10 );
  2690. }
  2691. else {
  2692. f = currentSlide.querySelectorAll( '.fragment.visible' ).length - 1;
  2693. }
  2694. }
  2695. }
  2696. return { h: h, v: v, f: f };
  2697. }
  2698. /**
  2699. * Retrieves the total number of slides in this presentation.
  2700. *
  2701. * @return {number}
  2702. */
  2703. function getTotalSlides() {
  2704. return dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  2705. }
  2706. /**
  2707. * Returns the slide element matching the specified index.
  2708. *
  2709. * @return {HTMLElement}
  2710. */
  2711. function getSlide( x, y ) {
  2712. var horizontalSlide = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
  2713. var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
  2714. if( verticalSlides && verticalSlides.length && typeof y === 'number' ) {
  2715. return verticalSlides ? verticalSlides[ y ] : undefined;
  2716. }
  2717. return horizontalSlide;
  2718. }
  2719. /**
  2720. * Returns the background element for the given slide.
  2721. * All slides, even the ones with no background properties
  2722. * defined, have a background element so as long as the
  2723. * index is valid an element will be returned.
  2724. *
  2725. * @param {number} x Horizontal background index
  2726. * @param {number} y Vertical background index
  2727. * @return {(HTMLElement[]|*)}
  2728. */
  2729. function getSlideBackground( x, y ) {
  2730. // When printing to PDF the slide backgrounds are nested
  2731. // inside of the slides
  2732. if( isPrintingPDF() ) {
  2733. var slide = getSlide( x, y );
  2734. if( slide ) {
  2735. return slide.slideBackgroundElement;
  2736. }
  2737. return undefined;
  2738. }
  2739. var horizontalBackground = dom.wrapper.querySelectorAll( '.backgrounds>.slide-background' )[ x ];
  2740. var verticalBackgrounds = horizontalBackground && horizontalBackground.querySelectorAll( '.slide-background' );
  2741. if( verticalBackgrounds && verticalBackgrounds.length && typeof y === 'number' ) {
  2742. return verticalBackgrounds ? verticalBackgrounds[ y ] : undefined;
  2743. }
  2744. return horizontalBackground;
  2745. }
  2746. /**
  2747. * Retrieves the speaker notes from a slide. Notes can be
  2748. * defined in two ways:
  2749. * 1. As a data-notes attribute on the slide <section>
  2750. * 2. As an <aside class="notes"> inside of the slide
  2751. *
  2752. * @param {HTMLElement} [slide=currentSlide]
  2753. * @return {(string|null)}
  2754. */
  2755. function getSlideNotes( slide ) {
  2756. // Default to the current slide
  2757. slide = slide || currentSlide;
  2758. // Notes can be specified via the data-notes attribute...
  2759. if( slide.hasAttribute( 'data-notes' ) ) {
  2760. return slide.getAttribute( 'data-notes' );
  2761. }
  2762. // ... or using an <aside class="notes"> element
  2763. var notesElement = slide.querySelector( 'aside.notes' );
  2764. if( notesElement ) {
  2765. return notesElement.innerHTML;
  2766. }
  2767. return null;
  2768. }
  2769. /**
  2770. * Retrieves the current state of the presentation as
  2771. * an object. This state can then be restored at any
  2772. * time.
  2773. *
  2774. * @return {{indexh: number, indexv: number, indexf: number, paused: boolean, overview: boolean}}
  2775. */
  2776. function getState() {
  2777. var indices = getIndices();
  2778. return {
  2779. indexh: indices.h,
  2780. indexv: indices.v,
  2781. indexf: indices.f,
  2782. paused: isPaused(),
  2783. overview: isOverview()
  2784. };
  2785. }
  2786. /**
  2787. * Restores the presentation to the given state.
  2788. *
  2789. * @param {object} state As generated by getState()
  2790. * @see {@link getState} generates the parameter `state`
  2791. */
  2792. function setState( state ) {
  2793. if( typeof state === 'object' ) {
  2794. slide( deserialize( state.indexh ), deserialize( state.indexv ), deserialize( state.indexf ) );
  2795. var pausedFlag = deserialize( state.paused ),
  2796. overviewFlag = deserialize( state.overview );
  2797. if( typeof pausedFlag === 'boolean' && pausedFlag !== isPaused() ) {
  2798. togglePause( pausedFlag );
  2799. }
  2800. if( typeof overviewFlag === 'boolean' && overviewFlag !== isOverview() ) {
  2801. toggleOverview( overviewFlag );
  2802. }
  2803. }
  2804. }
  2805. /**
  2806. * Return a sorted fragments list, ordered by an increasing
  2807. * "data-fragment-index" attribute.
  2808. *
  2809. * Fragments will be revealed in the order that they are returned by
  2810. * this function, so you can use the index attributes to control the
  2811. * order of fragment appearance.
  2812. *
  2813. * To maintain a sensible default fragment order, fragments are presumed
  2814. * to be passed in document order. This function adds a "fragment-index"
  2815. * attribute to each node if such an attribute is not already present,
  2816. * and sets that attribute to an integer value which is the position of
  2817. * the fragment within the fragments list.
  2818. *
  2819. * @param {object[]|*} fragments
  2820. * @return {object[]} sorted Sorted array of fragments
  2821. */
  2822. function sortFragments( fragments ) {
  2823. fragments = toArray( fragments );
  2824. var ordered = [],
  2825. unordered = [],
  2826. sorted = [];
  2827. // Group ordered and unordered elements
  2828. fragments.forEach( function( fragment, i ) {
  2829. if( fragment.hasAttribute( 'data-fragment-index' ) ) {
  2830. var index = parseInt( fragment.getAttribute( 'data-fragment-index' ), 10 );
  2831. if( !ordered[index] ) {
  2832. ordered[index] = [];
  2833. }
  2834. ordered[index].push( fragment );
  2835. }
  2836. else {
  2837. unordered.push( [ fragment ] );
  2838. }
  2839. } );
  2840. // Append fragments without explicit indices in their
  2841. // DOM order
  2842. ordered = ordered.concat( unordered );
  2843. // Manually count the index up per group to ensure there
  2844. // are no gaps
  2845. var index = 0;
  2846. // Push all fragments in their sorted order to an array,
  2847. // this flattens the groups
  2848. ordered.forEach( function( group ) {
  2849. group.forEach( function( fragment ) {
  2850. sorted.push( fragment );
  2851. fragment.setAttribute( 'data-fragment-index', index );
  2852. } );
  2853. index ++;
  2854. } );
  2855. return sorted;
  2856. }
  2857. /**
  2858. * Navigate to the specified slide fragment.
  2859. *
  2860. * @param {?number} index The index of the fragment that
  2861. * should be shown, -1 means all are invisible
  2862. * @param {number} offset Integer offset to apply to the
  2863. * fragment index
  2864. *
  2865. * @return {boolean} true if a change was made in any
  2866. * fragments visibility as part of this call
  2867. */
  2868. function navigateFragment( index, offset ) {
  2869. if( currentSlide && config.fragments ) {
  2870. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
  2871. if( fragments.length ) {
  2872. // If no index is specified, find the current
  2873. if( typeof index !== 'number' ) {
  2874. var lastVisibleFragment = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) ).pop();
  2875. if( lastVisibleFragment ) {
  2876. index = parseInt( lastVisibleFragment.getAttribute( 'data-fragment-index' ) || 0, 10 );
  2877. }
  2878. else {
  2879. index = -1;
  2880. }
  2881. }
  2882. // If an offset is specified, apply it to the index
  2883. if( typeof offset === 'number' ) {
  2884. index += offset;
  2885. }
  2886. var fragmentsShown = [],
  2887. fragmentsHidden = [];
  2888. toArray( fragments ).forEach( function( element, i ) {
  2889. if( element.hasAttribute( 'data-fragment-index' ) ) {
  2890. i = parseInt( element.getAttribute( 'data-fragment-index' ), 10 );
  2891. }
  2892. // Visible fragments
  2893. if( i <= index ) {
  2894. if( !element.classList.contains( 'visible' ) ) fragmentsShown.push( element );
  2895. element.classList.add( 'visible' );
  2896. element.classList.remove( 'current-fragment' );
  2897. // Announce the fragments one by one to the Screen Reader
  2898. dom.statusDiv.textContent = element.textContent;
  2899. if( i === index ) {
  2900. element.classList.add( 'current-fragment' );
  2901. }
  2902. }
  2903. // Hidden fragments
  2904. else {
  2905. if( element.classList.contains( 'visible' ) ) fragmentsHidden.push( element );
  2906. element.classList.remove( 'visible' );
  2907. element.classList.remove( 'current-fragment' );
  2908. }
  2909. } );
  2910. if( fragmentsHidden.length ) {
  2911. dispatchEvent( 'fragmenthidden', { fragment: fragmentsHidden[0], fragments: fragmentsHidden } );
  2912. }
  2913. if( fragmentsShown.length ) {
  2914. dispatchEvent( 'fragmentshown', { fragment: fragmentsShown[0], fragments: fragmentsShown } );
  2915. }
  2916. updateControls();
  2917. updateProgress();
  2918. return !!( fragmentsShown.length || fragmentsHidden.length );
  2919. }
  2920. }
  2921. return false;
  2922. }
  2923. /**
  2924. * Navigate to the next slide fragment.
  2925. *
  2926. * @return {boolean} true if there was a next fragment,
  2927. * false otherwise
  2928. */
  2929. function nextFragment() {
  2930. return navigateFragment( null, 1 );
  2931. }
  2932. /**
  2933. * Navigate to the previous slide fragment.
  2934. *
  2935. * @return {boolean} true if there was a previous fragment,
  2936. * false otherwise
  2937. */
  2938. function previousFragment() {
  2939. return navigateFragment( null, -1 );
  2940. }
  2941. /**
  2942. * Cues a new automated slide if enabled in the config.
  2943. */
  2944. function cueAutoSlide() {
  2945. cancelAutoSlide();
  2946. if( currentSlide ) {
  2947. var fragment = currentSlide.querySelector( '.current-fragment' );
  2948. // When the slide first appears there is no "current" fragment so
  2949. // we look for a data-autoslide timing on the first fragment
  2950. if( !fragment ) fragment = currentSlide.querySelector( '.fragment' );
  2951. var fragmentAutoSlide = fragment ? fragment.getAttribute( 'data-autoslide' ) : null;
  2952. var parentAutoSlide = currentSlide.parentNode ? currentSlide.parentNode.getAttribute( 'data-autoslide' ) : null;
  2953. var slideAutoSlide = currentSlide.getAttribute( 'data-autoslide' );
  2954. // Pick value in the following priority order:
  2955. // 1. Current fragment's data-autoslide
  2956. // 2. Current slide's data-autoslide
  2957. // 3. Parent slide's data-autoslide
  2958. // 4. Global autoSlide setting
  2959. if( fragmentAutoSlide ) {
  2960. autoSlide = parseInt( fragmentAutoSlide, 10 );
  2961. }
  2962. else if( slideAutoSlide ) {
  2963. autoSlide = parseInt( slideAutoSlide, 10 );
  2964. }
  2965. else if( parentAutoSlide ) {
  2966. autoSlide = parseInt( parentAutoSlide, 10 );
  2967. }
  2968. else {
  2969. autoSlide = config.autoSlide;
  2970. }
  2971. // If there are media elements with data-autoplay,
  2972. // automatically set the autoSlide duration to the
  2973. // length of that media. Not applicable if the slide
  2974. // is divided up into fragments.
  2975. if( currentSlide.querySelectorAll( '.fragment' ).length === 0 ) {
  2976. toArray( currentSlide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  2977. if( el.hasAttribute( 'data-autoplay' ) ) {
  2978. if( autoSlide && el.duration * 1000 > autoSlide ) {
  2979. autoSlide = ( el.duration * 1000 ) + 1000;
  2980. }
  2981. }
  2982. } );
  2983. }
  2984. // Cue the next auto-slide if:
  2985. // - There is an autoSlide value
  2986. // - Auto-sliding isn't paused by the user
  2987. // - The presentation isn't paused
  2988. // - The overview isn't active
  2989. // - The presentation isn't over
  2990. if( autoSlide && !autoSlidePaused && !isPaused() && !isOverview() && ( !Reveal.isLastSlide() || availableFragments().next || config.loop === true ) ) {
  2991. autoSlideTimeout = setTimeout( function() {
  2992. typeof config.autoSlideMethod === 'function' ? config.autoSlideMethod() : navigateNext();
  2993. cueAutoSlide();
  2994. }, autoSlide );
  2995. autoSlideStartTime = Date.now();
  2996. }
  2997. if( autoSlidePlayer ) {
  2998. autoSlidePlayer.setPlaying( autoSlideTimeout !== -1 );
  2999. }
  3000. }
  3001. }
  3002. /**
  3003. * Cancels any ongoing request to auto-slide.
  3004. */
  3005. function cancelAutoSlide() {
  3006. clearTimeout( autoSlideTimeout );
  3007. autoSlideTimeout = -1;
  3008. }
  3009. function pauseAutoSlide() {
  3010. if( autoSlide && !autoSlidePaused ) {
  3011. autoSlidePaused = true;
  3012. dispatchEvent( 'autoslidepaused' );
  3013. clearTimeout( autoSlideTimeout );
  3014. if( autoSlidePlayer ) {
  3015. autoSlidePlayer.setPlaying( false );
  3016. }
  3017. }
  3018. }
  3019. function resumeAutoSlide() {
  3020. if( autoSlide && autoSlidePaused ) {
  3021. autoSlidePaused = false;
  3022. dispatchEvent( 'autoslideresumed' );
  3023. cueAutoSlide();
  3024. }
  3025. }
  3026. function navigateLeft() {
  3027. // Reverse for RTL
  3028. if( config.rtl ) {
  3029. if( ( isOverview() || nextFragment() === false ) && availableRoutes().left ) {
  3030. slide( indexh + 1 );
  3031. }
  3032. }
  3033. // Normal navigation
  3034. else if( ( isOverview() || previousFragment() === false ) && availableRoutes().left ) {
  3035. slide( indexh - 1 );
  3036. }
  3037. }
  3038. function navigateRight() {
  3039. // Reverse for RTL
  3040. if( config.rtl ) {
  3041. if( ( isOverview() || previousFragment() === false ) && availableRoutes().right ) {
  3042. slide( indexh - 1 );
  3043. }
  3044. }
  3045. // Normal navigation
  3046. else if( ( isOverview() || nextFragment() === false ) && availableRoutes().right ) {
  3047. slide( indexh + 1 );
  3048. }
  3049. }
  3050. function navigateUp() {
  3051. // Prioritize hiding fragments
  3052. if( ( isOverview() || previousFragment() === false ) && availableRoutes().up ) {
  3053. slide( indexh, indexv - 1 );
  3054. }
  3055. }
  3056. function navigateDown() {
  3057. // Prioritize revealing fragments
  3058. if( ( isOverview() || nextFragment() === false ) && availableRoutes().down ) {
  3059. slide( indexh, indexv + 1 );
  3060. }
  3061. }
  3062. /**
  3063. * Navigates backwards, prioritized in the following order:
  3064. * 1) Previous fragment
  3065. * 2) Previous vertical slide
  3066. * 3) Previous horizontal slide
  3067. */
  3068. function navigatePrev() {
  3069. // Prioritize revealing fragments
  3070. if( previousFragment() === false ) {
  3071. if( availableRoutes().up ) {
  3072. navigateUp();
  3073. }
  3074. else {
  3075. // Fetch the previous horizontal slide, if there is one
  3076. var previousSlide;
  3077. if( config.rtl ) {
  3078. previousSlide = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.future' ) ).pop();
  3079. }
  3080. else {
  3081. previousSlide = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.past' ) ).pop();
  3082. }
  3083. if( previousSlide ) {
  3084. var v = ( previousSlide.querySelectorAll( 'section' ).length - 1 ) || undefined;
  3085. var h = indexh - 1;
  3086. slide( h, v );
  3087. }
  3088. }
  3089. }
  3090. }
  3091. /**
  3092. * The reverse of #navigatePrev().
  3093. */
  3094. function navigateNext() {
  3095. // Prioritize revealing fragments
  3096. if( nextFragment() === false ) {
  3097. if( availableRoutes().down ) {
  3098. navigateDown();
  3099. }
  3100. else if( config.rtl ) {
  3101. navigateLeft();
  3102. }
  3103. else {
  3104. navigateRight();
  3105. }
  3106. }
  3107. }
  3108. /**
  3109. * Checks if the target element prevents the triggering of
  3110. * swipe navigation.
  3111. */
  3112. function isSwipePrevented( target ) {
  3113. while( target && typeof target.hasAttribute === 'function' ) {
  3114. if( target.hasAttribute( 'data-prevent-swipe' ) ) return true;
  3115. target = target.parentNode;
  3116. }
  3117. return false;
  3118. }
  3119. // --------------------------------------------------------------------//
  3120. // ----------------------------- EVENTS -------------------------------//
  3121. // --------------------------------------------------------------------//
  3122. /**
  3123. * Called by all event handlers that are based on user
  3124. * input.
  3125. *
  3126. * @param {object} [event]
  3127. */
  3128. function onUserInput( event ) {
  3129. if( config.autoSlideStoppable ) {
  3130. pauseAutoSlide();
  3131. }
  3132. }
  3133. /**
  3134. * Handler for the document level 'keypress' event.
  3135. *
  3136. * @param {object} event
  3137. */
  3138. function onDocumentKeyPress( event ) {
  3139. // Check if the pressed key is question mark
  3140. if( event.shiftKey && event.charCode === 63 ) {
  3141. if( dom.overlay ) {
  3142. closeOverlay();
  3143. }
  3144. else {
  3145. showHelp( true );
  3146. }
  3147. }
  3148. }
  3149. /**
  3150. * Handler for the document level 'keydown' event.
  3151. *
  3152. * @param {object} event
  3153. */
  3154. function onDocumentKeyDown( event ) {
  3155. // If there's a condition specified and it returns false,
  3156. // ignore this event
  3157. if( typeof config.keyboardCondition === 'function' && config.keyboardCondition() === false ) {
  3158. return true;
  3159. }
  3160. // Remember if auto-sliding was paused so we can toggle it
  3161. var autoSlideWasPaused = autoSlidePaused;
  3162. onUserInput( event );
  3163. // Check if there's a focused element that could be using
  3164. // the keyboard
  3165. var activeElementIsCE = document.activeElement && document.activeElement.contentEditable !== 'inherit';
  3166. var activeElementIsInput = document.activeElement && document.activeElement.tagName && /input|textarea/i.test( document.activeElement.tagName );
  3167. var activeElementIsNotes = document.activeElement && document.activeElement.className && /speaker-notes/i.test( document.activeElement.className);
  3168. // Disregard the event if there's a focused element or a
  3169. // keyboard modifier key is present
  3170. if( activeElementIsCE || activeElementIsInput || activeElementIsNotes || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
  3171. // While paused only allow resume keyboard events; 'b', '.''
  3172. var resumeKeyCodes = [66,190,191];
  3173. var key;
  3174. // Custom key bindings for togglePause should be able to resume
  3175. if( typeof config.keyboard === 'object' ) {
  3176. for( key in config.keyboard ) {
  3177. if( config.keyboard[key] === 'togglePause' ) {
  3178. resumeKeyCodes.push( parseInt( key, 10 ) );
  3179. }
  3180. }
  3181. }
  3182. if( isPaused() && resumeKeyCodes.indexOf( event.keyCode ) === -1 ) {
  3183. return false;
  3184. }
  3185. var triggered = false;
  3186. // 1. User defined key bindings
  3187. if( typeof config.keyboard === 'object' ) {
  3188. for( key in config.keyboard ) {
  3189. // Check if this binding matches the pressed key
  3190. if( parseInt( key, 10 ) === event.keyCode ) {
  3191. var value = config.keyboard[ key ];
  3192. // Callback function
  3193. if( typeof value === 'function' ) {
  3194. value.apply( null, [ event ] );
  3195. }
  3196. // String shortcuts to reveal.js API
  3197. else if( typeof value === 'string' && typeof Reveal[ value ] === 'function' ) {
  3198. Reveal[ value ].call();
  3199. }
  3200. triggered = true;
  3201. }
  3202. }
  3203. }
  3204. // 2. System defined key bindings
  3205. if( triggered === false ) {
  3206. // Assume true and try to prove false
  3207. triggered = true;
  3208. switch( event.keyCode ) {
  3209. // p, page up
  3210. case 80: case 33: navigatePrev(); break;
  3211. // n, page down
  3212. case 78: case 34: navigateNext(); break;
  3213. // h, left
  3214. case 72: case 37: navigateLeft(); break;
  3215. // l, right
  3216. case 76: case 39: navigateRight(); break;
  3217. // k, up
  3218. case 75: case 38: navigateUp(); break;
  3219. // j, down
  3220. case 74: case 40: navigateDown(); break;
  3221. // home
  3222. case 36: slide( 0 ); break;
  3223. // end
  3224. case 35: slide( Number.MAX_VALUE ); break;
  3225. // space
  3226. case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
  3227. // return
  3228. case 13: isOverview() ? deactivateOverview() : triggered = false; break;
  3229. // two-spot, semicolon, b, period, Logitech presenter tools "black screen" button
  3230. case 58: case 59: case 66: case 190: case 191: togglePause(); break;
  3231. // f
  3232. case 70: enterFullscreen(); break;
  3233. // a
  3234. case 65: if ( config.autoSlideStoppable ) toggleAutoSlide( autoSlideWasPaused ); break;
  3235. default:
  3236. triggered = false;
  3237. }
  3238. }
  3239. // If the input resulted in a triggered action we should prevent
  3240. // the browsers default behavior
  3241. if( triggered ) {
  3242. event.preventDefault && event.preventDefault();
  3243. }
  3244. // ESC or O key
  3245. else if ( ( event.keyCode === 27 || event.keyCode === 79 ) && features.transforms3d ) {
  3246. if( dom.overlay ) {
  3247. closeOverlay();
  3248. }
  3249. else {
  3250. toggleOverview();
  3251. }
  3252. event.preventDefault && event.preventDefault();
  3253. }
  3254. // If auto-sliding is enabled we need to cue up
  3255. // another timeout
  3256. cueAutoSlide();
  3257. }
  3258. /**
  3259. * Handler for the 'touchstart' event, enables support for
  3260. * swipe and pinch gestures.
  3261. *
  3262. * @param {object} event
  3263. */
  3264. function onTouchStart( event ) {
  3265. if( isSwipePrevented( event.target ) ) return true;
  3266. touch.startX = event.touches[0].clientX;
  3267. touch.startY = event.touches[0].clientY;
  3268. touch.startCount = event.touches.length;
  3269. // If there's two touches we need to memorize the distance
  3270. // between those two points to detect pinching
  3271. if( event.touches.length === 2 && config.overview ) {
  3272. touch.startSpan = distanceBetween( {
  3273. x: event.touches[1].clientX,
  3274. y: event.touches[1].clientY
  3275. }, {
  3276. x: touch.startX,
  3277. y: touch.startY
  3278. } );
  3279. }
  3280. }
  3281. /**
  3282. * Handler for the 'touchmove' event.
  3283. *
  3284. * @param {object} event
  3285. */
  3286. function onTouchMove( event ) {
  3287. if( isSwipePrevented( event.target ) ) return true;
  3288. // Each touch should only trigger one action
  3289. if( !touch.captured ) {
  3290. onUserInput( event );
  3291. var currentX = event.touches[0].clientX;
  3292. var currentY = event.touches[0].clientY;
  3293. // If the touch started with two points and still has
  3294. // two active touches; test for the pinch gesture
  3295. if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
  3296. // The current distance in pixels between the two touch points
  3297. var currentSpan = distanceBetween( {
  3298. x: event.touches[1].clientX,
  3299. y: event.touches[1].clientY
  3300. }, {
  3301. x: touch.startX,
  3302. y: touch.startY
  3303. } );
  3304. // If the span is larger than the desire amount we've got
  3305. // ourselves a pinch
  3306. if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
  3307. touch.captured = true;
  3308. if( currentSpan < touch.startSpan ) {
  3309. activateOverview();
  3310. }
  3311. else {
  3312. deactivateOverview();
  3313. }
  3314. }
  3315. event.preventDefault();
  3316. }
  3317. // There was only one touch point, look for a swipe
  3318. else if( event.touches.length === 1 && touch.startCount !== 2 ) {
  3319. var deltaX = currentX - touch.startX,
  3320. deltaY = currentY - touch.startY;
  3321. if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  3322. touch.captured = true;
  3323. navigateLeft();
  3324. }
  3325. else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  3326. touch.captured = true;
  3327. navigateRight();
  3328. }
  3329. else if( deltaY > touch.threshold ) {
  3330. touch.captured = true;
  3331. navigateUp();
  3332. }
  3333. else if( deltaY < -touch.threshold ) {
  3334. touch.captured = true;
  3335. navigateDown();
  3336. }
  3337. // If we're embedded, only block touch events if they have
  3338. // triggered an action
  3339. if( config.embedded ) {
  3340. if( touch.captured || isVerticalSlide( currentSlide ) ) {
  3341. event.preventDefault();
  3342. }
  3343. }
  3344. // Not embedded? Block them all to avoid needless tossing
  3345. // around of the viewport in iOS
  3346. else {
  3347. event.preventDefault();
  3348. }
  3349. }
  3350. }
  3351. // There's a bug with swiping on some Android devices unless
  3352. // the default action is always prevented
  3353. else if( UA.match( /android/gi ) ) {
  3354. event.preventDefault();
  3355. }
  3356. }
  3357. /**
  3358. * Handler for the 'touchend' event.
  3359. *
  3360. * @param {object} event
  3361. */
  3362. function onTouchEnd( event ) {
  3363. touch.captured = false;
  3364. }
  3365. /**
  3366. * Convert pointer down to touch start.
  3367. *
  3368. * @param {object} event
  3369. */
  3370. function onPointerDown( event ) {
  3371. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  3372. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  3373. onTouchStart( event );
  3374. }
  3375. }
  3376. /**
  3377. * Convert pointer move to touch move.
  3378. *
  3379. * @param {object} event
  3380. */
  3381. function onPointerMove( event ) {
  3382. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  3383. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  3384. onTouchMove( event );
  3385. }
  3386. }
  3387. /**
  3388. * Convert pointer up to touch end.
  3389. *
  3390. * @param {object} event
  3391. */
  3392. function onPointerUp( event ) {
  3393. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  3394. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  3395. onTouchEnd( event );
  3396. }
  3397. }
  3398. /**
  3399. * Handles mouse wheel scrolling, throttled to avoid skipping
  3400. * multiple slides.
  3401. *
  3402. * @param {object} event
  3403. */
  3404. function onDocumentMouseScroll( event ) {
  3405. if( Date.now() - lastMouseWheelStep > 600 ) {
  3406. lastMouseWheelStep = Date.now();
  3407. var delta = event.detail || -event.wheelDelta;
  3408. if( delta > 0 ) {
  3409. navigateNext();
  3410. }
  3411. else {
  3412. navigatePrev();
  3413. }
  3414. }
  3415. }
  3416. /**
  3417. * Clicking on the progress bar results in a navigation to the
  3418. * closest approximate horizontal slide using this equation:
  3419. *
  3420. * ( clickX / presentationWidth ) * numberOfSlides
  3421. *
  3422. * @param {object} event
  3423. */
  3424. function onProgressClicked( event ) {
  3425. onUserInput( event );
  3426. event.preventDefault();
  3427. var slidesTotal = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
  3428. var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
  3429. if( config.rtl ) {
  3430. slideIndex = slidesTotal - slideIndex;
  3431. }
  3432. slide( slideIndex );
  3433. }
  3434. /**
  3435. * Event handler for navigation control buttons.
  3436. */
  3437. function onNavigateLeftClicked( event ) { event.preventDefault(); onUserInput(); navigateLeft(); }
  3438. function onNavigateRightClicked( event ) { event.preventDefault(); onUserInput(); navigateRight(); }
  3439. function onNavigateUpClicked( event ) { event.preventDefault(); onUserInput(); navigateUp(); }
  3440. function onNavigateDownClicked( event ) { event.preventDefault(); onUserInput(); navigateDown(); }
  3441. function onNavigatePrevClicked( event ) { event.preventDefault(); onUserInput(); navigatePrev(); }
  3442. function onNavigateNextClicked( event ) { event.preventDefault(); onUserInput(); navigateNext(); }
  3443. /**
  3444. * Handler for the window level 'hashchange' event.
  3445. *
  3446. * @param {object} [event]
  3447. */
  3448. function onWindowHashChange( event ) {
  3449. readURL();
  3450. }
  3451. /**
  3452. * Handler for the window level 'resize' event.
  3453. *
  3454. * @param {object} [event]
  3455. */
  3456. function onWindowResize( event ) {
  3457. layout();
  3458. }
  3459. /**
  3460. * Handle for the window level 'visibilitychange' event.
  3461. *
  3462. * @param {object} [event]
  3463. */
  3464. function onPageVisibilityChange( event ) {
  3465. var isHidden = document.webkitHidden ||
  3466. document.msHidden ||
  3467. document.hidden;
  3468. // If, after clicking a link or similar and we're coming back,
  3469. // focus the document.body to ensure we can use keyboard shortcuts
  3470. if( isHidden === false && document.activeElement !== document.body ) {
  3471. // Not all elements support .blur() - SVGs among them.
  3472. if( typeof document.activeElement.blur === 'function' ) {
  3473. document.activeElement.blur();
  3474. }
  3475. document.body.focus();
  3476. }
  3477. }
  3478. /**
  3479. * Invoked when a slide is and we're in the overview.
  3480. *
  3481. * @param {object} event
  3482. */
  3483. function onOverviewSlideClicked( event ) {
  3484. // TODO There's a bug here where the event listeners are not
  3485. // removed after deactivating the overview.
  3486. if( eventsAreBound && isOverview() ) {
  3487. event.preventDefault();
  3488. var element = event.target;
  3489. while( element && !element.nodeName.match( /section/gi ) ) {
  3490. element = element.parentNode;
  3491. }
  3492. if( element && !element.classList.contains( 'disabled' ) ) {
  3493. deactivateOverview();
  3494. if( element.nodeName.match( /section/gi ) ) {
  3495. var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
  3496. v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
  3497. slide( h, v );
  3498. }
  3499. }
  3500. }
  3501. }
  3502. /**
  3503. * Handles clicks on links that are set to preview in the
  3504. * iframe overlay.
  3505. *
  3506. * @param {object} event
  3507. */
  3508. function onPreviewLinkClicked( event ) {
  3509. if( event.currentTarget && event.currentTarget.hasAttribute( 'href' ) ) {
  3510. var url = event.currentTarget.getAttribute( 'href' );
  3511. if( url ) {
  3512. showPreview( url );
  3513. event.preventDefault();
  3514. }
  3515. }
  3516. }
  3517. /**
  3518. * Handles click on the auto-sliding controls element.
  3519. *
  3520. * @param {object} [event]
  3521. */
  3522. function onAutoSlidePlayerClick( event ) {
  3523. // Replay
  3524. if( Reveal.isLastSlide() && config.loop === false ) {
  3525. slide( 0, 0 );
  3526. resumeAutoSlide();
  3527. }
  3528. // Resume
  3529. else if( autoSlidePaused ) {
  3530. resumeAutoSlide();
  3531. }
  3532. // Pause
  3533. else {
  3534. pauseAutoSlide();
  3535. }
  3536. }
  3537. // --------------------------------------------------------------------//
  3538. // ------------------------ PLAYBACK COMPONENT ------------------------//
  3539. // --------------------------------------------------------------------//
  3540. /**
  3541. * Constructor for the playback component, which displays
  3542. * play/pause/progress controls.
  3543. *
  3544. * @param {HTMLElement} container The component will append
  3545. * itself to this
  3546. * @param {function} progressCheck A method which will be
  3547. * called frequently to get the current progress on a range
  3548. * of 0-1
  3549. */
  3550. function Playback( container, progressCheck ) {
  3551. // Cosmetics
  3552. this.diameter = 100;
  3553. this.diameter2 = this.diameter/2;
  3554. this.thickness = 6;
  3555. // Flags if we are currently playing
  3556. this.playing = false;
  3557. // Current progress on a 0-1 range
  3558. this.progress = 0;
  3559. // Used to loop the animation smoothly
  3560. this.progressOffset = 1;
  3561. this.container = container;
  3562. this.progressCheck = progressCheck;
  3563. this.canvas = document.createElement( 'canvas' );
  3564. this.canvas.className = 'playback';
  3565. this.canvas.width = this.diameter;
  3566. this.canvas.height = this.diameter;
  3567. this.canvas.style.width = this.diameter2 + 'px';
  3568. this.canvas.style.height = this.diameter2 + 'px';
  3569. this.context = this.canvas.getContext( '2d' );
  3570. this.container.appendChild( this.canvas );
  3571. this.render();
  3572. }
  3573. /**
  3574. * @param value
  3575. */
  3576. Playback.prototype.setPlaying = function( value ) {
  3577. var wasPlaying = this.playing;
  3578. this.playing = value;
  3579. // Start repainting if we weren't already
  3580. if( !wasPlaying && this.playing ) {
  3581. this.animate();
  3582. }
  3583. else {
  3584. this.render();
  3585. }
  3586. };
  3587. Playback.prototype.animate = function() {
  3588. var progressBefore = this.progress;
  3589. this.progress = this.progressCheck();
  3590. // When we loop, offset the progress so that it eases
  3591. // smoothly rather than immediately resetting
  3592. if( progressBefore > 0.8 && this.progress < 0.2 ) {
  3593. this.progressOffset = this.progress;
  3594. }
  3595. this.render();
  3596. if( this.playing ) {
  3597. features.requestAnimationFrameMethod.call( window, this.animate.bind( this ) );
  3598. }
  3599. };
  3600. /**
  3601. * Renders the current progress and playback state.
  3602. */
  3603. Playback.prototype.render = function() {
  3604. var progress = this.playing ? this.progress : 0,
  3605. radius = ( this.diameter2 ) - this.thickness,
  3606. x = this.diameter2,
  3607. y = this.diameter2,
  3608. iconSize = 28;
  3609. // Ease towards 1
  3610. this.progressOffset += ( 1 - this.progressOffset ) * 0.1;
  3611. var endAngle = ( - Math.PI / 2 ) + ( progress * ( Math.PI * 2 ) );
  3612. var startAngle = ( - Math.PI / 2 ) + ( this.progressOffset * ( Math.PI * 2 ) );
  3613. this.context.save();
  3614. this.context.clearRect( 0, 0, this.diameter, this.diameter );
  3615. // Solid background color
  3616. this.context.beginPath();
  3617. this.context.arc( x, y, radius + 4, 0, Math.PI * 2, false );
  3618. this.context.fillStyle = 'rgba( 0, 0, 0, 0.4 )';
  3619. this.context.fill();
  3620. // Draw progress track
  3621. this.context.beginPath();
  3622. this.context.arc( x, y, radius, 0, Math.PI * 2, false );
  3623. this.context.lineWidth = this.thickness;
  3624. this.context.strokeStyle = '#666';
  3625. this.context.stroke();
  3626. if( this.playing ) {
  3627. // Draw progress on top of track
  3628. this.context.beginPath();
  3629. this.context.arc( x, y, radius, startAngle, endAngle, false );
  3630. this.context.lineWidth = this.thickness;
  3631. this.context.strokeStyle = '#fff';
  3632. this.context.stroke();
  3633. }
  3634. this.context.translate( x - ( iconSize / 2 ), y - ( iconSize / 2 ) );
  3635. // Draw play/pause icons
  3636. if( this.playing ) {
  3637. this.context.fillStyle = '#fff';
  3638. this.context.fillRect( 0, 0, iconSize / 2 - 4, iconSize );
  3639. this.context.fillRect( iconSize / 2 + 4, 0, iconSize / 2 - 4, iconSize );
  3640. }
  3641. else {
  3642. this.context.beginPath();
  3643. this.context.translate( 4, 0 );
  3644. this.context.moveTo( 0, 0 );
  3645. this.context.lineTo( iconSize - 4, iconSize / 2 );
  3646. this.context.lineTo( 0, iconSize );
  3647. this.context.fillStyle = '#fff';
  3648. this.context.fill();
  3649. }
  3650. this.context.restore();
  3651. };
  3652. Playback.prototype.on = function( type, listener ) {
  3653. this.canvas.addEventListener( type, listener, false );
  3654. };
  3655. Playback.prototype.off = function( type, listener ) {
  3656. this.canvas.removeEventListener( type, listener, false );
  3657. };
  3658. Playback.prototype.destroy = function() {
  3659. this.playing = false;
  3660. if( this.canvas.parentNode ) {
  3661. this.container.removeChild( this.canvas );
  3662. }
  3663. };
  3664. // --------------------------------------------------------------------//
  3665. // ------------------------------- API --------------------------------//
  3666. // --------------------------------------------------------------------//
  3667. Reveal = {
  3668. VERSION: VERSION,
  3669. initialize: initialize,
  3670. configure: configure,
  3671. sync: sync,
  3672. // Navigation methods
  3673. slide: slide,
  3674. left: navigateLeft,
  3675. right: navigateRight,
  3676. up: navigateUp,
  3677. down: navigateDown,
  3678. prev: navigatePrev,
  3679. next: navigateNext,
  3680. // Fragment methods
  3681. navigateFragment: navigateFragment,
  3682. prevFragment: previousFragment,
  3683. nextFragment: nextFragment,
  3684. // Deprecated aliases
  3685. navigateTo: slide,
  3686. navigateLeft: navigateLeft,
  3687. navigateRight: navigateRight,
  3688. navigateUp: navigateUp,
  3689. navigateDown: navigateDown,
  3690. navigatePrev: navigatePrev,
  3691. navigateNext: navigateNext,
  3692. // Shows a help overlay with keyboard shortcuts
  3693. showHelp: showHelp,
  3694. // Forces an update in slide layout
  3695. layout: layout,
  3696. // Randomizes the order of slides
  3697. shuffle: shuffle,
  3698. // Returns an object with the available routes as booleans (left/right/top/bottom)
  3699. availableRoutes: availableRoutes,
  3700. // Returns an object with the available fragments as booleans (prev/next)
  3701. availableFragments: availableFragments,
  3702. // Toggles the overview mode on/off
  3703. toggleOverview: toggleOverview,
  3704. // Toggles the "black screen" mode on/off
  3705. togglePause: togglePause,
  3706. // Toggles the auto slide mode on/off
  3707. toggleAutoSlide: toggleAutoSlide,
  3708. // State checks
  3709. isOverview: isOverview,
  3710. isPaused: isPaused,
  3711. isAutoSliding: isAutoSliding,
  3712. // Adds or removes all internal event listeners (such as keyboard)
  3713. addEventListeners: addEventListeners,
  3714. removeEventListeners: removeEventListeners,
  3715. // Facility for persisting and restoring the presentation state
  3716. getState: getState,
  3717. setState: setState,
  3718. // Presentation progress on range of 0-1
  3719. getProgress: getProgress,
  3720. // Returns the indices of the current, or specified, slide
  3721. getIndices: getIndices,
  3722. getTotalSlides: getTotalSlides,
  3723. // Returns the slide element at the specified index
  3724. getSlide: getSlide,
  3725. // Returns the slide background element at the specified index
  3726. getSlideBackground: getSlideBackground,
  3727. // Returns the speaker notes string for a slide, or null
  3728. getSlideNotes: getSlideNotes,
  3729. // Returns the previous slide element, may be null
  3730. getPreviousSlide: function() {
  3731. return previousSlide;
  3732. },
  3733. // Returns the current slide element
  3734. getCurrentSlide: function() {
  3735. return currentSlide;
  3736. },
  3737. // Returns the current scale of the presentation content
  3738. getScale: function() {
  3739. return scale;
  3740. },
  3741. // Returns the current configuration object
  3742. getConfig: function() {
  3743. return config;
  3744. },
  3745. // Helper method, retrieves query string as a key/value hash
  3746. getQueryHash: function() {
  3747. var query = {};
  3748. location.search.replace( /[A-Z0-9]+?=([\w\.%-]*)/gi, function(a) {
  3749. query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
  3750. } );
  3751. // Basic deserialization
  3752. for( var i in query ) {
  3753. var value = query[ i ];
  3754. query[ i ] = deserialize( unescape( value ) );
  3755. }
  3756. return query;
  3757. },
  3758. // Returns true if we're currently on the first slide
  3759. isFirstSlide: function() {
  3760. return ( indexh === 0 && indexv === 0 );
  3761. },
  3762. // Returns true if we're currently on the last slide
  3763. isLastSlide: function() {
  3764. if( currentSlide ) {
  3765. // Does this slide has next a sibling?
  3766. if( currentSlide.nextElementSibling ) return false;
  3767. // If it's vertical, does its parent have a next sibling?
  3768. if( isVerticalSlide( currentSlide ) && currentSlide.parentNode.nextElementSibling ) return false;
  3769. return true;
  3770. }
  3771. return false;
  3772. },
  3773. // Checks if reveal.js has been loaded and is ready for use
  3774. isReady: function() {
  3775. return loaded;
  3776. },
  3777. // Forward event binding to the reveal DOM element
  3778. addEventListener: function( type, listener, useCapture ) {
  3779. if( 'addEventListener' in window ) {
  3780. ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
  3781. }
  3782. },
  3783. removeEventListener: function( type, listener, useCapture ) {
  3784. if( 'addEventListener' in window ) {
  3785. ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
  3786. }
  3787. },
  3788. // Programatically triggers a keyboard event
  3789. triggerKey: function( keyCode ) {
  3790. onDocumentKeyDown( { keyCode: keyCode } );
  3791. },
  3792. // Registers a new shortcut to include in the help overlay
  3793. registerKeyboardShortcut: function( key, value ) {
  3794. keyboardShortcuts[key] = value;
  3795. }
  3796. };
  3797. return Reveal;
  3798. }));