reveal.js 179 KB

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