reveal.js 153 KB

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