reveal.js 152 KB

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