reveal.js 141 KB

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