reveal.js 134 KB

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