reveal.js 151 KB

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