reveal.js 143 KB

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