reveal.js 153 KB

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