reveal.js 131 KB

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