reveal.js 151 KB

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