reveal.js 153 KB

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