reveal.js 169 KB

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