reveal.js 172 KB

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