reveal.js 112 KB

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