reveal.js 154 KB

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