reveal.js 135 KB

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