reveal.js 158 KB

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