reveal.js 134 KB

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