reveal.js 154 KB

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