reveal.js 159 KB

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