reveal.js 185 KB

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