reveal.js 152 KB

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