reveal.js 150 KB

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