reveal.js 158 KB

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