reveal.js 148 KB

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