reveal.js 159 KB

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