reveal.js 187 KB

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