reveal.js 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904
  1. import SlideContent from './controllers/slidecontent.js'
  2. import SlideNumber from './controllers/slidenumber.js'
  3. import JumpToSlide from './controllers/jumptoslide.js'
  4. import Backgrounds from './controllers/backgrounds.js'
  5. import AutoAnimate from './controllers/autoanimate.js'
  6. import ScrollView from './controllers/scrollview.js'
  7. import PrintView from './controllers/printview.js'
  8. import Fragments from './controllers/fragments.js'
  9. import Overview from './controllers/overview.js'
  10. import Keyboard from './controllers/keyboard.js'
  11. import Location from './controllers/location.js'
  12. import Controls from './controllers/controls.js'
  13. import Progress from './controllers/progress.js'
  14. import Pointer from './controllers/pointer.js'
  15. import Plugins from './controllers/plugins.js'
  16. import Overlay from './controllers/overlay.js'
  17. import Touch from './controllers/touch.js'
  18. import Focus from './controllers/focus.js'
  19. import Notes from './controllers/notes.js'
  20. import Playback from './components/playback.js'
  21. import defaultConfig from './config.js'
  22. import * as Util from './utils/util.js'
  23. import * as Device from './utils/device.js'
  24. import {
  25. SLIDES_SELECTOR,
  26. HORIZONTAL_SLIDES_SELECTOR,
  27. VERTICAL_SLIDES_SELECTOR,
  28. POST_MESSAGE_METHOD_BLACKLIST
  29. } from './utils/constants.js'
  30. // The reveal.js version
  31. export const VERSION = '5.2.0';
  32. /**
  33. * reveal.js
  34. * https://revealjs.com
  35. * MIT licensed
  36. *
  37. * Copyright (C) 2011-2022 Hakim El Hattab, https://hakim.se
  38. */
  39. export default function( revealElement, options ) {
  40. // Support initialization with no args, one arg
  41. // [options] or two args [revealElement, options]
  42. if( arguments.length < 2 ) {
  43. options = arguments[0];
  44. revealElement = document.querySelector( '.reveal' );
  45. }
  46. const Reveal = {};
  47. // Configuration defaults, can be overridden at initialization time
  48. let config = {},
  49. // Flags if initialize() has been invoked for this reveal instance
  50. initialized = false,
  51. // Flags if reveal.js is loaded (has dispatched the 'ready' event)
  52. ready = false,
  53. // The horizontal and vertical index of the currently active slide
  54. indexh,
  55. indexv,
  56. // The previous and current slide HTML elements
  57. previousSlide,
  58. currentSlide,
  59. // Remember which directions that the user has navigated towards
  60. navigationHistory = {
  61. hasNavigatedHorizontally: false,
  62. hasNavigatedVertically: false
  63. },
  64. // Slides may have a data-state attribute which we pick up and apply
  65. // as a class to the body. This list contains the combined state of
  66. // all current slides.
  67. state = [],
  68. // The current scale of the presentation (see width/height config)
  69. scale = 1,
  70. // CSS transform that is currently applied to the slides container,
  71. // split into two groups
  72. slidesTransform = { layout: '', overview: '' },
  73. // Cached references to DOM elements
  74. dom = {},
  75. // Flags if the interaction event listeners are bound
  76. eventsAreBound = false,
  77. // The current slide transition state; idle or running
  78. transition = 'idle',
  79. // The current auto-slide duration
  80. autoSlide = 0,
  81. // Auto slide properties
  82. autoSlidePlayer,
  83. autoSlideTimeout = 0,
  84. autoSlideStartTime = -1,
  85. autoSlidePaused = false,
  86. // Controllers for different aspects of our presentation. They're
  87. // all given direct references to this Reveal instance since there
  88. // may be multiple presentations running in parallel.
  89. slideContent = new SlideContent( Reveal ),
  90. slideNumber = new SlideNumber( Reveal ),
  91. jumpToSlide = new JumpToSlide( Reveal ),
  92. autoAnimate = new AutoAnimate( Reveal ),
  93. backgrounds = new Backgrounds( Reveal ),
  94. scrollView = new ScrollView( Reveal ),
  95. printView = new PrintView( Reveal ),
  96. fragments = new Fragments( Reveal ),
  97. overview = new Overview( Reveal ),
  98. keyboard = new Keyboard( Reveal ),
  99. location = new Location( Reveal ),
  100. controls = new Controls( Reveal ),
  101. progress = new Progress( Reveal ),
  102. pointer = new Pointer( Reveal ),
  103. plugins = new Plugins( Reveal ),
  104. overlay = new Overlay( Reveal ),
  105. focus = new Focus( Reveal ),
  106. touch = new Touch( Reveal ),
  107. notes = new Notes( Reveal );
  108. /**
  109. * Starts up the presentation.
  110. */
  111. function initialize( initOptions ) {
  112. if( !revealElement ) throw 'Unable to find presentation root (<div class="reveal">).';
  113. if( initialized ) throw 'Reveal.js has already been initialized.';
  114. initialized = true;
  115. // Cache references to key DOM elements
  116. dom.wrapper = revealElement;
  117. dom.slides = revealElement.querySelector( '.slides' );
  118. if( !dom.slides ) throw 'Unable to find slides container (<div class="slides">).';
  119. // Compose our config object in order of increasing precedence:
  120. // 1. Default reveal.js options
  121. // 2. Options provided via Reveal.configure() prior to
  122. // initialization
  123. // 3. Options passed to the Reveal constructor
  124. // 4. Options passed to Reveal.initialize
  125. // 5. Query params
  126. config = { ...defaultConfig, ...config, ...options, ...initOptions, ...Util.getQueryHash() };
  127. // Legacy support for the ?print-pdf query
  128. if( /print-pdf/gi.test( window.location.search ) ) {
  129. config.view = 'print';
  130. }
  131. setViewport();
  132. // Force a layout when the whole page, incl fonts, has loaded
  133. window.addEventListener( 'load', layout, false );
  134. // Register plugins and load dependencies, then move on to #start()
  135. plugins.load( config.plugins, config.dependencies ).then( start );
  136. return new Promise( resolve => Reveal.on( 'ready', resolve ) );
  137. }
  138. /**
  139. * Encase the presentation in a reveal.js viewport. The
  140. * extent of the viewport differs based on configuration.
  141. */
  142. function setViewport() {
  143. // Embedded decks use the reveal element as their viewport
  144. if( config.embedded === true ) {
  145. dom.viewport = Util.closest( revealElement, '.reveal-viewport' ) || revealElement;
  146. }
  147. // Full-page decks use the body as their viewport
  148. else {
  149. dom.viewport = document.body;
  150. document.documentElement.classList.add( 'reveal-full-page' );
  151. }
  152. dom.viewport.classList.add( 'reveal-viewport' );
  153. }
  154. /**
  155. * Starts up reveal.js by binding input events and navigating
  156. * to the current URL deeplink if there is one.
  157. */
  158. function start() {
  159. // Don't proceed if this instance has been destroyed
  160. if( initialized === false ) return;
  161. ready = true;
  162. // Remove slides hidden with data-visibility
  163. removeHiddenSlides();
  164. // Make sure we've got all the DOM elements we need
  165. setupDOM();
  166. // Listen to messages posted to this window
  167. setupPostMessage();
  168. // Prevent the slides from being scrolled out of view
  169. setupScrollPrevention();
  170. // Adds bindings for fullscreen mode
  171. setupFullscreen();
  172. // Resets all vertical slides so that only the first is visible
  173. resetVerticalSlides();
  174. // Updates the presentation to match the current configuration values
  175. configure();
  176. // Create slide backgrounds
  177. backgrounds.update( true );
  178. // Activate the print/scroll view if configured
  179. activateInitialView();
  180. // Read the initial hash
  181. location.readURL();
  182. // Notify listeners that the presentation is ready but use a 1ms
  183. // timeout to ensure it's not fired synchronously after #initialize()
  184. setTimeout( () => {
  185. // Enable transitions now that we're loaded
  186. dom.slides.classList.remove( 'no-transition' );
  187. dom.wrapper.classList.add( 'ready' );
  188. dispatchEvent({
  189. type: 'ready',
  190. data: {
  191. indexh,
  192. indexv,
  193. currentSlide
  194. }
  195. });
  196. }, 1 );
  197. }
  198. /**
  199. * Activates the correct reveal.js view based on our config.
  200. * This is only invoked once during initialization.
  201. */
  202. function activateInitialView() {
  203. const activatePrintView = config.view === 'print';
  204. const activateScrollView = config.view === 'scroll' || config.view === 'reader';
  205. if( activatePrintView || activateScrollView ) {
  206. if( activatePrintView ) {
  207. removeEventListeners();
  208. }
  209. else {
  210. touch.unbind();
  211. }
  212. // Avoid content flickering during layout
  213. dom.viewport.classList.add( 'loading-scroll-mode' );
  214. if( activatePrintView ) {
  215. // The document needs to have loaded for the PDF layout
  216. // measurements to be accurate
  217. if( document.readyState === 'complete' ) {
  218. printView.activate();
  219. }
  220. else {
  221. window.addEventListener( 'load', () => printView.activate() );
  222. }
  223. }
  224. else {
  225. scrollView.activate();
  226. }
  227. }
  228. }
  229. /**
  230. * Removes all slides with data-visibility="hidden". This
  231. * is done right before the rest of the presentation is
  232. * initialized.
  233. *
  234. * If you want to show all hidden slides, initialize
  235. * reveal.js with showHiddenSlides set to true.
  236. */
  237. function removeHiddenSlides() {
  238. if( !config.showHiddenSlides ) {
  239. Util.queryAll( dom.wrapper, 'section[data-visibility="hidden"]' ).forEach( slide => {
  240. const parent = slide.parentNode;
  241. // If this slide is part of a stack and that stack will be
  242. // empty after removing the hidden slide, remove the entire
  243. // stack
  244. if( parent.childElementCount === 1 && /section/i.test( parent.nodeName ) ) {
  245. parent.remove();
  246. }
  247. else {
  248. slide.remove();
  249. }
  250. } );
  251. }
  252. }
  253. /**
  254. * Finds and stores references to DOM elements which are
  255. * required by the presentation. If a required element is
  256. * not found, it is created.
  257. */
  258. function setupDOM() {
  259. // Prevent transitions while we're loading
  260. dom.slides.classList.add( 'no-transition' );
  261. if( Device.isMobile ) {
  262. dom.wrapper.classList.add( 'no-hover' );
  263. }
  264. else {
  265. dom.wrapper.classList.remove( 'no-hover' );
  266. }
  267. backgrounds.render();
  268. slideNumber.render();
  269. jumpToSlide.render();
  270. controls.render();
  271. progress.render();
  272. notes.render();
  273. // Overlay graphic which is displayed during the paused mode
  274. dom.pauseOverlay = Util.createSingletonNode( dom.wrapper, 'div', 'pause-overlay', config.controls ? '<button class="resume-button">Resume presentation</button>' : null );
  275. dom.statusElement = createStatusElement();
  276. dom.wrapper.setAttribute( 'role', 'application' );
  277. }
  278. /**
  279. * Creates a hidden div with role aria-live to announce the
  280. * current slide content. Hide the div off-screen to make it
  281. * available only to Assistive Technologies.
  282. *
  283. * @return {HTMLElement}
  284. */
  285. function createStatusElement() {
  286. let statusElement = dom.wrapper.querySelector( '.aria-status' );
  287. if( !statusElement ) {
  288. statusElement = document.createElement( 'div' );
  289. statusElement.style.position = 'absolute';
  290. statusElement.style.height = '1px';
  291. statusElement.style.width = '1px';
  292. statusElement.style.overflow = 'hidden';
  293. statusElement.style.clip = 'rect( 1px, 1px, 1px, 1px )';
  294. statusElement.classList.add( 'aria-status' );
  295. statusElement.setAttribute( 'aria-live', 'polite' );
  296. statusElement.setAttribute( 'aria-atomic','true' );
  297. dom.wrapper.appendChild( statusElement );
  298. }
  299. return statusElement;
  300. }
  301. /**
  302. * Announces the given text to screen readers.
  303. */
  304. function announceStatus( value ) {
  305. dom.statusElement.textContent = value;
  306. }
  307. /**
  308. * Converts the given HTML element into a string of text
  309. * that can be announced to a screen reader. Hidden
  310. * elements are excluded.
  311. */
  312. function getStatusText( node ) {
  313. let text = '';
  314. // Text node
  315. if( node.nodeType === 3 ) {
  316. text += node.textContent;
  317. }
  318. // Element node
  319. else if( node.nodeType === 1 ) {
  320. let isAriaHidden = node.getAttribute( 'aria-hidden' );
  321. let isDisplayHidden = window.getComputedStyle( node )['display'] === 'none';
  322. if( isAriaHidden !== 'true' && !isDisplayHidden ) {
  323. Array.from( node.childNodes ).forEach( child => {
  324. text += getStatusText( child );
  325. } );
  326. }
  327. }
  328. text = text.trim();
  329. return text === '' ? '' : text + ' ';
  330. }
  331. /**
  332. * This is an unfortunate necessity. Some actions – such as
  333. * an input field being focused in an iframe or using the
  334. * keyboard to expand text selection beyond the bounds of
  335. * a slide – can trigger our content to be pushed out of view.
  336. * This scrolling can not be prevented by hiding overflow in
  337. * CSS (we already do) so we have to resort to repeatedly
  338. * checking if the slides have been offset :(
  339. */
  340. function setupScrollPrevention() {
  341. setInterval( () => {
  342. if( !scrollView.isActive() && dom.wrapper.scrollTop !== 0 || dom.wrapper.scrollLeft !== 0 ) {
  343. dom.wrapper.scrollTop = 0;
  344. dom.wrapper.scrollLeft = 0;
  345. }
  346. }, 1000 );
  347. }
  348. /**
  349. * After entering fullscreen we need to force a layout to
  350. * get our presentations to scale correctly. This behavior
  351. * is inconsistent across browsers but a force layout seems
  352. * to normalize it.
  353. */
  354. function setupFullscreen() {
  355. document.addEventListener( 'fullscreenchange', onFullscreenChange );
  356. document.addEventListener( 'webkitfullscreenchange', onFullscreenChange );
  357. }
  358. /**
  359. * Registers a listener to postMessage events, this makes it
  360. * possible to call all reveal.js API methods from another
  361. * window. For example:
  362. *
  363. * revealWindow.postMessage( JSON.stringify({
  364. * method: 'slide',
  365. * args: [ 2 ]
  366. * }), '*' );
  367. */
  368. function setupPostMessage() {
  369. if( config.postMessage ) {
  370. window.addEventListener( 'message', onPostMessage, false );
  371. }
  372. }
  373. /**
  374. * Applies the configuration settings from the config
  375. * object. May be called multiple times.
  376. *
  377. * @param {object} options
  378. */
  379. function configure( options ) {
  380. const oldConfig = { ...config }
  381. // New config options may be passed when this method
  382. // is invoked through the API after initialization
  383. if( typeof options === 'object' ) Util.extend( config, options );
  384. // Abort if reveal.js hasn't finished loading, config
  385. // changes will be applied automatically once ready
  386. if( Reveal.isReady() === false ) return;
  387. const numberOfSlides = dom.wrapper.querySelectorAll( SLIDES_SELECTOR ).length;
  388. // The transition is added as a class on the .reveal element
  389. dom.wrapper.classList.remove( oldConfig.transition );
  390. dom.wrapper.classList.add( config.transition );
  391. dom.wrapper.setAttribute( 'data-transition-speed', config.transitionSpeed );
  392. dom.wrapper.setAttribute( 'data-background-transition', config.backgroundTransition );
  393. // Expose our configured slide dimensions as custom props
  394. dom.viewport.style.setProperty( '--slide-width', typeof config.width === 'string' ? config.width : config.width + 'px' );
  395. dom.viewport.style.setProperty( '--slide-height', typeof config.height === 'string' ? config.height : config.height + 'px' );
  396. if( config.shuffle ) {
  397. shuffle();
  398. }
  399. Util.toggleClass( dom.wrapper, 'embedded', config.embedded );
  400. Util.toggleClass( dom.wrapper, 'rtl', config.rtl );
  401. Util.toggleClass( dom.wrapper, 'center', config.center );
  402. // Exit the paused mode if it was configured off
  403. if( config.pause === false ) {
  404. resume();
  405. }
  406. // Reset all changes made by auto-animations
  407. autoAnimate.reset();
  408. // Remove existing auto-slide controls
  409. if( autoSlidePlayer ) {
  410. autoSlidePlayer.destroy();
  411. autoSlidePlayer = null;
  412. }
  413. // Generate auto-slide controls if needed
  414. if( numberOfSlides > 1 && config.autoSlide && config.autoSlideStoppable ) {
  415. autoSlidePlayer = new Playback( dom.wrapper, () => {
  416. return Math.min( Math.max( ( Date.now() - autoSlideStartTime ) / autoSlide, 0 ), 1 );
  417. } );
  418. autoSlidePlayer.on( 'click', onAutoSlidePlayerClick );
  419. autoSlidePaused = false;
  420. }
  421. // Add the navigation mode to the DOM so we can adjust styling
  422. if( config.navigationMode !== 'default' ) {
  423. dom.wrapper.setAttribute( 'data-navigation-mode', config.navigationMode );
  424. }
  425. else {
  426. dom.wrapper.removeAttribute( 'data-navigation-mode' );
  427. }
  428. notes.configure( config, oldConfig );
  429. focus.configure( config, oldConfig );
  430. pointer.configure( config, oldConfig );
  431. controls.configure( config, oldConfig );
  432. progress.configure( config, oldConfig );
  433. keyboard.configure( config, oldConfig );
  434. fragments.configure( config, oldConfig );
  435. slideNumber.configure( config, oldConfig );
  436. sync();
  437. }
  438. /**
  439. * Binds all event listeners.
  440. */
  441. function addEventListeners() {
  442. eventsAreBound = true;
  443. window.addEventListener( 'resize', onWindowResize, false );
  444. if( config.touch ) touch.bind();
  445. if( config.keyboard ) keyboard.bind();
  446. if( config.progress ) progress.bind();
  447. if( config.respondToHashChanges ) location.bind();
  448. controls.bind();
  449. focus.bind();
  450. dom.slides.addEventListener( 'click', onSlidesClicked, false );
  451. dom.slides.addEventListener( 'transitionend', onTransitionEnd, false );
  452. dom.pauseOverlay.addEventListener( 'click', resume, false );
  453. if( config.focusBodyOnPageVisibilityChange ) {
  454. document.addEventListener( 'visibilitychange', onPageVisibilityChange, false );
  455. }
  456. }
  457. /**
  458. * Unbinds all event listeners.
  459. */
  460. function removeEventListeners() {
  461. eventsAreBound = false;
  462. touch.unbind();
  463. focus.unbind();
  464. keyboard.unbind();
  465. controls.unbind();
  466. progress.unbind();
  467. location.unbind();
  468. window.removeEventListener( 'resize', onWindowResize, false );
  469. dom.slides.removeEventListener( 'click', onSlidesClicked, false );
  470. dom.slides.removeEventListener( 'transitionend', onTransitionEnd, false );
  471. dom.pauseOverlay.removeEventListener( 'click', resume, false );
  472. }
  473. /**
  474. * Uninitializes reveal.js by undoing changes made to the
  475. * DOM and removing all event listeners.
  476. */
  477. function destroy() {
  478. initialized = false;
  479. // There's nothing to destroy if this instance hasn't finished
  480. // initializing
  481. if( ready === false ) return;
  482. removeEventListeners();
  483. cancelAutoSlide();
  484. // Destroy controllers
  485. notes.destroy();
  486. focus.destroy();
  487. overlay.destroy();
  488. plugins.destroy();
  489. pointer.destroy();
  490. controls.destroy();
  491. progress.destroy();
  492. backgrounds.destroy();
  493. slideNumber.destroy();
  494. jumpToSlide.destroy();
  495. // Remove event listeners
  496. document.removeEventListener( 'fullscreenchange', onFullscreenChange );
  497. document.removeEventListener( 'webkitfullscreenchange', onFullscreenChange );
  498. document.removeEventListener( 'visibilitychange', onPageVisibilityChange, false );
  499. window.removeEventListener( 'message', onPostMessage, false );
  500. window.removeEventListener( 'load', layout, false );
  501. // Undo DOM changes
  502. if( dom.pauseOverlay ) dom.pauseOverlay.remove();
  503. if( dom.statusElement ) dom.statusElement.remove();
  504. document.documentElement.classList.remove( 'reveal-full-page' );
  505. dom.wrapper.classList.remove( 'ready', 'center', 'has-horizontal-slides', 'has-vertical-slides' );
  506. dom.wrapper.removeAttribute( 'data-transition-speed' );
  507. dom.wrapper.removeAttribute( 'data-background-transition' );
  508. dom.viewport.classList.remove( 'reveal-viewport' );
  509. dom.viewport.style.removeProperty( '--slide-width' );
  510. dom.viewport.style.removeProperty( '--slide-height' );
  511. dom.slides.style.removeProperty( 'width' );
  512. dom.slides.style.removeProperty( 'height' );
  513. dom.slides.style.removeProperty( 'zoom' );
  514. dom.slides.style.removeProperty( 'left' );
  515. dom.slides.style.removeProperty( 'top' );
  516. dom.slides.style.removeProperty( 'bottom' );
  517. dom.slides.style.removeProperty( 'right' );
  518. dom.slides.style.removeProperty( 'transform' );
  519. Array.from( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) ).forEach( slide => {
  520. slide.style.removeProperty( 'display' );
  521. slide.style.removeProperty( 'top' );
  522. slide.removeAttribute( 'hidden' );
  523. slide.removeAttribute( 'aria-hidden' );
  524. } );
  525. }
  526. /**
  527. * Adds a listener to one of our custom reveal.js events,
  528. * like slidechanged.
  529. */
  530. function on( type, listener, useCapture ) {
  531. revealElement.addEventListener( type, listener, useCapture );
  532. }
  533. /**
  534. * Unsubscribes from a reveal.js event.
  535. */
  536. function off( type, listener, useCapture ) {
  537. revealElement.removeEventListener( type, listener, useCapture );
  538. }
  539. /**
  540. * Applies CSS transforms to the slides container. The container
  541. * is transformed from two separate sources: layout and the overview
  542. * mode.
  543. *
  544. * @param {object} transforms
  545. */
  546. function transformSlides( transforms ) {
  547. // Pick up new transforms from arguments
  548. if( typeof transforms.layout === 'string' ) slidesTransform.layout = transforms.layout;
  549. if( typeof transforms.overview === 'string' ) slidesTransform.overview = transforms.overview;
  550. // Apply the transforms to the slides container
  551. if( slidesTransform.layout ) {
  552. Util.transformElement( dom.slides, slidesTransform.layout + ' ' + slidesTransform.overview );
  553. }
  554. else {
  555. Util.transformElement( dom.slides, slidesTransform.overview );
  556. }
  557. }
  558. /**
  559. * Dispatches an event of the specified type from the
  560. * reveal DOM element.
  561. */
  562. function dispatchEvent({ target=dom.wrapper, type, data, bubbles=true }) {
  563. let event = document.createEvent( 'HTMLEvents', 1, 2 );
  564. event.initEvent( type, bubbles, true );
  565. Util.extend( event, data );
  566. target.dispatchEvent( event );
  567. if( target === dom.wrapper ) {
  568. // If we're in an iframe, post each reveal.js event to the
  569. // parent window. Used by the notes plugin
  570. dispatchPostMessage( type );
  571. }
  572. return event;
  573. }
  574. /**
  575. * Dispatches a slidechanged event.
  576. *
  577. * @param {string} origin Used to identify multiplex clients
  578. */
  579. function dispatchSlideChanged( origin ) {
  580. dispatchEvent({
  581. type: 'slidechanged',
  582. data: {
  583. indexh,
  584. indexv,
  585. previousSlide,
  586. currentSlide,
  587. origin
  588. }
  589. });
  590. }
  591. /**
  592. * Dispatched a postMessage of the given type from our window.
  593. */
  594. function dispatchPostMessage( type, data ) {
  595. if( config.postMessageEvents && window.parent !== window.self ) {
  596. let message = {
  597. namespace: 'reveal',
  598. eventName: type,
  599. state: getState()
  600. };
  601. Util.extend( message, data );
  602. window.parent.postMessage( JSON.stringify( message ), '*' );
  603. }
  604. }
  605. /**
  606. * Applies JavaScript-controlled layout rules to the
  607. * presentation.
  608. */
  609. function layout() {
  610. if( dom.wrapper && !printView.isActive() ) {
  611. const viewportWidth = dom.viewport.offsetWidth;
  612. const viewportHeight = dom.viewport.offsetHeight;
  613. if( !config.disableLayout ) {
  614. // On some mobile devices '100vh' is taller than the visible
  615. // viewport which leads to part of the presentation being
  616. // cut off. To work around this we define our own '--vh' custom
  617. // property where 100x adds up to the correct height.
  618. //
  619. // https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
  620. if( Device.isMobile && !config.embedded ) {
  621. document.documentElement.style.setProperty( '--vh', ( window.innerHeight * 0.01 ) + 'px' );
  622. }
  623. const size = scrollView.isActive() ?
  624. getComputedSlideSize( viewportWidth, viewportHeight ) :
  625. getComputedSlideSize();
  626. const oldScale = scale;
  627. // Layout the contents of the slides
  628. layoutSlideContents( config.width, config.height );
  629. dom.slides.style.width = size.width + 'px';
  630. dom.slides.style.height = size.height + 'px';
  631. // Determine scale of content to fit within available space
  632. scale = Math.min( size.presentationWidth / size.width, size.presentationHeight / size.height );
  633. // Respect max/min scale settings
  634. scale = Math.max( scale, config.minScale );
  635. scale = Math.min( scale, config.maxScale );
  636. // Don't apply any scaling styles if scale is 1 or we're
  637. // in the scroll view
  638. if( scale === 1 || scrollView.isActive() ) {
  639. dom.slides.style.zoom = '';
  640. dom.slides.style.left = '';
  641. dom.slides.style.top = '';
  642. dom.slides.style.bottom = '';
  643. dom.slides.style.right = '';
  644. transformSlides( { layout: '' } );
  645. }
  646. else {
  647. dom.slides.style.zoom = '';
  648. dom.slides.style.left = '50%';
  649. dom.slides.style.top = '50%';
  650. dom.slides.style.bottom = 'auto';
  651. dom.slides.style.right = 'auto';
  652. transformSlides( { layout: 'translate(-50%, -50%) scale('+ scale +')' } );
  653. }
  654. // Select all slides, vertical and horizontal
  655. const slides = Array.from( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) );
  656. for( let i = 0, len = slides.length; i < len; i++ ) {
  657. const slide = slides[ i ];
  658. // Don't bother updating invisible slides
  659. if( slide.style.display === 'none' ) {
  660. continue;
  661. }
  662. if( ( config.center || slide.classList.contains( 'center' ) ) ) {
  663. // Vertical stacks are not centred since their section
  664. // children will be
  665. if( slide.classList.contains( 'stack' ) ) {
  666. slide.style.top = 0;
  667. }
  668. else {
  669. slide.style.top = Math.max( ( size.height - slide.scrollHeight ) / 2, 0 ) + 'px';
  670. }
  671. }
  672. else {
  673. slide.style.top = '';
  674. }
  675. }
  676. if( oldScale !== scale ) {
  677. dispatchEvent({
  678. type: 'resize',
  679. data: {
  680. oldScale,
  681. scale,
  682. size
  683. }
  684. });
  685. }
  686. }
  687. checkResponsiveScrollView();
  688. dom.viewport.style.setProperty( '--slide-scale', scale );
  689. dom.viewport.style.setProperty( '--viewport-width', viewportWidth + 'px' );
  690. dom.viewport.style.setProperty( '--viewport-height', viewportHeight + 'px' );
  691. scrollView.layout();
  692. progress.update();
  693. backgrounds.updateParallax();
  694. if( overview.isActive() ) {
  695. overview.update();
  696. }
  697. }
  698. }
  699. /**
  700. * Applies layout logic to the contents of all slides in
  701. * the presentation.
  702. *
  703. * @param {string|number} width
  704. * @param {string|number} height
  705. */
  706. function layoutSlideContents( width, height ) {
  707. // Handle sizing of elements with the 'r-stretch' class
  708. Util.queryAll( dom.slides, 'section > .stretch, section > .r-stretch' ).forEach( element => {
  709. // Determine how much vertical space we can use
  710. let remainingHeight = Util.getRemainingHeight( element, height );
  711. // Consider the aspect ratio of media elements
  712. if( /(img|video)/gi.test( element.nodeName ) ) {
  713. const nw = element.naturalWidth || element.videoWidth,
  714. nh = element.naturalHeight || element.videoHeight;
  715. const es = Math.min( width / nw, remainingHeight / nh );
  716. element.style.width = ( nw * es ) + 'px';
  717. element.style.height = ( nh * es ) + 'px';
  718. }
  719. else {
  720. element.style.width = width + 'px';
  721. element.style.height = remainingHeight + 'px';
  722. }
  723. } );
  724. }
  725. /**
  726. * Responsively activates the scroll mode when we reach the configured
  727. * activation width.
  728. */
  729. function checkResponsiveScrollView() {
  730. // Only proceed if...
  731. // 1. The DOM is ready
  732. // 2. Layouts aren't disabled via config
  733. // 3. We're not currently printing
  734. // 4. There is a scrollActivationWidth set
  735. // 5. The deck isn't configured to always use the scroll view
  736. if(
  737. dom.wrapper &&
  738. !config.disableLayout &&
  739. !printView.isActive() &&
  740. typeof config.scrollActivationWidth === 'number' &&
  741. config.view !== 'scroll'
  742. ) {
  743. const size = getComputedSlideSize();
  744. if( size.presentationWidth > 0 && size.presentationWidth <= config.scrollActivationWidth ) {
  745. if( !scrollView.isActive() ) {
  746. backgrounds.create();
  747. scrollView.activate()
  748. };
  749. }
  750. else {
  751. if( scrollView.isActive() ) scrollView.deactivate();
  752. }
  753. }
  754. }
  755. /**
  756. * Calculates the computed pixel size of our slides. These
  757. * values are based on the width and height configuration
  758. * options.
  759. *
  760. * @param {number} [presentationWidth=dom.wrapper.offsetWidth]
  761. * @param {number} [presentationHeight=dom.wrapper.offsetHeight]
  762. */
  763. function getComputedSlideSize( presentationWidth, presentationHeight ) {
  764. let width = config.width;
  765. let height = config.height;
  766. if( config.disableLayout ) {
  767. width = dom.slides.offsetWidth;
  768. height = dom.slides.offsetHeight;
  769. }
  770. const size = {
  771. // Slide size
  772. width: width,
  773. height: height,
  774. // Presentation size
  775. presentationWidth: presentationWidth || dom.wrapper.offsetWidth,
  776. presentationHeight: presentationHeight || dom.wrapper.offsetHeight
  777. };
  778. // Reduce available space by margin
  779. size.presentationWidth -= ( size.presentationWidth * config.margin );
  780. size.presentationHeight -= ( size.presentationHeight * config.margin );
  781. // Slide width may be a percentage of available width
  782. if( typeof size.width === 'string' && /%$/.test( size.width ) ) {
  783. size.width = parseInt( size.width, 10 ) / 100 * size.presentationWidth;
  784. }
  785. // Slide height may be a percentage of available height
  786. if( typeof size.height === 'string' && /%$/.test( size.height ) ) {
  787. size.height = parseInt( size.height, 10 ) / 100 * size.presentationHeight;
  788. }
  789. return size;
  790. }
  791. /**
  792. * Stores the vertical index of a stack so that the same
  793. * vertical slide can be selected when navigating to and
  794. * from the stack.
  795. *
  796. * @param {HTMLElement} stack The vertical stack element
  797. * @param {string|number} [v=0] Index to memorize
  798. */
  799. function setPreviousVerticalIndex( stack, v ) {
  800. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
  801. stack.setAttribute( 'data-previous-indexv', v || 0 );
  802. }
  803. }
  804. /**
  805. * Retrieves the vertical index which was stored using
  806. * #setPreviousVerticalIndex() or 0 if no previous index
  807. * exists.
  808. *
  809. * @param {HTMLElement} stack The vertical stack element
  810. */
  811. function getPreviousVerticalIndex( stack ) {
  812. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
  813. // Prefer manually defined start-indexv
  814. const attributeName = stack.hasAttribute( 'data-start-indexv' ) ? 'data-start-indexv' : 'data-previous-indexv';
  815. return parseInt( stack.getAttribute( attributeName ) || 0, 10 );
  816. }
  817. return 0;
  818. }
  819. /**
  820. * Checks if the current or specified slide is vertical
  821. * (nested within another slide).
  822. *
  823. * @param {HTMLElement} [slide=currentSlide] The slide to check
  824. * orientation of
  825. * @return {Boolean}
  826. */
  827. function isVerticalSlide( slide = currentSlide ) {
  828. return slide && slide.parentNode && !!slide.parentNode.nodeName.match( /section/i );
  829. }
  830. /**
  831. * Checks if the current or specified slide is a stack containing
  832. * vertical slides.
  833. *
  834. * @param {HTMLElement} [slide=currentSlide]
  835. * @return {Boolean}
  836. */
  837. function isVerticalStack( slide = currentSlide ) {
  838. return slide.classList.contains( '.stack' ) || slide.querySelector( 'section' ) !== null;
  839. }
  840. /**
  841. * Returns true if we're on the last slide in the current
  842. * vertical stack.
  843. */
  844. function isLastVerticalSlide() {
  845. if( currentSlide && isVerticalSlide( currentSlide ) ) {
  846. // Does this slide have a next sibling?
  847. if( currentSlide.nextElementSibling ) return false;
  848. return true;
  849. }
  850. return false;
  851. }
  852. /**
  853. * Returns true if we're currently on the first slide in
  854. * the presentation.
  855. */
  856. function isFirstSlide() {
  857. return indexh === 0 && indexv === 0;
  858. }
  859. /**
  860. * Returns true if we're currently on the last slide in
  861. * the presentation. If the last slide is a stack, we only
  862. * consider this the last slide if it's at the end of the
  863. * stack.
  864. */
  865. function isLastSlide() {
  866. if( currentSlide ) {
  867. // Does this slide have a next sibling?
  868. if( currentSlide.nextElementSibling ) return false;
  869. // If it's vertical, does its parent have a next sibling?
  870. if( isVerticalSlide( currentSlide ) && currentSlide.parentNode.nextElementSibling ) return false;
  871. return true;
  872. }
  873. return false;
  874. }
  875. /**
  876. * Enters the paused mode which fades everything on screen to
  877. * black.
  878. */
  879. function pause() {
  880. if( config.pause ) {
  881. const wasPaused = dom.wrapper.classList.contains( 'paused' );
  882. cancelAutoSlide();
  883. dom.wrapper.classList.add( 'paused' );
  884. if( wasPaused === false ) {
  885. dispatchEvent({ type: 'paused' });
  886. }
  887. }
  888. }
  889. /**
  890. * Exits from the paused mode.
  891. */
  892. function resume() {
  893. const wasPaused = dom.wrapper.classList.contains( 'paused' );
  894. dom.wrapper.classList.remove( 'paused' );
  895. cueAutoSlide();
  896. if( wasPaused ) {
  897. dispatchEvent({ type: 'resumed' });
  898. }
  899. }
  900. /**
  901. * Toggles the paused mode on and off.
  902. */
  903. function togglePause( override ) {
  904. if( typeof override === 'boolean' ) {
  905. override ? pause() : resume();
  906. }
  907. else {
  908. isPaused() ? resume() : pause();
  909. }
  910. }
  911. /**
  912. * Checks if we are currently in the paused mode.
  913. *
  914. * @return {Boolean}
  915. */
  916. function isPaused() {
  917. return dom.wrapper.classList.contains( 'paused' );
  918. }
  919. /**
  920. * Toggles visibility of the jump-to-slide UI.
  921. */
  922. function toggleJumpToSlide( override ) {
  923. if( typeof override === 'boolean' ) {
  924. override ? jumpToSlide.show() : jumpToSlide.hide();
  925. }
  926. else {
  927. jumpToSlide.isVisible() ? jumpToSlide.hide() : jumpToSlide.show();
  928. }
  929. }
  930. /**
  931. * Toggles the auto slide mode on and off.
  932. *
  933. * @param {Boolean} [override] Flag which sets the desired state.
  934. * True means autoplay starts, false means it stops.
  935. */
  936. function toggleAutoSlide( override ) {
  937. if( typeof override === 'boolean' ) {
  938. override ? resumeAutoSlide() : pauseAutoSlide();
  939. }
  940. else {
  941. autoSlidePaused ? resumeAutoSlide() : pauseAutoSlide();
  942. }
  943. }
  944. /**
  945. * Checks if the auto slide mode is currently on.
  946. *
  947. * @return {Boolean}
  948. */
  949. function isAutoSliding() {
  950. return !!( autoSlide && !autoSlidePaused );
  951. }
  952. /**
  953. * Steps from the current point in the presentation to the
  954. * slide which matches the specified horizontal and vertical
  955. * indices.
  956. *
  957. * @param {number} [h=indexh] Horizontal index of the target slide
  958. * @param {number} [v=indexv] Vertical index of the target slide
  959. * @param {number} [f] Index of a fragment within the
  960. * target slide to activate
  961. * @param {number} [origin] Origin for use in multimaster environments
  962. */
  963. function slide( h, v, f, origin ) {
  964. // Dispatch an event before the slide
  965. const slidechange = dispatchEvent({
  966. type: 'beforeslidechange',
  967. data: {
  968. indexh: h === undefined ? indexh : h,
  969. indexv: v === undefined ? indexv : v,
  970. origin
  971. }
  972. });
  973. // Abort if this slide change was prevented by an event listener
  974. if( slidechange.defaultPrevented ) return;
  975. // Remember where we were at before
  976. previousSlide = currentSlide;
  977. // Query all horizontal slides in the deck
  978. const horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  979. // If we're in scroll mode, we scroll the target slide into view
  980. // instead of running our standard slide transition
  981. if( scrollView.isActive() ) {
  982. const scrollToSlide = scrollView.getSlideByIndices( h, v );
  983. if( scrollToSlide ) scrollView.scrollToSlide( scrollToSlide );
  984. return;
  985. }
  986. // Abort if there are no slides
  987. if( horizontalSlides.length === 0 ) return;
  988. // If no vertical index is specified and the upcoming slide is a
  989. // stack, resume at its previous vertical index
  990. if( v === undefined && !overview.isActive() ) {
  991. v = getPreviousVerticalIndex( horizontalSlides[ h ] );
  992. }
  993. // If we were on a vertical stack, remember what vertical index
  994. // it was on so we can resume at the same position when returning
  995. if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
  996. setPreviousVerticalIndex( previousSlide.parentNode, indexv );
  997. }
  998. // Remember the state before this slide
  999. const stateBefore = state.concat();
  1000. // Reset the state array
  1001. state.length = 0;
  1002. let indexhBefore = indexh || 0,
  1003. indexvBefore = indexv || 0;
  1004. // Activate and transition to the new slide
  1005. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
  1006. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
  1007. // Dispatch an event if the slide changed
  1008. let slideChanged = ( indexh !== indexhBefore || indexv !== indexvBefore );
  1009. // Ensure that the previous slide is never the same as the current
  1010. if( !slideChanged ) previousSlide = null;
  1011. // Find the current horizontal slide and any possible vertical slides
  1012. // within it
  1013. let currentHorizontalSlide = horizontalSlides[ indexh ],
  1014. currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
  1015. // Indicate when we're on a vertical slide
  1016. revealElement.classList.toggle( 'is-vertical-slide', currentVerticalSlides.length > 1 );
  1017. // Store references to the previous and current slides
  1018. currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
  1019. let autoAnimateTransition = false;
  1020. // Detect if we're moving between two auto-animated slides
  1021. if( slideChanged && previousSlide && currentSlide && !overview.isActive() ) {
  1022. transition = 'running';
  1023. autoAnimateTransition = shouldAutoAnimateBetween( previousSlide, currentSlide, indexhBefore, indexvBefore );
  1024. // If this is an auto-animated transition, we disable the
  1025. // regular slide transition
  1026. //
  1027. // Note 20-03-2020:
  1028. // This needs to happen before we update slide visibility,
  1029. // otherwise transitions will still run in Safari.
  1030. if( autoAnimateTransition ) {
  1031. dom.slides.classList.add( 'disable-slide-transitions' )
  1032. }
  1033. }
  1034. // Update the visibility of slides now that the indices have changed
  1035. updateSlidesVisibility();
  1036. layout();
  1037. // Update the overview if it's currently active
  1038. if( overview.isActive() ) {
  1039. overview.update();
  1040. }
  1041. // Show fragment, if specified
  1042. if( typeof f !== 'undefined' ) {
  1043. fragments.goto( f );
  1044. }
  1045. // Solves an edge case where the previous slide maintains the
  1046. // 'present' class when navigating between adjacent vertical
  1047. // stacks
  1048. if( previousSlide && previousSlide !== currentSlide ) {
  1049. previousSlide.classList.remove( 'present' );
  1050. previousSlide.setAttribute( 'aria-hidden', 'true' );
  1051. // Reset all slides upon navigate to home
  1052. if( isFirstSlide() ) {
  1053. // Launch async task
  1054. setTimeout( () => {
  1055. getVerticalStacks().forEach( slide => {
  1056. setPreviousVerticalIndex( slide, 0 );
  1057. } );
  1058. }, 0 );
  1059. }
  1060. }
  1061. // Apply the new state
  1062. stateLoop: for( let i = 0, len = state.length; i < len; i++ ) {
  1063. // Check if this state existed on the previous slide. If it
  1064. // did, we will avoid adding it repeatedly
  1065. for( let j = 0; j < stateBefore.length; j++ ) {
  1066. if( stateBefore[j] === state[i] ) {
  1067. stateBefore.splice( j, 1 );
  1068. continue stateLoop;
  1069. }
  1070. }
  1071. dom.viewport.classList.add( state[i] );
  1072. // Dispatch custom event matching the state's name
  1073. dispatchEvent({ type: state[i] });
  1074. }
  1075. // Clean up the remains of the previous state
  1076. while( stateBefore.length ) {
  1077. dom.viewport.classList.remove( stateBefore.pop() );
  1078. }
  1079. if( slideChanged ) {
  1080. dispatchSlideChanged( origin );
  1081. }
  1082. // Handle embedded content
  1083. if( slideChanged || !previousSlide ) {
  1084. slideContent.stopEmbeddedContent( previousSlide );
  1085. slideContent.startEmbeddedContent( currentSlide );
  1086. }
  1087. // Announce the current slide contents to screen readers
  1088. // Use animation frame to prevent getComputedStyle in getStatusText
  1089. // from triggering layout mid-frame
  1090. requestAnimationFrame( () => {
  1091. announceStatus( getStatusText( currentSlide ) );
  1092. });
  1093. progress.update();
  1094. controls.update();
  1095. notes.update();
  1096. backgrounds.update();
  1097. backgrounds.updateParallax();
  1098. slideNumber.update();
  1099. fragments.update();
  1100. // Update the URL hash
  1101. location.writeURL();
  1102. cueAutoSlide();
  1103. // Auto-animation
  1104. if( autoAnimateTransition ) {
  1105. setTimeout( () => {
  1106. dom.slides.classList.remove( 'disable-slide-transitions' );
  1107. }, 0 );
  1108. if( config.autoAnimate ) {
  1109. // Run the auto-animation between our slides
  1110. autoAnimate.run( previousSlide, currentSlide );
  1111. }
  1112. }
  1113. }
  1114. /**
  1115. * Checks whether or not an auto-animation should take place between
  1116. * the two given slides.
  1117. *
  1118. * @param {HTMLElement} fromSlide
  1119. * @param {HTMLElement} toSlide
  1120. * @param {number} indexhBefore
  1121. * @param {number} indexvBefore
  1122. *
  1123. * @returns {boolean}
  1124. */
  1125. function shouldAutoAnimateBetween( fromSlide, toSlide, indexhBefore, indexvBefore ) {
  1126. return fromSlide.hasAttribute( 'data-auto-animate' ) && toSlide.hasAttribute( 'data-auto-animate' ) &&
  1127. fromSlide.getAttribute( 'data-auto-animate-id' ) === toSlide.getAttribute( 'data-auto-animate-id' ) &&
  1128. !( ( indexh > indexhBefore || indexv > indexvBefore ) ? toSlide : fromSlide ).hasAttribute( 'data-auto-animate-restart' );
  1129. }
  1130. /**
  1131. * Called anytime a new slide should be activated while in the scroll
  1132. * view. The active slide is the page that occupies the most space in
  1133. * the scrollable viewport.
  1134. *
  1135. * @param {number} pageIndex
  1136. * @param {HTMLElement} slideElement
  1137. */
  1138. function setCurrentScrollPage( slideElement, h, v ) {
  1139. let indexhBefore = indexh || 0;
  1140. indexh = h;
  1141. indexv = v;
  1142. const slideChanged = currentSlide !== slideElement;
  1143. previousSlide = currentSlide;
  1144. currentSlide = slideElement;
  1145. if( currentSlide && previousSlide ) {
  1146. if( config.autoAnimate && shouldAutoAnimateBetween( previousSlide, currentSlide, indexhBefore, indexv ) ) {
  1147. // Run the auto-animation between our slides
  1148. autoAnimate.run( previousSlide, currentSlide );
  1149. }
  1150. }
  1151. // Start or stop embedded content like videos and iframes
  1152. if( slideChanged ) {
  1153. if( previousSlide ) {
  1154. slideContent.stopEmbeddedContent( previousSlide );
  1155. slideContent.stopEmbeddedContent( previousSlide.slideBackgroundElement );
  1156. }
  1157. slideContent.startEmbeddedContent( currentSlide );
  1158. slideContent.startEmbeddedContent( currentSlide.slideBackgroundElement );
  1159. }
  1160. requestAnimationFrame( () => {
  1161. announceStatus( getStatusText( currentSlide ) );
  1162. });
  1163. dispatchSlideChanged();
  1164. }
  1165. /**
  1166. * Syncs the presentation with the current DOM. Useful
  1167. * when new slides or control elements are added or when
  1168. * the configuration has changed.
  1169. */
  1170. function sync() {
  1171. // Subscribe to input
  1172. removeEventListeners();
  1173. addEventListeners();
  1174. // Force a layout to make sure the current config is accounted for
  1175. layout();
  1176. // Reflect the current autoSlide value
  1177. autoSlide = config.autoSlide;
  1178. // Start auto-sliding if it's enabled
  1179. cueAutoSlide();
  1180. // Re-create all slide backgrounds
  1181. backgrounds.create();
  1182. // Write the current hash to the URL
  1183. location.writeURL();
  1184. if( config.sortFragmentsOnSync === true ) {
  1185. fragments.sortAll();
  1186. }
  1187. controls.update();
  1188. progress.update();
  1189. updateSlidesVisibility();
  1190. notes.update();
  1191. notes.updateVisibility();
  1192. overlay.update();
  1193. backgrounds.update( true );
  1194. slideNumber.update();
  1195. slideContent.formatEmbeddedContent();
  1196. // Start or stop embedded content depending on global config
  1197. if( config.autoPlayMedia === false ) {
  1198. slideContent.stopEmbeddedContent( currentSlide, { unloadIframes: false } );
  1199. }
  1200. else {
  1201. slideContent.startEmbeddedContent( currentSlide );
  1202. }
  1203. if( overview.isActive() ) {
  1204. overview.layout();
  1205. }
  1206. }
  1207. /**
  1208. * Updates reveal.js to keep in sync with new slide attributes. For
  1209. * example, if you add a new `data-background-image` you can call
  1210. * this to have reveal.js render the new background image.
  1211. *
  1212. * Similar to #sync() but more efficient when you only need to
  1213. * refresh a specific slide.
  1214. *
  1215. * @param {HTMLElement} slide
  1216. */
  1217. function syncSlide( slide = currentSlide ) {
  1218. backgrounds.sync( slide );
  1219. fragments.sync( slide );
  1220. slideContent.load( slide );
  1221. backgrounds.update();
  1222. notes.update();
  1223. }
  1224. /**
  1225. * Resets all vertical slides so that only the first
  1226. * is visible.
  1227. */
  1228. function resetVerticalSlides() {
  1229. getHorizontalSlides().forEach( horizontalSlide => {
  1230. Util.queryAll( horizontalSlide, 'section' ).forEach( ( verticalSlide, y ) => {
  1231. if( y > 0 ) {
  1232. verticalSlide.classList.remove( 'present' );
  1233. verticalSlide.classList.remove( 'past' );
  1234. verticalSlide.classList.add( 'future' );
  1235. verticalSlide.setAttribute( 'aria-hidden', 'true' );
  1236. }
  1237. } );
  1238. } );
  1239. }
  1240. /**
  1241. * Randomly shuffles all slides in the deck.
  1242. */
  1243. function shuffle( slides = getHorizontalSlides() ) {
  1244. slides.forEach( ( slide, i ) => {
  1245. // Insert the slide next to a randomly picked sibling slide
  1246. // slide. This may cause the slide to insert before itself,
  1247. // but that's not an issue.
  1248. let beforeSlide = slides[ Math.floor( Math.random() * slides.length ) ];
  1249. if( beforeSlide.parentNode === slide.parentNode ) {
  1250. slide.parentNode.insertBefore( slide, beforeSlide );
  1251. }
  1252. // Randomize the order of vertical slides (if there are any)
  1253. let verticalSlides = slide.querySelectorAll( 'section' );
  1254. if( verticalSlides.length ) {
  1255. shuffle( verticalSlides );
  1256. }
  1257. } );
  1258. }
  1259. /**
  1260. * Updates one dimension of slides by showing the slide
  1261. * with the specified index.
  1262. *
  1263. * @param {string} selector A CSS selector that will fetch
  1264. * the group of slides we are working with
  1265. * @param {number} index The index of the slide that should be
  1266. * shown
  1267. *
  1268. * @return {number} The index of the slide that is now shown,
  1269. * might differ from the passed in index if it was out of
  1270. * bounds.
  1271. */
  1272. function updateSlides( selector, index ) {
  1273. // Select all slides and convert the NodeList result to
  1274. // an array
  1275. let slides = Util.queryAll( dom.wrapper, selector ),
  1276. slidesLength = slides.length;
  1277. let printMode = scrollView.isActive() || printView.isActive();
  1278. let loopedForwards = false;
  1279. let loopedBackwards = false;
  1280. if( slidesLength ) {
  1281. // Should the index loop?
  1282. if( config.loop ) {
  1283. if( index >= slidesLength ) loopedForwards = true;
  1284. index %= slidesLength;
  1285. if( index < 0 ) {
  1286. index = slidesLength + index;
  1287. loopedBackwards = true;
  1288. }
  1289. }
  1290. // Enforce max and minimum index bounds
  1291. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  1292. for( let i = 0; i < slidesLength; i++ ) {
  1293. let element = slides[i];
  1294. let reverse = config.rtl && !isVerticalSlide( element );
  1295. // Avoid .remove() with multiple args for IE11 support
  1296. element.classList.remove( 'past' );
  1297. element.classList.remove( 'present' );
  1298. element.classList.remove( 'future' );
  1299. // http://www.w3.org/html/wg/drafts/html/master/editing.html#the-hidden-attribute
  1300. element.setAttribute( 'hidden', '' );
  1301. element.setAttribute( 'aria-hidden', 'true' );
  1302. // If this element contains vertical slides
  1303. if( element.querySelector( 'section' ) ) {
  1304. element.classList.add( 'stack' );
  1305. }
  1306. // If we're printing static slides, all slides are "present"
  1307. if( printMode ) {
  1308. element.classList.add( 'present' );
  1309. continue;
  1310. }
  1311. if( i < index ) {
  1312. // Any element previous to index is given the 'past' class
  1313. element.classList.add( reverse ? 'future' : 'past' );
  1314. if( config.fragments ) {
  1315. // Show all fragments in prior slides
  1316. showFragmentsIn( element );
  1317. }
  1318. }
  1319. else if( i > index ) {
  1320. // Any element subsequent to index is given the 'future' class
  1321. element.classList.add( reverse ? 'past' : 'future' );
  1322. if( config.fragments ) {
  1323. // Hide all fragments in future slides
  1324. hideFragmentsIn( element );
  1325. }
  1326. }
  1327. // Update the visibility of fragments when a presentation loops
  1328. // in either direction
  1329. else if( i === index && config.fragments ) {
  1330. if( loopedForwards ) {
  1331. hideFragmentsIn( element );
  1332. }
  1333. else if( loopedBackwards ) {
  1334. showFragmentsIn( element );
  1335. }
  1336. }
  1337. }
  1338. let slide = slides[index];
  1339. let wasPresent = slide.classList.contains( 'present' );
  1340. // Mark the current slide as present
  1341. slide.classList.add( 'present' );
  1342. slide.removeAttribute( 'hidden' );
  1343. slide.removeAttribute( 'aria-hidden' );
  1344. if( !wasPresent ) {
  1345. // Dispatch an event indicating the slide is now visible
  1346. dispatchEvent({
  1347. target: slide,
  1348. type: 'visible',
  1349. bubbles: false
  1350. });
  1351. }
  1352. // If this slide has a state associated with it, add it
  1353. // onto the current state of the deck
  1354. let slideState = slide.getAttribute( 'data-state' );
  1355. if( slideState ) {
  1356. state = state.concat( slideState.split( ' ' ) );
  1357. }
  1358. }
  1359. else {
  1360. // Since there are no slides we can't be anywhere beyond the
  1361. // zeroth index
  1362. index = 0;
  1363. }
  1364. return index;
  1365. }
  1366. /**
  1367. * Shows all fragment elements within the given container.
  1368. */
  1369. function showFragmentsIn( container ) {
  1370. Util.queryAll( container, '.fragment' ).forEach( fragment => {
  1371. fragment.classList.add( 'visible' );
  1372. fragment.classList.remove( 'current-fragment' );
  1373. } );
  1374. }
  1375. /**
  1376. * Hides all fragment elements within the given container.
  1377. */
  1378. function hideFragmentsIn( container ) {
  1379. Util.queryAll( container, '.fragment.visible' ).forEach( fragment => {
  1380. fragment.classList.remove( 'visible', 'current-fragment' );
  1381. } );
  1382. }
  1383. /**
  1384. * Optimization method; hide all slides that are far away
  1385. * from the present slide.
  1386. */
  1387. function updateSlidesVisibility() {
  1388. // Select all slides and convert the NodeList result to
  1389. // an array
  1390. let horizontalSlides = getHorizontalSlides(),
  1391. horizontalSlidesLength = horizontalSlides.length,
  1392. distanceX,
  1393. distanceY;
  1394. if( horizontalSlidesLength && typeof indexh !== 'undefined' ) {
  1395. // The number of steps away from the present slide that will
  1396. // be visible
  1397. let viewDistance = overview.isActive() ? 10 : config.viewDistance;
  1398. // Shorten the view distance on devices that typically have
  1399. // less resources
  1400. if( Device.isMobile ) {
  1401. viewDistance = overview.isActive() ? 6 : config.mobileViewDistance;
  1402. }
  1403. // All slides need to be visible when exporting to PDF
  1404. if( printView.isActive() ) {
  1405. viewDistance = Number.MAX_VALUE;
  1406. }
  1407. for( let x = 0; x < horizontalSlidesLength; x++ ) {
  1408. let horizontalSlide = horizontalSlides[x];
  1409. let verticalSlides = Util.queryAll( horizontalSlide, 'section' ),
  1410. verticalSlidesLength = verticalSlides.length;
  1411. // Determine how far away this slide is from the present
  1412. distanceX = Math.abs( ( indexh || 0 ) - x ) || 0;
  1413. // If the presentation is looped, distance should measure
  1414. // 1 between the first and last slides
  1415. if( config.loop ) {
  1416. distanceX = Math.abs( ( ( indexh || 0 ) - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0;
  1417. }
  1418. // Show the horizontal slide if it's within the view distance
  1419. if( distanceX < viewDistance ) {
  1420. slideContent.load( horizontalSlide );
  1421. }
  1422. else {
  1423. slideContent.unload( horizontalSlide );
  1424. }
  1425. if( verticalSlidesLength ) {
  1426. let oy = getPreviousVerticalIndex( horizontalSlide );
  1427. for( let y = 0; y < verticalSlidesLength; y++ ) {
  1428. let verticalSlide = verticalSlides[y];
  1429. distanceY = x === ( indexh || 0 ) ? Math.abs( ( indexv || 0 ) - y ) : Math.abs( y - oy );
  1430. if( distanceX + distanceY < viewDistance ) {
  1431. slideContent.load( verticalSlide );
  1432. }
  1433. else {
  1434. slideContent.unload( verticalSlide );
  1435. }
  1436. }
  1437. }
  1438. }
  1439. // Flag if there are ANY vertical slides, anywhere in the deck
  1440. if( hasVerticalSlides() ) {
  1441. dom.wrapper.classList.add( 'has-vertical-slides' );
  1442. }
  1443. else {
  1444. dom.wrapper.classList.remove( 'has-vertical-slides' );
  1445. }
  1446. // Flag if there are ANY horizontal slides, anywhere in the deck
  1447. if( hasHorizontalSlides() ) {
  1448. dom.wrapper.classList.add( 'has-horizontal-slides' );
  1449. }
  1450. else {
  1451. dom.wrapper.classList.remove( 'has-horizontal-slides' );
  1452. }
  1453. }
  1454. }
  1455. /**
  1456. * Determine what available routes there are for navigation.
  1457. *
  1458. * @return {{left: boolean, right: boolean, up: boolean, down: boolean}}
  1459. */
  1460. function availableRoutes({ includeFragments = false } = {}) {
  1461. let horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1462. verticalSlides = dom.wrapper.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1463. let routes = {
  1464. left: indexh > 0,
  1465. right: indexh < horizontalSlides.length - 1,
  1466. up: indexv > 0,
  1467. down: indexv < verticalSlides.length - 1
  1468. };
  1469. // Looped presentations can always be navigated as long as
  1470. // there are slides available
  1471. if( config.loop ) {
  1472. if( horizontalSlides.length > 1 ) {
  1473. routes.left = true;
  1474. routes.right = true;
  1475. }
  1476. if( verticalSlides.length > 1 ) {
  1477. routes.up = true;
  1478. routes.down = true;
  1479. }
  1480. }
  1481. if ( horizontalSlides.length > 1 && config.navigationMode === 'linear' ) {
  1482. routes.right = routes.right || routes.down;
  1483. routes.left = routes.left || routes.up;
  1484. }
  1485. // If includeFragments is set, a route will be considered
  1486. // available if either a slid OR fragment is available in
  1487. // the given direction
  1488. if( includeFragments === true ) {
  1489. let fragmentRoutes = fragments.availableRoutes();
  1490. routes.left = routes.left || fragmentRoutes.prev;
  1491. routes.up = routes.up || fragmentRoutes.prev;
  1492. routes.down = routes.down || fragmentRoutes.next;
  1493. routes.right = routes.right || fragmentRoutes.next;
  1494. }
  1495. // Reverse horizontal controls for rtl
  1496. if( config.rtl ) {
  1497. let left = routes.left;
  1498. routes.left = routes.right;
  1499. routes.right = left;
  1500. }
  1501. return routes;
  1502. }
  1503. /**
  1504. * Returns the number of past slides. This can be used as a global
  1505. * flattened index for slides.
  1506. *
  1507. * @param {HTMLElement} [slide=currentSlide] The slide we're counting before
  1508. *
  1509. * @return {number} Past slide count
  1510. */
  1511. function getSlidePastCount( slide = currentSlide ) {
  1512. let horizontalSlides = getHorizontalSlides();
  1513. // The number of past slides
  1514. let pastCount = 0;
  1515. // Step through all slides and count the past ones
  1516. mainLoop: for( let i = 0; i < horizontalSlides.length; i++ ) {
  1517. let horizontalSlide = horizontalSlides[i];
  1518. let verticalSlides = horizontalSlide.querySelectorAll( 'section' );
  1519. for( let j = 0; j < verticalSlides.length; j++ ) {
  1520. // Stop as soon as we arrive at the present
  1521. if( verticalSlides[j] === slide ) {
  1522. break mainLoop;
  1523. }
  1524. // Don't count slides with the "uncounted" class
  1525. if( verticalSlides[j].dataset.visibility !== 'uncounted' ) {
  1526. pastCount++;
  1527. }
  1528. }
  1529. // Stop as soon as we arrive at the present
  1530. if( horizontalSlide === slide ) {
  1531. break;
  1532. }
  1533. // Don't count the wrapping section for vertical slides and
  1534. // slides marked as uncounted
  1535. if( horizontalSlide.classList.contains( 'stack' ) === false && horizontalSlide.dataset.visibility !== 'uncounted' ) {
  1536. pastCount++;
  1537. }
  1538. }
  1539. return pastCount;
  1540. }
  1541. /**
  1542. * Returns a value ranging from 0-1 that represents
  1543. * how far into the presentation we have navigated.
  1544. *
  1545. * @return {number}
  1546. */
  1547. function getProgress() {
  1548. // The number of past and total slides
  1549. let totalCount = getTotalSlides();
  1550. let pastCount = getSlidePastCount();
  1551. if( currentSlide ) {
  1552. let allFragments = currentSlide.querySelectorAll( '.fragment' );
  1553. // If there are fragments in the current slide those should be
  1554. // accounted for in the progress.
  1555. if( allFragments.length > 0 ) {
  1556. let visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
  1557. // This value represents how big a portion of the slide progress
  1558. // that is made up by its fragments (0-1)
  1559. let fragmentWeight = 0.9;
  1560. // Add fragment progress to the past slide count
  1561. pastCount += ( visibleFragments.length / allFragments.length ) * fragmentWeight;
  1562. }
  1563. }
  1564. return Math.min( pastCount / ( totalCount - 1 ), 1 );
  1565. }
  1566. /**
  1567. * Retrieves the h/v location and fragment of the current,
  1568. * or specified, slide.
  1569. *
  1570. * @param {HTMLElement} [slide] If specified, the returned
  1571. * index will be for this slide rather than the currently
  1572. * active one
  1573. *
  1574. * @return {{h: number, v: number, f: number}}
  1575. */
  1576. function getIndices( slide ) {
  1577. // By default, return the current indices
  1578. let h = indexh,
  1579. v = indexv,
  1580. f;
  1581. // If a slide is specified, return the indices of that slide
  1582. if( slide ) {
  1583. // In scroll mode the original h/x index is stored on the slide
  1584. if( scrollView.isActive() ) {
  1585. h = parseInt( slide.getAttribute( 'data-index-h' ), 10 );
  1586. if( slide.getAttribute( 'data-index-v' ) ) {
  1587. v = parseInt( slide.getAttribute( 'data-index-v' ), 10 );
  1588. }
  1589. }
  1590. else {
  1591. let isVertical = isVerticalSlide( slide );
  1592. let slideh = isVertical ? slide.parentNode : slide;
  1593. // Select all horizontal slides
  1594. let horizontalSlides = getHorizontalSlides();
  1595. // Now that we know which the horizontal slide is, get its index
  1596. h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
  1597. // Assume we're not vertical
  1598. v = undefined;
  1599. // If this is a vertical slide, grab the vertical index
  1600. if( isVertical ) {
  1601. v = Math.max( Util.queryAll( slide.parentNode, 'section' ).indexOf( slide ), 0 );
  1602. }
  1603. }
  1604. }
  1605. if( !slide && currentSlide ) {
  1606. let hasFragments = currentSlide.querySelectorAll( '.fragment' ).length > 0;
  1607. if( hasFragments ) {
  1608. let currentFragment = currentSlide.querySelector( '.current-fragment' );
  1609. if( currentFragment && currentFragment.hasAttribute( 'data-fragment-index' ) ) {
  1610. f = parseInt( currentFragment.getAttribute( 'data-fragment-index' ), 10 );
  1611. }
  1612. else {
  1613. f = currentSlide.querySelectorAll( '.fragment.visible' ).length - 1;
  1614. }
  1615. }
  1616. }
  1617. return { h, v, f };
  1618. }
  1619. /**
  1620. * Retrieves all slides in this presentation.
  1621. */
  1622. function getSlides() {
  1623. return Util.queryAll( dom.wrapper, SLIDES_SELECTOR + ':not(.stack):not([data-visibility="uncounted"])' );
  1624. }
  1625. /**
  1626. * Returns a list of all horizontal slides in the deck. Each
  1627. * vertical stack is included as one horizontal slide in the
  1628. * resulting array.
  1629. */
  1630. function getHorizontalSlides() {
  1631. return Util.queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR );
  1632. }
  1633. /**
  1634. * Returns all vertical slides that exist within this deck.
  1635. */
  1636. function getVerticalSlides() {
  1637. return Util.queryAll( dom.wrapper, '.slides>section>section' );
  1638. }
  1639. /**
  1640. * Returns all vertical stacks (each stack can contain multiple slides).
  1641. */
  1642. function getVerticalStacks() {
  1643. return Util.queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR + '.stack');
  1644. }
  1645. /**
  1646. * Returns true if there are at least two horizontal slides.
  1647. */
  1648. function hasHorizontalSlides() {
  1649. return getHorizontalSlides().length > 1;
  1650. }
  1651. /**
  1652. * Returns true if there are at least two vertical slides.
  1653. */
  1654. function hasVerticalSlides() {
  1655. return getVerticalSlides().length > 1;
  1656. }
  1657. /**
  1658. * Returns an array of objects where each object represents the
  1659. * attributes on its respective slide.
  1660. */
  1661. function getSlidesAttributes() {
  1662. return getSlides().map( slide => {
  1663. let attributes = {};
  1664. for( let i = 0; i < slide.attributes.length; i++ ) {
  1665. let attribute = slide.attributes[ i ];
  1666. attributes[ attribute.name ] = attribute.value;
  1667. }
  1668. return attributes;
  1669. } );
  1670. }
  1671. /**
  1672. * Retrieves the total number of slides in this presentation.
  1673. *
  1674. * @return {number}
  1675. */
  1676. function getTotalSlides() {
  1677. return getSlides().length;
  1678. }
  1679. /**
  1680. * Returns the slide element matching the specified index.
  1681. *
  1682. * @return {HTMLElement}
  1683. */
  1684. function getSlide( x, y ) {
  1685. let horizontalSlide = getHorizontalSlides()[ x ];
  1686. let verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
  1687. if( verticalSlides && verticalSlides.length && typeof y === 'number' ) {
  1688. return verticalSlides ? verticalSlides[ y ] : undefined;
  1689. }
  1690. return horizontalSlide;
  1691. }
  1692. /**
  1693. * Returns the background element for the given slide.
  1694. * All slides, even the ones with no background properties
  1695. * defined, have a background element so as long as the
  1696. * index is valid an element will be returned.
  1697. *
  1698. * @param {mixed} x Horizontal background index OR a slide
  1699. * HTML element
  1700. * @param {number} y Vertical background index
  1701. * @return {(HTMLElement[]|*)}
  1702. */
  1703. function getSlideBackground( x, y ) {
  1704. let slide = typeof x === 'number' ? getSlide( x, y ) : x;
  1705. if( slide ) {
  1706. return slide.slideBackgroundElement;
  1707. }
  1708. return undefined;
  1709. }
  1710. /**
  1711. * Retrieves the current state of the presentation as
  1712. * an object. This state can then be restored at any
  1713. * time.
  1714. *
  1715. * @return {{indexh: number, indexv: number, indexf: number, paused: boolean, overview: boolean}}
  1716. */
  1717. function getState() {
  1718. let indices = getIndices();
  1719. return {
  1720. indexh: indices.h,
  1721. indexv: indices.v,
  1722. indexf: indices.f,
  1723. paused: isPaused(),
  1724. overview: overview.isActive(),
  1725. ...overlay.getState()
  1726. };
  1727. }
  1728. /**
  1729. * Restores the presentation to the given state.
  1730. *
  1731. * @param {object} state As generated by getState()
  1732. * @see {@link getState} generates the parameter `state`
  1733. */
  1734. function setState( state ) {
  1735. if( typeof state === 'object' ) {
  1736. slide( Util.deserialize( state.indexh ), Util.deserialize( state.indexv ), Util.deserialize( state.indexf ) );
  1737. let pausedFlag = Util.deserialize( state.paused ),
  1738. overviewFlag = Util.deserialize( state.overview );
  1739. if( typeof pausedFlag === 'boolean' && pausedFlag !== isPaused() ) {
  1740. togglePause( pausedFlag );
  1741. }
  1742. if( typeof overviewFlag === 'boolean' && overviewFlag !== overview.isActive() ) {
  1743. overview.toggle( overviewFlag );
  1744. }
  1745. overlay.setState( state );
  1746. }
  1747. }
  1748. /**
  1749. * Cues a new automated slide if enabled in the config.
  1750. */
  1751. function cueAutoSlide() {
  1752. cancelAutoSlide();
  1753. if( currentSlide && config.autoSlide !== false ) {
  1754. let fragment = currentSlide.querySelector( '.current-fragment[data-autoslide]' );
  1755. let fragmentAutoSlide = fragment ? fragment.getAttribute( 'data-autoslide' ) : null;
  1756. let parentAutoSlide = currentSlide.parentNode ? currentSlide.parentNode.getAttribute( 'data-autoslide' ) : null;
  1757. let slideAutoSlide = currentSlide.getAttribute( 'data-autoslide' );
  1758. // Pick value in the following priority order:
  1759. // 1. Current fragment's data-autoslide
  1760. // 2. Current slide's data-autoslide
  1761. // 3. Parent slide's data-autoslide
  1762. // 4. Global autoSlide setting
  1763. if( fragmentAutoSlide ) {
  1764. autoSlide = parseInt( fragmentAutoSlide, 10 );
  1765. }
  1766. else if( slideAutoSlide ) {
  1767. autoSlide = parseInt( slideAutoSlide, 10 );
  1768. }
  1769. else if( parentAutoSlide ) {
  1770. autoSlide = parseInt( parentAutoSlide, 10 );
  1771. }
  1772. else {
  1773. autoSlide = config.autoSlide;
  1774. // If there are media elements with data-autoplay,
  1775. // automatically set the autoSlide duration to the
  1776. // length of that media. Not applicable if the slide
  1777. // is divided up into fragments.
  1778. // playbackRate is accounted for in the duration.
  1779. if( currentSlide.querySelectorAll( '.fragment' ).length === 0 ) {
  1780. Util.queryAll( currentSlide, 'video, audio' ).forEach( el => {
  1781. if( el.hasAttribute( 'data-autoplay' ) ) {
  1782. if( autoSlide && (el.duration * 1000 / el.playbackRate ) > autoSlide ) {
  1783. autoSlide = ( el.duration * 1000 / el.playbackRate ) + 1000;
  1784. }
  1785. }
  1786. } );
  1787. }
  1788. }
  1789. // Cue the next auto-slide if:
  1790. // - There is an autoSlide value
  1791. // - Auto-sliding isn't paused by the user
  1792. // - The presentation isn't paused
  1793. // - The overview isn't active
  1794. // - The presentation isn't over
  1795. if( autoSlide && !autoSlidePaused && !isPaused() && !overview.isActive() && ( !isLastSlide() || fragments.availableRoutes().next || config.loop === true ) ) {
  1796. autoSlideTimeout = setTimeout( () => {
  1797. if( typeof config.autoSlideMethod === 'function' ) {
  1798. config.autoSlideMethod()
  1799. }
  1800. else {
  1801. navigateNext();
  1802. }
  1803. cueAutoSlide();
  1804. }, autoSlide );
  1805. autoSlideStartTime = Date.now();
  1806. }
  1807. if( autoSlidePlayer ) {
  1808. autoSlidePlayer.setPlaying( autoSlideTimeout !== -1 );
  1809. }
  1810. }
  1811. }
  1812. /**
  1813. * Cancels any ongoing request to auto-slide.
  1814. */
  1815. function cancelAutoSlide() {
  1816. clearTimeout( autoSlideTimeout );
  1817. autoSlideTimeout = -1;
  1818. }
  1819. function pauseAutoSlide() {
  1820. if( autoSlide && !autoSlidePaused ) {
  1821. autoSlidePaused = true;
  1822. dispatchEvent({ type: 'autoslidepaused' });
  1823. clearTimeout( autoSlideTimeout );
  1824. if( autoSlidePlayer ) {
  1825. autoSlidePlayer.setPlaying( false );
  1826. }
  1827. }
  1828. }
  1829. function resumeAutoSlide() {
  1830. if( autoSlide && autoSlidePaused ) {
  1831. autoSlidePaused = false;
  1832. dispatchEvent({ type: 'autoslideresumed' });
  1833. cueAutoSlide();
  1834. }
  1835. }
  1836. function navigateLeft({skipFragments=false}={}) {
  1837. navigationHistory.hasNavigatedHorizontally = true;
  1838. // Scroll view navigation is handled independently
  1839. if( scrollView.isActive() ) return scrollView.prev();
  1840. // Reverse for RTL
  1841. if( config.rtl ) {
  1842. if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().left ) {
  1843. slide( indexh + 1, config.navigationMode === 'grid' ? indexv : undefined );
  1844. }
  1845. }
  1846. // Normal navigation
  1847. else if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().left ) {
  1848. slide( indexh - 1, config.navigationMode === 'grid' ? indexv : undefined );
  1849. }
  1850. }
  1851. function navigateRight({skipFragments=false}={}) {
  1852. navigationHistory.hasNavigatedHorizontally = true;
  1853. // Scroll view navigation is handled independently
  1854. if( scrollView.isActive() ) return scrollView.next();
  1855. // Reverse for RTL
  1856. if( config.rtl ) {
  1857. if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().right ) {
  1858. slide( indexh - 1, config.navigationMode === 'grid' ? indexv : undefined );
  1859. }
  1860. }
  1861. // Normal navigation
  1862. else if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().right ) {
  1863. slide( indexh + 1, config.navigationMode === 'grid' ? indexv : undefined );
  1864. }
  1865. }
  1866. function navigateUp({skipFragments=false}={}) {
  1867. // Scroll view navigation is handled independently
  1868. if( scrollView.isActive() ) return scrollView.prev();
  1869. // Prioritize hiding fragments
  1870. if( ( overview.isActive() || skipFragments || fragments.prev() === false ) && availableRoutes().up ) {
  1871. slide( indexh, indexv - 1 );
  1872. }
  1873. }
  1874. function navigateDown({skipFragments=false}={}) {
  1875. navigationHistory.hasNavigatedVertically = true;
  1876. // Scroll view navigation is handled independently
  1877. if( scrollView.isActive() ) return scrollView.next();
  1878. // Prioritize revealing fragments
  1879. if( ( overview.isActive() || skipFragments || fragments.next() === false ) && availableRoutes().down ) {
  1880. slide( indexh, indexv + 1 );
  1881. }
  1882. }
  1883. /**
  1884. * Navigates backwards, prioritized in the following order:
  1885. * 1) Previous fragment
  1886. * 2) Previous vertical slide
  1887. * 3) Previous horizontal slide
  1888. */
  1889. function navigatePrev({skipFragments=false}={}) {
  1890. // Scroll view navigation is handled independently
  1891. if( scrollView.isActive() ) return scrollView.prev();
  1892. // Prioritize revealing fragments
  1893. if( skipFragments || fragments.prev() === false ) {
  1894. if( availableRoutes().up ) {
  1895. navigateUp({skipFragments});
  1896. }
  1897. else {
  1898. // Fetch the previous horizontal slide, if there is one
  1899. let previousSlide;
  1900. if( config.rtl ) {
  1901. previousSlide = Util.queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR + '.future' ).pop();
  1902. }
  1903. else {
  1904. previousSlide = Util.queryAll( dom.wrapper, HORIZONTAL_SLIDES_SELECTOR + '.past' ).pop();
  1905. }
  1906. // When going backwards and arriving on a stack we start
  1907. // at the bottom of the stack
  1908. if( previousSlide && previousSlide.classList.contains( 'stack' ) ) {
  1909. let v = ( previousSlide.querySelectorAll( 'section' ).length - 1 ) || undefined;
  1910. let h = indexh - 1;
  1911. slide( h, v );
  1912. }
  1913. else if( config.rtl ) {
  1914. navigateRight({skipFragments});
  1915. }
  1916. else {
  1917. navigateLeft({skipFragments});
  1918. }
  1919. }
  1920. }
  1921. }
  1922. /**
  1923. * The reverse of #navigatePrev().
  1924. */
  1925. function navigateNext({skipFragments=false}={}) {
  1926. navigationHistory.hasNavigatedHorizontally = true;
  1927. navigationHistory.hasNavigatedVertically = true;
  1928. // Scroll view navigation is handled independently
  1929. if( scrollView.isActive() ) return scrollView.next();
  1930. // Prioritize revealing fragments
  1931. if( skipFragments || fragments.next() === false ) {
  1932. let routes = availableRoutes();
  1933. // When looping is enabled `routes.down` is always available
  1934. // so we need a separate check for when we've reached the
  1935. // end of a stack and should move horizontally
  1936. if( routes.down && routes.right && config.loop && isLastVerticalSlide() ) {
  1937. routes.down = false;
  1938. }
  1939. if( routes.down ) {
  1940. navigateDown({skipFragments});
  1941. }
  1942. else if( config.rtl ) {
  1943. navigateLeft({skipFragments});
  1944. }
  1945. else {
  1946. navigateRight({skipFragments});
  1947. }
  1948. }
  1949. }
  1950. // --------------------------------------------------------------------//
  1951. // ----------------------------- EVENTS -------------------------------//
  1952. // --------------------------------------------------------------------//
  1953. /**
  1954. * Called by all event handlers that are based on user
  1955. * input.
  1956. *
  1957. * @param {object} [event]
  1958. */
  1959. function onUserInput( event ) {
  1960. if( config.autoSlideStoppable ) {
  1961. pauseAutoSlide();
  1962. }
  1963. }
  1964. /**
  1965. * Listener for post message events posted to this window.
  1966. */
  1967. function onPostMessage( event ) {
  1968. let data = event.data;
  1969. // Make sure we're dealing with JSON
  1970. if( typeof data === 'string' && data.charAt( 0 ) === '{' && data.charAt( data.length - 1 ) === '}' ) {
  1971. data = JSON.parse( data );
  1972. // Check if the requested method can be found
  1973. if( data.method && typeof Reveal[data.method] === 'function' ) {
  1974. if( POST_MESSAGE_METHOD_BLACKLIST.test( data.method ) === false ) {
  1975. const result = Reveal[data.method].apply( Reveal, data.args );
  1976. // Dispatch a postMessage event with the returned value from
  1977. // our method invocation for getter functions
  1978. dispatchPostMessage( 'callback', { method: data.method, result: result } );
  1979. }
  1980. else {
  1981. console.warn( 'reveal.js: "'+ data.method +'" is is blacklisted from the postMessage API' );
  1982. }
  1983. }
  1984. }
  1985. }
  1986. /**
  1987. * Event listener for transition end on the current slide.
  1988. *
  1989. * @param {object} [event]
  1990. */
  1991. function onTransitionEnd( event ) {
  1992. if( transition === 'running' && /section/gi.test( event.target.nodeName ) ) {
  1993. transition = 'idle';
  1994. dispatchEvent({
  1995. type: 'slidetransitionend',
  1996. data: { indexh, indexv, previousSlide, currentSlide }
  1997. });
  1998. }
  1999. }
  2000. /**
  2001. * A global listener for all click events inside of the
  2002. * .slides container.
  2003. *
  2004. * @param {object} [event]
  2005. */
  2006. function onSlidesClicked( event ) {
  2007. const anchor = Util.closest( event.target, 'a[href^="#"]' );
  2008. // If a hash link is clicked, we find the target slide
  2009. // and navigate to it. We previously relied on 'hashchange'
  2010. // for links like these but that prevented media with
  2011. // audio tracks from playing in mobile browsers since it
  2012. // wasn't considered a direct interaction with the document.
  2013. if( anchor ) {
  2014. const hash = anchor.getAttribute( 'href' );
  2015. const indices = location.getIndicesFromHash( hash );
  2016. if( indices ) {
  2017. Reveal.slide( indices.h, indices.v, indices.f );
  2018. event.preventDefault();
  2019. }
  2020. }
  2021. }
  2022. /**
  2023. * Handler for the window level 'resize' event.
  2024. *
  2025. * @param {object} [event]
  2026. */
  2027. function onWindowResize( event ) {
  2028. layout();
  2029. }
  2030. /**
  2031. * Handle for the window level 'visibilitychange' event.
  2032. *
  2033. * @param {object} [event]
  2034. */
  2035. function onPageVisibilityChange( event ) {
  2036. // If, after clicking a link or similar and we're coming back,
  2037. // focus the document.body to ensure we can use keyboard shortcuts
  2038. if( document.hidden === false && document.activeElement !== document.body ) {
  2039. // Not all elements support .blur() - SVGs among them.
  2040. if( typeof document.activeElement.blur === 'function' ) {
  2041. document.activeElement.blur();
  2042. }
  2043. document.body.focus();
  2044. }
  2045. }
  2046. /**
  2047. * Handler for the document level 'fullscreenchange' event.
  2048. *
  2049. * @param {object} [event]
  2050. */
  2051. function onFullscreenChange( event ) {
  2052. let element = document.fullscreenElement || document.webkitFullscreenElement;
  2053. if( element === dom.wrapper ) {
  2054. event.stopImmediatePropagation();
  2055. // Timeout to avoid layout shift in Safari
  2056. setTimeout( () => {
  2057. Reveal.layout();
  2058. Reveal.focus.focus(); // focus.focus :'(
  2059. }, 1 );
  2060. }
  2061. }
  2062. /**
  2063. * Handles click on the auto-sliding controls element.
  2064. *
  2065. * @param {object} [event]
  2066. */
  2067. function onAutoSlidePlayerClick( event ) {
  2068. // Replay
  2069. if( isLastSlide() && config.loop === false ) {
  2070. slide( 0, 0 );
  2071. resumeAutoSlide();
  2072. }
  2073. // Resume
  2074. else if( autoSlidePaused ) {
  2075. resumeAutoSlide();
  2076. }
  2077. // Pause
  2078. else {
  2079. pauseAutoSlide();
  2080. }
  2081. }
  2082. // --------------------------------------------------------------------//
  2083. // ------------------------------- API --------------------------------//
  2084. // --------------------------------------------------------------------//
  2085. // The public reveal.js API
  2086. const API = {
  2087. VERSION,
  2088. initialize,
  2089. configure,
  2090. destroy,
  2091. sync,
  2092. syncSlide,
  2093. syncFragments: fragments.sync.bind( fragments ),
  2094. // Navigation methods
  2095. slide,
  2096. left: navigateLeft,
  2097. right: navigateRight,
  2098. up: navigateUp,
  2099. down: navigateDown,
  2100. prev: navigatePrev,
  2101. next: navigateNext,
  2102. // Navigation aliases
  2103. navigateLeft, navigateRight, navigateUp, navigateDown, navigatePrev, navigateNext,
  2104. // Fragment methods
  2105. navigateFragment: fragments.goto.bind( fragments ),
  2106. prevFragment: fragments.prev.bind( fragments ),
  2107. nextFragment: fragments.next.bind( fragments ),
  2108. // Event binding
  2109. on,
  2110. off,
  2111. // Legacy event binding methods left in for backwards compatibility
  2112. addEventListener: on,
  2113. removeEventListener: off,
  2114. // Forces an update in slide layout
  2115. layout,
  2116. // Randomizes the order of slides
  2117. shuffle,
  2118. // Returns an object with the available routes as booleans (left/right/top/bottom)
  2119. availableRoutes,
  2120. // Returns an object with the available fragments as booleans (prev/next)
  2121. availableFragments: fragments.availableRoutes.bind( fragments ),
  2122. // Toggles a help overlay with keyboard shortcuts
  2123. toggleHelp: overlay.toggleHelp.bind( overlay ),
  2124. // Toggles the overview mode on/off
  2125. toggleOverview: overview.toggle.bind( overview ),
  2126. // Toggles the scroll view on/off
  2127. toggleScrollView: scrollView.toggle.bind( scrollView ),
  2128. // Toggles the "black screen" mode on/off
  2129. togglePause,
  2130. // Toggles the auto slide mode on/off
  2131. toggleAutoSlide,
  2132. // Toggles visibility of the jump-to-slide UI
  2133. toggleJumpToSlide,
  2134. // Slide navigation checks
  2135. isFirstSlide,
  2136. isLastSlide,
  2137. isLastVerticalSlide,
  2138. isVerticalSlide,
  2139. isVerticalStack,
  2140. // State checks
  2141. isPaused,
  2142. isAutoSliding,
  2143. isSpeakerNotes: notes.isSpeakerNotesWindow.bind( notes ),
  2144. isOverview: overview.isActive.bind( overview ),
  2145. isFocused: focus.isFocused.bind( focus ),
  2146. isOverlayOpen: overlay.isOpen.bind( overlay ),
  2147. isScrollView: scrollView.isActive.bind( scrollView ),
  2148. isPrintView: printView.isActive.bind( printView ),
  2149. // Checks if reveal.js has been loaded and is ready for use
  2150. isReady: () => ready,
  2151. // Slide preloading
  2152. loadSlide: slideContent.load.bind( slideContent ),
  2153. unloadSlide: slideContent.unload.bind( slideContent ),
  2154. // Start/stop all media inside of the current slide
  2155. startEmbeddedContent: () => slideContent.startEmbeddedContent( currentSlide ),
  2156. stopEmbeddedContent: () => slideContent.stopEmbeddedContent( currentSlide, { unloadIframes: false } ),
  2157. // Preview management
  2158. showIframePreview: overlay.showIframePreview.bind( overlay ),
  2159. showMediaPreview: overlay.showMediaPreview.bind( overlay ),
  2160. showPreview: overlay.showIframePreview.bind( overlay ), // deprecated in favor of showIframePreview
  2161. hidePreview: overlay.close.bind( overlay ),
  2162. // Adds or removes all internal event listeners
  2163. addEventListeners,
  2164. removeEventListeners,
  2165. dispatchEvent,
  2166. // Facility for persisting and restoring the presentation state
  2167. getState,
  2168. setState,
  2169. // Presentation progress on range of 0-1
  2170. getProgress,
  2171. // Returns the indices of the current, or specified, slide
  2172. getIndices,
  2173. // Returns an Array of key:value maps of the attributes of each
  2174. // slide in the deck
  2175. getSlidesAttributes,
  2176. // Returns the number of slides that we have passed
  2177. getSlidePastCount,
  2178. // Returns the total number of slides
  2179. getTotalSlides,
  2180. // Returns the slide element at the specified index
  2181. getSlide,
  2182. // Returns the previous slide element, may be null
  2183. getPreviousSlide: () => previousSlide,
  2184. // Returns the current slide element
  2185. getCurrentSlide: () => currentSlide,
  2186. // Returns the slide background element at the specified index
  2187. getSlideBackground,
  2188. // Returns the speaker notes string for a slide, or null
  2189. getSlideNotes: notes.getSlideNotes.bind( notes ),
  2190. // Returns an Array of all slides
  2191. getSlides,
  2192. // Returns an array with all horizontal/vertical slides in the deck
  2193. getHorizontalSlides,
  2194. getVerticalSlides,
  2195. // Checks if the presentation contains two or more horizontal
  2196. // and vertical slides
  2197. hasHorizontalSlides,
  2198. hasVerticalSlides,
  2199. // Checks if the deck has navigated on either axis at least once
  2200. hasNavigatedHorizontally: () => navigationHistory.hasNavigatedHorizontally,
  2201. hasNavigatedVertically: () => navigationHistory.hasNavigatedVertically,
  2202. shouldAutoAnimateBetween,
  2203. // Adds/removes a custom key binding
  2204. addKeyBinding: keyboard.addKeyBinding.bind( keyboard ),
  2205. removeKeyBinding: keyboard.removeKeyBinding.bind( keyboard ),
  2206. // Programmatically triggers a keyboard event
  2207. triggerKey: keyboard.triggerKey.bind( keyboard ),
  2208. // Registers a new shortcut to include in the help overlay
  2209. registerKeyboardShortcut: keyboard.registerKeyboardShortcut.bind( keyboard ),
  2210. getComputedSlideSize,
  2211. setCurrentScrollPage,
  2212. // Returns the current scale of the presentation content
  2213. getScale: () => scale,
  2214. // Returns the current configuration object
  2215. getConfig: () => config,
  2216. // Helper method, retrieves query string as a key:value map
  2217. getQueryHash: Util.getQueryHash,
  2218. // Returns the path to the current slide as represented in the URL
  2219. getSlidePath: location.getHash.bind( location ),
  2220. // Returns reveal.js DOM elements
  2221. getRevealElement: () => revealElement,
  2222. getSlidesElement: () => dom.slides,
  2223. getViewportElement: () => dom.viewport,
  2224. getBackgroundsElement: () => backgrounds.element,
  2225. // API for registering and retrieving plugins
  2226. registerPlugin: plugins.registerPlugin.bind( plugins ),
  2227. hasPlugin: plugins.hasPlugin.bind( plugins ),
  2228. getPlugin: plugins.getPlugin.bind( plugins ),
  2229. getPlugins: plugins.getRegisteredPlugins.bind( plugins )
  2230. };
  2231. // Our internal API which controllers have access to
  2232. Util.extend( Reveal, {
  2233. ...API,
  2234. // Methods for announcing content to screen readers
  2235. announceStatus,
  2236. getStatusText,
  2237. // Controllers
  2238. focus,
  2239. scroll: scrollView,
  2240. progress,
  2241. controls,
  2242. location,
  2243. overview,
  2244. keyboard,
  2245. fragments,
  2246. backgrounds,
  2247. slideContent,
  2248. slideNumber,
  2249. onUserInput,
  2250. closeOverlay: overlay.close.bind( overlay ),
  2251. updateSlidesVisibility,
  2252. layoutSlideContents,
  2253. transformSlides,
  2254. cueAutoSlide,
  2255. cancelAutoSlide
  2256. } );
  2257. return API;
  2258. };