reveal.js 140 KB

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