reveal.js 135 KB

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