reveal.js 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902
  1. /*!
  2. * reveal.js
  3. * http://lab.hakim.se/reveal-js
  4. * MIT licensed
  5. *
  6. * Copyright (C) 2013 Hakim El Hattab, http://hakim.se
  7. */
  8. var Reveal = (function(){
  9. 'use strict';
  10. var SLIDES_SELECTOR = '.reveal .slides section',
  11. HORIZONTAL_SLIDES_SELECTOR = '.reveal .slides>section',
  12. VERTICAL_SLIDES_SELECTOR = '.reveal .slides>section.present>section',
  13. HOME_SLIDE_SELECTOR = '.reveal .slides>section:first-child',
  14. // Configurations defaults, can be overridden at initialization time
  15. config = {
  16. // The "normal" size of the presentation, aspect ratio will be preserved
  17. // when the presentation is scaled to fit different resolutions
  18. width: 960,
  19. height: 700,
  20. // Factor of the display size that should remain empty around the content
  21. margin: 0.1,
  22. // Bounds for smallest/largest possible scale to apply to content
  23. minScale: 0.2,
  24. maxScale: 1.0,
  25. // Display controls in the bottom right corner
  26. controls: true,
  27. // Display a presentation progress bar
  28. progress: true,
  29. // Push each slide change to the browser history
  30. history: false,
  31. // Enable keyboard shortcuts for navigation
  32. keyboard: true,
  33. // Enable the slide overview mode
  34. overview: true,
  35. // Vertical centring of slides
  36. center: true,
  37. // Enables touch navigation on devices with touch input
  38. touch: true,
  39. // Loop the presentation
  40. loop: false,
  41. // Change the presentation direction to be RTL
  42. rtl: false,
  43. // Turns fragments on and off globally
  44. fragments: true,
  45. // Flags if the presentation is running in an embedded mode,
  46. // i.e. contained within a limited portion of the screen
  47. embedded: false,
  48. // Number of milliseconds between automatically proceeding to the
  49. // next slide, disabled when set to 0, this value can be overwritten
  50. // by using a data-autoslide attribute on your slides
  51. autoSlide: 0,
  52. // Stop auto-sliding after user input
  53. autoSlideStoppable: false,
  54. // Enable slide navigation via mouse wheel
  55. mouseWheel: false,
  56. // Apply a 3D roll to links on hover
  57. rollingLinks: false,
  58. // Hides the address bar on mobile devices
  59. hideAddressBar: true,
  60. // Opens links in an iframe preview overlay
  61. previewLinks: false,
  62. // Focuses body when page changes visiblity to ensure keyboard shortcuts work
  63. focusBodyOnPageVisiblityChange: true,
  64. // Theme (see /css/theme)
  65. theme: null,
  66. // Transition style
  67. transition: 'default', // default/cube/page/concave/zoom/linear/fade/none
  68. // Transition speed
  69. transitionSpeed: 'default', // default/fast/slow
  70. // Transition style for full page slide backgrounds
  71. backgroundTransition: 'default', // default/linear/none
  72. // Parallax background image
  73. parallaxBackgroundImage: '', // CSS syntax, e.g. "a.jpg"
  74. // Parallax background size
  75. parallaxBackgroundSize: '', // CSS syntax, e.g. "3000px 2000px"
  76. // Number of slides away from the current that are visible
  77. viewDistance: 3,
  78. // Script dependencies to load
  79. dependencies: []
  80. },
  81. // Flags if reveal.js is loaded (has dispatched the 'ready' event)
  82. loaded = false,
  83. // The current auto-slide duration
  84. autoSlide = 0,
  85. // The horizontal and vertical index of the currently active slide
  86. indexh,
  87. indexv,
  88. // The previous and current slide HTML elements
  89. previousSlide,
  90. currentSlide,
  91. // Slides may hold a data-state attribute which we pick up and apply
  92. // as a class to the body. This list contains the combined state of
  93. // all current slides.
  94. state = [],
  95. // The current scale of the presentation (see width/height config)
  96. scale = 1,
  97. // Cached references to DOM elements
  98. dom = {},
  99. // Client support for CSS 3D transforms, see #checkCapabilities()
  100. supports3DTransforms,
  101. // Client support for CSS 2D transforms, see #checkCapabilities()
  102. supports2DTransforms,
  103. // Client is a mobile device, see #checkCapabilities()
  104. isMobileDevice,
  105. // Throttles mouse wheel navigation
  106. lastMouseWheelStep = 0,
  107. // An interval used to automatically move on to the next slide
  108. autoSlideTimeout = 0,
  109. // Delays updates to the URL due to a Chrome thumbnailer bug
  110. writeURLTimeout = 0,
  111. // A delay used to activate the overview mode
  112. activateOverviewTimeout = 0,
  113. // A delay used to deactivate the overview mode
  114. deactivateOverviewTimeout = 0,
  115. // Flags if the interaction event listeners are bound
  116. eventsAreBound = false,
  117. // Holds information about the currently ongoing touch input
  118. touch = {
  119. startX: 0,
  120. startY: 0,
  121. startSpan: 0,
  122. startCount: 0,
  123. captured: false,
  124. threshold: 40
  125. };
  126. /**
  127. * Starts up the presentation if the client is capable.
  128. */
  129. function initialize( options ) {
  130. checkCapabilities();
  131. if( !supports2DTransforms && !supports3DTransforms ) {
  132. document.body.setAttribute( 'class', 'no-transforms' );
  133. // If the browser doesn't support core features we won't be
  134. // using JavaScript to control the presentation
  135. return;
  136. }
  137. // Force a layout when the whole page, incl fonts, has loaded
  138. window.addEventListener( 'load', layout, false );
  139. // Copy options over to our config object
  140. extend( config, options );
  141. // Hide the address bar in mobile browsers
  142. hideAddressBar();
  143. // Loads the dependencies and continues to #start() once done
  144. load();
  145. }
  146. /**
  147. * Inspect the client to see what it's capable of, this
  148. * should only happens once per runtime.
  149. */
  150. function checkCapabilities() {
  151. supports3DTransforms = 'WebkitPerspective' in document.body.style ||
  152. 'MozPerspective' in document.body.style ||
  153. 'msPerspective' in document.body.style ||
  154. 'OPerspective' in document.body.style ||
  155. 'perspective' in document.body.style;
  156. supports2DTransforms = 'WebkitTransform' in document.body.style ||
  157. 'MozTransform' in document.body.style ||
  158. 'msTransform' in document.body.style ||
  159. 'OTransform' in document.body.style ||
  160. 'transform' in document.body.style;
  161. isMobileDevice = navigator.userAgent.match( /(iphone|ipod|android)/gi );
  162. }
  163. /**
  164. * Loads the dependencies of reveal.js. Dependencies are
  165. * defined via the configuration option 'dependencies'
  166. * and will be loaded prior to starting/binding reveal.js.
  167. * Some dependencies may have an 'async' flag, if so they
  168. * will load after reveal.js has been started up.
  169. */
  170. function load() {
  171. var scripts = [],
  172. scriptsAsync = [];
  173. for( var i = 0, len = config.dependencies.length; i < len; i++ ) {
  174. var s = config.dependencies[i];
  175. // Load if there's no condition or the condition is truthy
  176. if( !s.condition || s.condition() ) {
  177. if( s.async ) {
  178. scriptsAsync.push( s.src );
  179. }
  180. else {
  181. scripts.push( s.src );
  182. }
  183. // Extension may contain callback functions
  184. if( typeof s.callback === 'function' ) {
  185. head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], s.callback );
  186. }
  187. }
  188. }
  189. // Called once synchronous scripts finish loading
  190. function proceed() {
  191. if( scriptsAsync.length ) {
  192. // Load asynchronous scripts
  193. head.js.apply( null, scriptsAsync );
  194. }
  195. start();
  196. }
  197. if( scripts.length ) {
  198. head.ready( proceed );
  199. // Load synchronous scripts
  200. head.js.apply( null, scripts );
  201. }
  202. else {
  203. proceed();
  204. }
  205. }
  206. /**
  207. * Starts up reveal.js by binding input events and navigating
  208. * to the current URL deeplink if there is one.
  209. */
  210. function start() {
  211. // Make sure we've got all the DOM elements we need
  212. setupDOM();
  213. // Decorate the slide DOM elements with state classes (past/future)
  214. setupSlides();
  215. // Updates the presentation to match the current configuration values
  216. configure();
  217. // Read the initial hash
  218. readURL();
  219. // Notify listeners that the presentation is ready but use a 1ms
  220. // timeout to ensure it's not fired synchronously after #initialize()
  221. setTimeout( function() {
  222. // Enable transitions now that we're loaded
  223. dom.slides.classList.remove( 'no-transition' );
  224. loaded = true;
  225. dispatchEvent( 'ready', {
  226. 'indexh': indexh,
  227. 'indexv': indexv,
  228. 'currentSlide': currentSlide
  229. } );
  230. }, 1 );
  231. }
  232. /**
  233. * Iterates through and decorates slides DOM elements with
  234. * appropriate classes.
  235. */
  236. function setupSlides() {
  237. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  238. horizontalSlides.forEach( function( horizontalSlide ) {
  239. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  240. verticalSlides.forEach( function( verticalSlide, y ) {
  241. if( y > 0 ) verticalSlide.classList.add( 'future' );
  242. } );
  243. } );
  244. }
  245. /**
  246. * Finds and stores references to DOM elements which are
  247. * required by the presentation. If a required element is
  248. * not found, it is created.
  249. */
  250. function setupDOM() {
  251. // Cache references to key DOM elements
  252. dom.theme = document.querySelector( '#theme' );
  253. dom.wrapper = document.querySelector( '.reveal' );
  254. dom.slides = document.querySelector( '.reveal .slides' );
  255. // Prevent transitions while we're loading
  256. dom.slides.classList.add( 'no-transition' );
  257. // Background element
  258. dom.background = createSingletonNode( dom.wrapper, 'div', 'backgrounds', null );
  259. // Progress bar
  260. dom.progress = createSingletonNode( dom.wrapper, 'div', 'progress', '<span></span>' );
  261. dom.progressbar = dom.progress.querySelector( 'span' );
  262. // Arrow controls
  263. createSingletonNode( dom.wrapper, 'aside', 'controls',
  264. '<div class="navigate-left"></div>' +
  265. '<div class="navigate-right"></div>' +
  266. '<div class="navigate-up"></div>' +
  267. '<div class="navigate-down"></div>' );
  268. // State background element [DEPRECATED]
  269. createSingletonNode( dom.wrapper, 'div', 'state-background', null );
  270. // Overlay graphic which is displayed during the paused mode
  271. createSingletonNode( dom.wrapper, 'div', 'pause-overlay', null );
  272. // Cache references to elements
  273. dom.controls = document.querySelector( '.reveal .controls' );
  274. // There can be multiple instances of controls throughout the page
  275. dom.controlsLeft = toArray( document.querySelectorAll( '.navigate-left' ) );
  276. dom.controlsRight = toArray( document.querySelectorAll( '.navigate-right' ) );
  277. dom.controlsUp = toArray( document.querySelectorAll( '.navigate-up' ) );
  278. dom.controlsDown = toArray( document.querySelectorAll( '.navigate-down' ) );
  279. dom.controlsPrev = toArray( document.querySelectorAll( '.navigate-prev' ) );
  280. dom.controlsNext = toArray( document.querySelectorAll( '.navigate-next' ) );
  281. }
  282. /**
  283. * Creates an HTML element and returns a reference to it.
  284. * If the element already exists the existing instance will
  285. * be returned.
  286. */
  287. function createSingletonNode( container, tagname, classname, innerHTML ) {
  288. var node = container.querySelector( '.' + classname );
  289. if( !node ) {
  290. node = document.createElement( tagname );
  291. node.classList.add( classname );
  292. if( innerHTML !== null ) {
  293. node.innerHTML = innerHTML;
  294. }
  295. container.appendChild( node );
  296. }
  297. return node;
  298. }
  299. /**
  300. * Creates the slide background elements and appends them
  301. * to the background container. One element is created per
  302. * slide no matter if the given slide has visible background.
  303. */
  304. function createBackgrounds() {
  305. if( isPrintingPDF() ) {
  306. document.body.classList.add( 'print-pdf' );
  307. }
  308. // Clear prior backgrounds
  309. dom.background.innerHTML = '';
  310. dom.background.classList.add( 'no-transition' );
  311. // Helper method for creating a background element for the
  312. // given slide
  313. function _createBackground( slide, container ) {
  314. var data = {
  315. background: slide.getAttribute( 'data-background' ),
  316. backgroundSize: slide.getAttribute( 'data-background-size' ),
  317. backgroundImage: slide.getAttribute( 'data-background-image' ),
  318. backgroundColor: slide.getAttribute( 'data-background-color' ),
  319. backgroundRepeat: slide.getAttribute( 'data-background-repeat' ),
  320. backgroundPosition: slide.getAttribute( 'data-background-position' ),
  321. backgroundTransition: slide.getAttribute( 'data-background-transition' )
  322. };
  323. var element = document.createElement( 'div' );
  324. element.className = 'slide-background';
  325. if( data.background ) {
  326. // Auto-wrap image urls in url(...)
  327. if( /^(http|file|\/\/)/gi.test( data.background ) || /\.(png|jpg|jpeg|gif|bmp)$/gi.test( data.background ) ) {
  328. element.style.backgroundImage = 'url('+ data.background +')';
  329. }
  330. else {
  331. element.style.background = data.background;
  332. }
  333. }
  334. // Additional and optional background properties
  335. if( data.backgroundSize ) element.style.backgroundSize = data.backgroundSize;
  336. if( data.backgroundImage ) element.style.backgroundImage = 'url("' + data.backgroundImage + '")';
  337. if( data.backgroundColor ) element.style.backgroundColor = data.backgroundColor;
  338. if( data.backgroundRepeat ) element.style.backgroundRepeat = data.backgroundRepeat;
  339. if( data.backgroundPosition ) element.style.backgroundPosition = data.backgroundPosition;
  340. if( data.backgroundTransition ) element.setAttribute( 'data-background-transition', data.backgroundTransition );
  341. container.appendChild( element );
  342. return element;
  343. }
  344. // Iterate over all horizontal slides
  345. toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).forEach( function( slideh ) {
  346. var backgroundStack;
  347. if( isPrintingPDF() ) {
  348. backgroundStack = _createBackground( slideh, slideh );
  349. }
  350. else {
  351. backgroundStack = _createBackground( slideh, dom.background );
  352. }
  353. // Iterate over all vertical slides
  354. toArray( slideh.querySelectorAll( 'section' ) ).forEach( function( slidev ) {
  355. if( isPrintingPDF() ) {
  356. _createBackground( slidev, slidev );
  357. }
  358. else {
  359. _createBackground( slidev, backgroundStack );
  360. }
  361. } );
  362. } );
  363. // Add parallax background if specified
  364. if( config.parallaxBackgroundImage ) {
  365. dom.background.style.backgroundImage = 'url("' + config.parallaxBackgroundImage + '")';
  366. dom.background.style.backgroundSize = config.parallaxBackgroundSize;
  367. // Make sure the below properties are set on the element - these properties are
  368. // needed for proper transitions to be set on the element via CSS. To remove
  369. // annoying background slide-in effect when the presentation starts, apply
  370. // these properties after short time delay
  371. setTimeout( function() {
  372. dom.wrapper.classList.add( 'has-parallax-background' );
  373. }, 1 );
  374. }
  375. else {
  376. dom.background.style.backgroundImage = '';
  377. dom.wrapper.classList.remove( 'has-parallax-background' );
  378. }
  379. }
  380. /**
  381. * Applies the configuration settings from the config
  382. * object. May be called multiple times.
  383. */
  384. function configure( options ) {
  385. dom.wrapper.classList.remove( config.transition );
  386. // New config options may be passed when this method
  387. // is invoked through the API after initialization
  388. if( typeof options === 'object' ) extend( config, options );
  389. // Force linear transition based on browser capabilities
  390. if( supports3DTransforms === false ) config.transition = 'linear';
  391. dom.wrapper.classList.add( config.transition );
  392. dom.wrapper.setAttribute( 'data-transition-speed', config.transitionSpeed );
  393. dom.wrapper.setAttribute( 'data-background-transition', config.backgroundTransition );
  394. dom.controls.style.display = config.controls ? 'block' : 'none';
  395. dom.progress.style.display = config.progress ? 'block' : 'none';
  396. if( config.rtl ) {
  397. dom.wrapper.classList.add( 'rtl' );
  398. }
  399. else {
  400. dom.wrapper.classList.remove( 'rtl' );
  401. }
  402. if( config.center ) {
  403. dom.wrapper.classList.add( 'center' );
  404. }
  405. else {
  406. dom.wrapper.classList.remove( 'center' );
  407. }
  408. if( config.mouseWheel ) {
  409. document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  410. document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
  411. }
  412. else {
  413. document.removeEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
  414. document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
  415. }
  416. // Rolling 3D links
  417. if( config.rollingLinks ) {
  418. enableRollingLinks();
  419. }
  420. else {
  421. disableRollingLinks();
  422. }
  423. // Iframe link previews
  424. if( config.previewLinks ) {
  425. enablePreviewLinks();
  426. }
  427. else {
  428. disablePreviewLinks();
  429. enablePreviewLinks( '[data-preview-link]' );
  430. }
  431. // Load the theme in the config, if it's not already loaded
  432. if( config.theme && dom.theme ) {
  433. var themeURL = dom.theme.getAttribute( 'href' );
  434. var themeFinder = /[^\/]*?(?=\.css)/;
  435. var themeName = themeURL.match(themeFinder)[0];
  436. if( config.theme !== themeName ) {
  437. themeURL = themeURL.replace(themeFinder, config.theme);
  438. dom.theme.setAttribute( 'href', themeURL );
  439. }
  440. }
  441. sync();
  442. }
  443. /**
  444. * Binds all event listeners.
  445. */
  446. function addEventListeners() {
  447. eventsAreBound = true;
  448. window.addEventListener( 'hashchange', onWindowHashChange, false );
  449. window.addEventListener( 'resize', onWindowResize, false );
  450. if( config.touch ) {
  451. dom.wrapper.addEventListener( 'touchstart', onTouchStart, false );
  452. dom.wrapper.addEventListener( 'touchmove', onTouchMove, false );
  453. dom.wrapper.addEventListener( 'touchend', onTouchEnd, false );
  454. // Support pointer-style touch interaction as well
  455. if( window.navigator.msPointerEnabled ) {
  456. dom.wrapper.addEventListener( 'MSPointerDown', onPointerDown, false );
  457. dom.wrapper.addEventListener( 'MSPointerMove', onPointerMove, false );
  458. dom.wrapper.addEventListener( 'MSPointerUp', onPointerUp, false );
  459. }
  460. }
  461. if( config.keyboard ) {
  462. document.addEventListener( 'keydown', onDocumentKeyDown, false );
  463. }
  464. if( config.progress && dom.progress ) {
  465. dom.progress.addEventListener( 'click', onProgressClicked, false );
  466. }
  467. if( config.focusBodyOnPageVisiblityChange ) {
  468. var visibilityChange;
  469. if( 'hidden' in document ) {
  470. visibilityChange = 'visibilitychange';
  471. }
  472. else if( 'msHidden' in document ) {
  473. visibilityChange = 'msvisibilitychange';
  474. }
  475. else if( 'webkitHidden' in document ) {
  476. visibilityChange = 'webkitvisibilitychange';
  477. }
  478. if( visibilityChange ) {
  479. document.addEventListener( visibilityChange, onPageVisibilityChange, false );
  480. }
  481. }
  482. [ 'touchstart', 'click' ].forEach( function( eventName ) {
  483. dom.controlsLeft.forEach( function( el ) { el.addEventListener( eventName, onNavigateLeftClicked, false ); } );
  484. dom.controlsRight.forEach( function( el ) { el.addEventListener( eventName, onNavigateRightClicked, false ); } );
  485. dom.controlsUp.forEach( function( el ) { el.addEventListener( eventName, onNavigateUpClicked, false ); } );
  486. dom.controlsDown.forEach( function( el ) { el.addEventListener( eventName, onNavigateDownClicked, false ); } );
  487. dom.controlsPrev.forEach( function( el ) { el.addEventListener( eventName, onNavigatePrevClicked, false ); } );
  488. dom.controlsNext.forEach( function( el ) { el.addEventListener( eventName, onNavigateNextClicked, false ); } );
  489. } );
  490. }
  491. /**
  492. * Unbinds all event listeners.
  493. */
  494. function removeEventListeners() {
  495. eventsAreBound = false;
  496. document.removeEventListener( 'keydown', onDocumentKeyDown, false );
  497. window.removeEventListener( 'hashchange', onWindowHashChange, false );
  498. window.removeEventListener( 'resize', onWindowResize, false );
  499. dom.wrapper.removeEventListener( 'touchstart', onTouchStart, false );
  500. dom.wrapper.removeEventListener( 'touchmove', onTouchMove, false );
  501. dom.wrapper.removeEventListener( 'touchend', onTouchEnd, false );
  502. if( window.navigator.msPointerEnabled ) {
  503. dom.wrapper.removeEventListener( 'MSPointerDown', onPointerDown, false );
  504. dom.wrapper.removeEventListener( 'MSPointerMove', onPointerMove, false );
  505. dom.wrapper.removeEventListener( 'MSPointerUp', onPointerUp, false );
  506. }
  507. if ( config.progress && dom.progress ) {
  508. dom.progress.removeEventListener( 'click', onProgressClicked, false );
  509. }
  510. [ 'touchstart', 'click' ].forEach( function( eventName ) {
  511. dom.controlsLeft.forEach( function( el ) { el.removeEventListener( eventName, onNavigateLeftClicked, false ); } );
  512. dom.controlsRight.forEach( function( el ) { el.removeEventListener( eventName, onNavigateRightClicked, false ); } );
  513. dom.controlsUp.forEach( function( el ) { el.removeEventListener( eventName, onNavigateUpClicked, false ); } );
  514. dom.controlsDown.forEach( function( el ) { el.removeEventListener( eventName, onNavigateDownClicked, false ); } );
  515. dom.controlsPrev.forEach( function( el ) { el.removeEventListener( eventName, onNavigatePrevClicked, false ); } );
  516. dom.controlsNext.forEach( function( el ) { el.removeEventListener( eventName, onNavigateNextClicked, false ); } );
  517. } );
  518. }
  519. /**
  520. * Extend object a with the properties of object b.
  521. * If there's a conflict, object b takes precedence.
  522. */
  523. function extend( a, b ) {
  524. for( var i in b ) {
  525. a[ i ] = b[ i ];
  526. }
  527. }
  528. /**
  529. * Converts the target object to an array.
  530. */
  531. function toArray( o ) {
  532. return Array.prototype.slice.call( o );
  533. }
  534. /**
  535. * Measures the distance in pixels between point a
  536. * and point b.
  537. *
  538. * @param {Object} a point with x/y properties
  539. * @param {Object} b point with x/y properties
  540. */
  541. function distanceBetween( a, b ) {
  542. var dx = a.x - b.x,
  543. dy = a.y - b.y;
  544. return Math.sqrt( dx*dx + dy*dy );
  545. }
  546. /**
  547. * Applies a CSS transform to the target element.
  548. */
  549. function transformElement( element, transform ) {
  550. element.style.WebkitTransform = transform;
  551. element.style.MozTransform = transform;
  552. element.style.msTransform = transform;
  553. element.style.OTransform = transform;
  554. element.style.transform = transform;
  555. }
  556. /**
  557. * Retrieves the height of the given element by looking
  558. * at the position and height of its immediate children.
  559. */
  560. function getAbsoluteHeight( element ) {
  561. var height = 0;
  562. if( element ) {
  563. var absoluteChildren = 0;
  564. toArray( element.childNodes ).forEach( function( child ) {
  565. if( typeof child.offsetTop === 'number' && child.style ) {
  566. // Count # of abs children
  567. if( child.style.position === 'absolute' ) {
  568. absoluteChildren += 1;
  569. }
  570. height = Math.max( height, child.offsetTop + child.offsetHeight );
  571. }
  572. } );
  573. // If there are no absolute children, use offsetHeight
  574. if( absoluteChildren === 0 ) {
  575. height = element.offsetHeight;
  576. }
  577. }
  578. return height;
  579. }
  580. /**
  581. * Returns the remaining height within the parent of the
  582. * target element after subtracting the height of all
  583. * siblings.
  584. *
  585. * remaining height = [parent height] - [ siblings height]
  586. */
  587. function getRemainingHeight( element, height ) {
  588. height = height || 0;
  589. if( element ) {
  590. var parent = element.parentNode;
  591. var siblings = parent.childNodes;
  592. // Subtract the height of each sibling
  593. toArray( siblings ).forEach( function( sibling ) {
  594. if( typeof sibling.offsetHeight === 'number' && sibling !== element ) {
  595. var styles = window.getComputedStyle( sibling ),
  596. marginTop = parseInt( styles.marginTop, 10 ),
  597. marginBottom = parseInt( styles.marginBottom, 10 );
  598. height -= sibling.offsetHeight + marginTop + marginBottom;
  599. }
  600. } );
  601. var elementStyles = window.getComputedStyle( element );
  602. // Subtract the margins of the target element
  603. height -= parseInt( elementStyles.marginTop, 10 ) +
  604. parseInt( elementStyles.marginBottom, 10 );
  605. }
  606. return height;
  607. }
  608. /**
  609. * Checks if this instance is being used to print a PDF.
  610. */
  611. function isPrintingPDF() {
  612. return ( /print-pdf/gi ).test( window.location.search );
  613. }
  614. /**
  615. * Hides the address bar if we're on a mobile device.
  616. */
  617. function hideAddressBar() {
  618. if( config.hideAddressBar && isMobileDevice ) {
  619. // Events that should trigger the address bar to hide
  620. window.addEventListener( 'load', removeAddressBar, false );
  621. window.addEventListener( 'orientationchange', removeAddressBar, false );
  622. }
  623. }
  624. /**
  625. * Causes the address bar to hide on mobile devices,
  626. * more vertical space ftw.
  627. */
  628. function removeAddressBar() {
  629. // Portrait and not Chrome for iOS
  630. if( window.orientation === 0 && !/crios/gi.test( navigator.userAgent ) ) {
  631. document.documentElement.style.overflow = 'scroll';
  632. document.body.style.height = '120%';
  633. }
  634. else {
  635. document.documentElement.style.overflow = '';
  636. document.body.style.height = '100%';
  637. }
  638. setTimeout( function() {
  639. window.scrollTo( 0, 1 );
  640. }, 10 );
  641. }
  642. /**
  643. * Dispatches an event of the specified type from the
  644. * reveal DOM element.
  645. */
  646. function dispatchEvent( type, properties ) {
  647. var event = document.createEvent( "HTMLEvents", 1, 2 );
  648. event.initEvent( type, true, true );
  649. extend( event, properties );
  650. dom.wrapper.dispatchEvent( event );
  651. }
  652. /**
  653. * Wrap all links in 3D goodness.
  654. */
  655. function enableRollingLinks() {
  656. if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) {
  657. var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
  658. for( var i = 0, len = anchors.length; i < len; i++ ) {
  659. var anchor = anchors[i];
  660. if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
  661. var span = document.createElement('span');
  662. span.setAttribute('data-title', anchor.text);
  663. span.innerHTML = anchor.innerHTML;
  664. anchor.classList.add( 'roll' );
  665. anchor.innerHTML = '';
  666. anchor.appendChild(span);
  667. }
  668. }
  669. }
  670. }
  671. /**
  672. * Unwrap all 3D links.
  673. */
  674. function disableRollingLinks() {
  675. var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
  676. for( var i = 0, len = anchors.length; i < len; i++ ) {
  677. var anchor = anchors[i];
  678. var span = anchor.querySelector( 'span' );
  679. if( span ) {
  680. anchor.classList.remove( 'roll' );
  681. anchor.innerHTML = span.innerHTML;
  682. }
  683. }
  684. }
  685. /**
  686. * Bind preview frame links.
  687. */
  688. function enablePreviewLinks( selector ) {
  689. var anchors = toArray( document.querySelectorAll( selector ? selector : 'a' ) );
  690. anchors.forEach( function( element ) {
  691. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  692. element.addEventListener( 'click', onPreviewLinkClicked, false );
  693. }
  694. } );
  695. }
  696. /**
  697. * Unbind preview frame links.
  698. */
  699. function disablePreviewLinks() {
  700. var anchors = toArray( document.querySelectorAll( 'a' ) );
  701. anchors.forEach( function( element ) {
  702. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  703. element.removeEventListener( 'click', onPreviewLinkClicked, false );
  704. }
  705. } );
  706. }
  707. /**
  708. * Opens a preview window for the target URL.
  709. */
  710. function openPreview( url ) {
  711. closePreview();
  712. dom.preview = document.createElement( 'div' );
  713. dom.preview.classList.add( 'preview-link-overlay' );
  714. dom.wrapper.appendChild( dom.preview );
  715. dom.preview.innerHTML = [
  716. '<header>',
  717. '<a class="close" href="#"><span class="icon"></span></a>',
  718. '<a class="external" href="'+ url +'" target="_blank"><span class="icon"></span></a>',
  719. '</header>',
  720. '<div class="spinner"></div>',
  721. '<div class="viewport">',
  722. '<iframe src="'+ url +'"></iframe>',
  723. '</div>'
  724. ].join('');
  725. dom.preview.querySelector( 'iframe' ).addEventListener( 'load', function( event ) {
  726. dom.preview.classList.add( 'loaded' );
  727. }, false );
  728. dom.preview.querySelector( '.close' ).addEventListener( 'click', function( event ) {
  729. closePreview();
  730. event.preventDefault();
  731. }, false );
  732. dom.preview.querySelector( '.external' ).addEventListener( 'click', function( event ) {
  733. closePreview();
  734. }, false );
  735. setTimeout( function() {
  736. dom.preview.classList.add( 'visible' );
  737. }, 1 );
  738. }
  739. /**
  740. * Closes the iframe preview window.
  741. */
  742. function closePreview() {
  743. if( dom.preview ) {
  744. dom.preview.setAttribute( 'src', '' );
  745. dom.preview.parentNode.removeChild( dom.preview );
  746. dom.preview = null;
  747. }
  748. }
  749. /**
  750. * Return a sorted fragments list, ordered by an increasing
  751. * "data-fragment-index" attribute.
  752. *
  753. * Fragments will be revealed in the order that they are returned by
  754. * this function, so you can use the index attributes to control the
  755. * order of fragment appearance.
  756. *
  757. * To maintain a sensible default fragment order, fragments are presumed
  758. * to be passed in document order. This function adds a "fragment-index"
  759. * attribute to each node if such an attribute is not already present,
  760. * and sets that attribute to an integer value which is the position of
  761. * the fragment within the fragments list.
  762. */
  763. function sortFragments( fragments ) {
  764. var a = toArray( fragments );
  765. a.forEach( function( el, idx ) {
  766. if( !el.hasAttribute( 'data-fragment-index' ) ) {
  767. el.setAttribute( 'data-fragment-index', idx );
  768. }
  769. } );
  770. a.sort( function( l, r ) {
  771. return l.getAttribute( 'data-fragment-index' ) - r.getAttribute( 'data-fragment-index');
  772. } );
  773. return a;
  774. }
  775. /**
  776. * Applies JavaScript-controlled layout rules to the
  777. * presentation.
  778. */
  779. function layout() {
  780. if( dom.wrapper && !isPrintingPDF() ) {
  781. // Available space to scale within
  782. var availableWidth = dom.wrapper.offsetWidth,
  783. availableHeight = dom.wrapper.offsetHeight;
  784. // Reduce available space by margin
  785. availableWidth -= ( availableHeight * config.margin );
  786. availableHeight -= ( availableHeight * config.margin );
  787. // Dimensions of the content
  788. var slideWidth = config.width,
  789. slideHeight = config.height,
  790. slidePadding = 20; // TODO Dig this out of DOM
  791. // Layout the contents of the slides
  792. layoutSlideContents( config.width, config.height, slidePadding );
  793. // Slide width may be a percentage of available width
  794. if( typeof slideWidth === 'string' && /%$/.test( slideWidth ) ) {
  795. slideWidth = parseInt( slideWidth, 10 ) / 100 * availableWidth;
  796. }
  797. // Slide height may be a percentage of available height
  798. if( typeof slideHeight === 'string' && /%$/.test( slideHeight ) ) {
  799. slideHeight = parseInt( slideHeight, 10 ) / 100 * availableHeight;
  800. }
  801. dom.slides.style.width = slideWidth + 'px';
  802. dom.slides.style.height = slideHeight + 'px';
  803. // Determine scale of content to fit within available space
  804. scale = Math.min( availableWidth / slideWidth, availableHeight / slideHeight );
  805. // Respect max/min scale settings
  806. scale = Math.max( scale, config.minScale );
  807. scale = Math.min( scale, config.maxScale );
  808. // Prefer applying scale via zoom since Chrome blurs scaled content
  809. // with nested transforms
  810. if( typeof dom.slides.style.zoom !== 'undefined' && !navigator.userAgent.match( /(iphone|ipod|ipad|android)/gi ) ) {
  811. dom.slides.style.zoom = scale;
  812. }
  813. // Apply scale transform as a fallback
  814. else {
  815. transformElement( dom.slides, 'translate(-50%, -50%) scale('+ scale +') translate(50%, 50%)' );
  816. }
  817. // Select all slides, vertical and horizontal
  818. var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
  819. for( var i = 0, len = slides.length; i < len; i++ ) {
  820. var slide = slides[ i ];
  821. // Don't bother updating invisible slides
  822. if( slide.style.display === 'none' ) {
  823. continue;
  824. }
  825. if( config.center ) {
  826. // Vertical stacks are not centred since their section
  827. // children will be
  828. if( slide.classList.contains( 'stack' ) ) {
  829. slide.style.top = 0;
  830. }
  831. else {
  832. slide.style.top = Math.max( - ( getAbsoluteHeight( slide ) / 2 ) - slidePadding, -slideHeight / 2 ) + 'px';
  833. }
  834. }
  835. else {
  836. slide.style.top = '';
  837. }
  838. }
  839. updateProgress();
  840. updateParallax();
  841. }
  842. }
  843. /**
  844. * Applies layout logic to the contents of all slides in
  845. * the presentation.
  846. */
  847. function layoutSlideContents( width, height, padding ) {
  848. // Handle sizing of elements with the 'stretch' class
  849. toArray( dom.slides.querySelectorAll( 'section > .stretch' ) ).forEach( function( element ) {
  850. // Determine how much vertical space we can use
  851. var remainingHeight = getRemainingHeight( element, ( height - ( padding * 2 ) ) );
  852. // Consider the aspect ratio of media elements
  853. if( /(img|video)/gi.test( element.nodeName ) ) {
  854. var nw = element.naturalWidth || element.videoWidth,
  855. nh = element.naturalHeight || element.videoHeight;
  856. var es = Math.min( width / nw, remainingHeight / nh );
  857. element.style.width = ( nw * es ) + 'px';
  858. element.style.height = ( nh * es ) + 'px';
  859. }
  860. else {
  861. element.style.width = width + 'px';
  862. element.style.height = remainingHeight + 'px';
  863. }
  864. } );
  865. }
  866. /**
  867. * Stores the vertical index of a stack so that the same
  868. * vertical slide can be selected when navigating to and
  869. * from the stack.
  870. *
  871. * @param {HTMLElement} stack The vertical stack element
  872. * @param {int} v Index to memorize
  873. */
  874. function setPreviousVerticalIndex( stack, v ) {
  875. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
  876. stack.setAttribute( 'data-previous-indexv', v || 0 );
  877. }
  878. }
  879. /**
  880. * Retrieves the vertical index which was stored using
  881. * #setPreviousVerticalIndex() or 0 if no previous index
  882. * exists.
  883. *
  884. * @param {HTMLElement} stack The vertical stack element
  885. */
  886. function getPreviousVerticalIndex( stack ) {
  887. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
  888. // Prefer manually defined start-indexv
  889. var attributeName = stack.hasAttribute( 'data-start-indexv' ) ? 'data-start-indexv' : 'data-previous-indexv';
  890. return parseInt( stack.getAttribute( attributeName ) || 0, 10 );
  891. }
  892. return 0;
  893. }
  894. /**
  895. * Displays the overview of slides (quick nav) by
  896. * scaling down and arranging all slide elements.
  897. *
  898. * Experimental feature, might be dropped if perf
  899. * can't be improved.
  900. */
  901. function activateOverview() {
  902. // Only proceed if enabled in config
  903. if( config.overview ) {
  904. // Don't auto-slide while in overview mode
  905. cancelAutoSlide();
  906. var wasActive = dom.wrapper.classList.contains( 'overview' );
  907. // Vary the depth of the overview based on screen size
  908. var depth = window.innerWidth < 400 ? 1000 : 2500;
  909. dom.wrapper.classList.add( 'overview' );
  910. dom.wrapper.classList.remove( 'overview-deactivating' );
  911. clearTimeout( activateOverviewTimeout );
  912. clearTimeout( deactivateOverviewTimeout );
  913. // Not the pretties solution, but need to let the overview
  914. // class apply first so that slides are measured accurately
  915. // before we can position them
  916. activateOverviewTimeout = setTimeout( function() {
  917. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  918. for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
  919. var hslide = horizontalSlides[i],
  920. hoffset = config.rtl ? -105 : 105;
  921. hslide.setAttribute( 'data-index-h', i );
  922. // Apply CSS transform
  923. transformElement( hslide, 'translateZ(-'+ depth +'px) translate(' + ( ( i - indexh ) * hoffset ) + '%, 0%)' );
  924. if( hslide.classList.contains( 'stack' ) ) {
  925. var verticalSlides = hslide.querySelectorAll( 'section' );
  926. for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
  927. var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
  928. var vslide = verticalSlides[j];
  929. vslide.setAttribute( 'data-index-h', i );
  930. vslide.setAttribute( 'data-index-v', j );
  931. // Apply CSS transform
  932. transformElement( vslide, 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)' );
  933. // Navigate to this slide on click
  934. vslide.addEventListener( 'click', onOverviewSlideClicked, true );
  935. }
  936. }
  937. else {
  938. // Navigate to this slide on click
  939. hslide.addEventListener( 'click', onOverviewSlideClicked, true );
  940. }
  941. }
  942. updateSlidesVisibility();
  943. layout();
  944. if( !wasActive ) {
  945. // Notify observers of the overview showing
  946. dispatchEvent( 'overviewshown', {
  947. 'indexh': indexh,
  948. 'indexv': indexv,
  949. 'currentSlide': currentSlide
  950. } );
  951. }
  952. }, 10 );
  953. }
  954. }
  955. /**
  956. * Exits the slide overview and enters the currently
  957. * active slide.
  958. */
  959. function deactivateOverview() {
  960. // Only proceed if enabled in config
  961. if( config.overview ) {
  962. clearTimeout( activateOverviewTimeout );
  963. clearTimeout( deactivateOverviewTimeout );
  964. dom.wrapper.classList.remove( 'overview' );
  965. // Temporarily add a class so that transitions can do different things
  966. // depending on whether they are exiting/entering overview, or just
  967. // moving from slide to slide
  968. dom.wrapper.classList.add( 'overview-deactivating' );
  969. deactivateOverviewTimeout = setTimeout( function () {
  970. dom.wrapper.classList.remove( 'overview-deactivating' );
  971. }, 1 );
  972. // Select all slides
  973. toArray( document.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
  974. // Resets all transforms to use the external styles
  975. transformElement( slide, '' );
  976. slide.removeEventListener( 'click', onOverviewSlideClicked, true );
  977. } );
  978. slide( indexh, indexv );
  979. cueAutoSlide();
  980. // Notify observers of the overview hiding
  981. dispatchEvent( 'overviewhidden', {
  982. 'indexh': indexh,
  983. 'indexv': indexv,
  984. 'currentSlide': currentSlide
  985. } );
  986. }
  987. }
  988. /**
  989. * Toggles the slide overview mode on and off.
  990. *
  991. * @param {Boolean} override Optional flag which overrides the
  992. * toggle logic and forcibly sets the desired state. True means
  993. * overview is open, false means it's closed.
  994. */
  995. function toggleOverview( override ) {
  996. if( typeof override === 'boolean' ) {
  997. override ? activateOverview() : deactivateOverview();
  998. }
  999. else {
  1000. isOverview() ? deactivateOverview() : activateOverview();
  1001. }
  1002. }
  1003. /**
  1004. * Checks if the overview is currently active.
  1005. *
  1006. * @return {Boolean} true if the overview is active,
  1007. * false otherwise
  1008. */
  1009. function isOverview() {
  1010. return dom.wrapper.classList.contains( 'overview' );
  1011. }
  1012. /**
  1013. * Checks if the current or specified slide is vertical
  1014. * (nested within another slide).
  1015. *
  1016. * @param {HTMLElement} slide [optional] The slide to check
  1017. * orientation of
  1018. */
  1019. function isVerticalSlide( slide ) {
  1020. // Prefer slide argument, otherwise use current slide
  1021. slide = slide ? slide : currentSlide;
  1022. return slide && slide.parentNode && !!slide.parentNode.nodeName.match( /section/i );
  1023. }
  1024. /**
  1025. * Handling the fullscreen functionality via the fullscreen API
  1026. *
  1027. * @see http://fullscreen.spec.whatwg.org/
  1028. * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
  1029. */
  1030. function enterFullscreen() {
  1031. var element = document.body;
  1032. // Check which implementation is available
  1033. var requestMethod = element.requestFullScreen ||
  1034. element.webkitRequestFullscreen ||
  1035. element.webkitRequestFullScreen ||
  1036. element.mozRequestFullScreen ||
  1037. element.msRequestFullScreen;
  1038. if( requestMethod ) {
  1039. requestMethod.apply( element );
  1040. }
  1041. }
  1042. /**
  1043. * Enters the paused mode which fades everything on screen to
  1044. * black.
  1045. */
  1046. function pause() {
  1047. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1048. cancelAutoSlide();
  1049. dom.wrapper.classList.add( 'paused' );
  1050. if( wasPaused === false ) {
  1051. dispatchEvent( 'paused' );
  1052. }
  1053. }
  1054. /**
  1055. * Exits from the paused mode.
  1056. */
  1057. function resume() {
  1058. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1059. dom.wrapper.classList.remove( 'paused' );
  1060. cueAutoSlide();
  1061. if( wasPaused ) {
  1062. dispatchEvent( 'resumed' );
  1063. }
  1064. }
  1065. /**
  1066. * Toggles the paused mode on and off.
  1067. */
  1068. function togglePause() {
  1069. if( isPaused() ) {
  1070. resume();
  1071. }
  1072. else {
  1073. pause();
  1074. }
  1075. }
  1076. /**
  1077. * Checks if we are currently in the paused mode.
  1078. */
  1079. function isPaused() {
  1080. return dom.wrapper.classList.contains( 'paused' );
  1081. }
  1082. /**
  1083. * Steps from the current point in the presentation to the
  1084. * slide which matches the specified horizontal and vertical
  1085. * indices.
  1086. *
  1087. * @param {int} h Horizontal index of the target slide
  1088. * @param {int} v Vertical index of the target slide
  1089. * @param {int} f Optional index of a fragment within the
  1090. * target slide to activate
  1091. * @param {int} o Optional origin for use in multimaster environments
  1092. */
  1093. function slide( h, v, f, o ) {
  1094. // Remember where we were at before
  1095. previousSlide = currentSlide;
  1096. // Query all horizontal slides in the deck
  1097. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  1098. // If no vertical index is specified and the upcoming slide is a
  1099. // stack, resume at its previous vertical index
  1100. if( v === undefined ) {
  1101. v = getPreviousVerticalIndex( horizontalSlides[ h ] );
  1102. }
  1103. // If we were on a vertical stack, remember what vertical index
  1104. // it was on so we can resume at the same position when returning
  1105. if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
  1106. setPreviousVerticalIndex( previousSlide.parentNode, indexv );
  1107. }
  1108. // Remember the state before this slide
  1109. var stateBefore = state.concat();
  1110. // Reset the state array
  1111. state.length = 0;
  1112. var indexhBefore = indexh || 0,
  1113. indexvBefore = indexv || 0;
  1114. // Activate and transition to the new slide
  1115. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
  1116. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
  1117. // Update the visibility of slides now that the indices have changed
  1118. updateSlidesVisibility();
  1119. layout();
  1120. // Apply the new state
  1121. stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
  1122. // Check if this state existed on the previous slide. If it
  1123. // did, we will avoid adding it repeatedly
  1124. for( var j = 0; j < stateBefore.length; j++ ) {
  1125. if( stateBefore[j] === state[i] ) {
  1126. stateBefore.splice( j, 1 );
  1127. continue stateLoop;
  1128. }
  1129. }
  1130. document.documentElement.classList.add( state[i] );
  1131. // Dispatch custom event matching the state's name
  1132. dispatchEvent( state[i] );
  1133. }
  1134. // Clean up the remains of the previous state
  1135. while( stateBefore.length ) {
  1136. document.documentElement.classList.remove( stateBefore.pop() );
  1137. }
  1138. // If the overview is active, re-activate it to update positions
  1139. if( isOverview() ) {
  1140. activateOverview();
  1141. }
  1142. // Find the current horizontal slide and any possible vertical slides
  1143. // within it
  1144. var currentHorizontalSlide = horizontalSlides[ indexh ],
  1145. currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
  1146. // Store references to the previous and current slides
  1147. currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
  1148. // Show fragment, if specified
  1149. if( typeof f !== 'undefined' ) {
  1150. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
  1151. toArray( fragments ).forEach( function( fragment, indexf ) {
  1152. if( indexf < f ) {
  1153. fragment.classList.add( 'visible' );
  1154. }
  1155. else {
  1156. fragment.classList.remove( 'visible' );
  1157. }
  1158. } );
  1159. }
  1160. // Dispatch an event if the slide changed
  1161. var slideChanged = ( indexh !== indexhBefore || indexv !== indexvBefore );
  1162. if( slideChanged ) {
  1163. dispatchEvent( 'slidechanged', {
  1164. 'indexh': indexh,
  1165. 'indexv': indexv,
  1166. 'previousSlide': previousSlide,
  1167. 'currentSlide': currentSlide,
  1168. 'origin': o
  1169. } );
  1170. }
  1171. else {
  1172. // Ensure that the previous slide is never the same as the current
  1173. previousSlide = null;
  1174. }
  1175. // Solves an edge case where the previous slide maintains the
  1176. // 'present' class when navigating between adjacent vertical
  1177. // stacks
  1178. if( previousSlide ) {
  1179. previousSlide.classList.remove( 'present' );
  1180. // Reset all slides upon navigate to home
  1181. // Issue: #285
  1182. if ( document.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
  1183. // Launch async task
  1184. setTimeout( function () {
  1185. var slides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
  1186. for( i in slides ) {
  1187. if( slides[i] ) {
  1188. // Reset stack
  1189. setPreviousVerticalIndex( slides[i], 0 );
  1190. }
  1191. }
  1192. }, 0 );
  1193. }
  1194. }
  1195. // Handle embedded content
  1196. if( slideChanged ) {
  1197. stopEmbeddedContent( previousSlide );
  1198. startEmbeddedContent( currentSlide );
  1199. }
  1200. updateControls();
  1201. updateProgress();
  1202. updateBackground();
  1203. updateParallax();
  1204. // Update the URL hash
  1205. writeURL();
  1206. }
  1207. /**
  1208. * Syncs the presentation with the current DOM. Useful
  1209. * when new slides or control elements are added or when
  1210. * the configuration has changed.
  1211. */
  1212. function sync() {
  1213. // Subscribe to input
  1214. removeEventListeners();
  1215. addEventListeners();
  1216. // Force a layout to make sure the current config is accounted for
  1217. layout();
  1218. // Reflect the current autoSlide value
  1219. autoSlide = config.autoSlide;
  1220. // Start auto-sliding if it's enabled
  1221. cueAutoSlide();
  1222. // Re-create the slide backgrounds
  1223. createBackgrounds();
  1224. updateControls();
  1225. updateProgress();
  1226. updateBackground();
  1227. }
  1228. /**
  1229. * Updates one dimension of slides by showing the slide
  1230. * with the specified index.
  1231. *
  1232. * @param {String} selector A CSS selector that will fetch
  1233. * the group of slides we are working with
  1234. * @param {Number} index The index of the slide that should be
  1235. * shown
  1236. *
  1237. * @return {Number} The index of the slide that is now shown,
  1238. * might differ from the passed in index if it was out of
  1239. * bounds.
  1240. */
  1241. function updateSlides( selector, index ) {
  1242. // Select all slides and convert the NodeList result to
  1243. // an array
  1244. var slides = toArray( document.querySelectorAll( selector ) ),
  1245. slidesLength = slides.length;
  1246. if( slidesLength ) {
  1247. // Should the index loop?
  1248. if( config.loop ) {
  1249. index %= slidesLength;
  1250. if( index < 0 ) {
  1251. index = slidesLength + index;
  1252. }
  1253. }
  1254. // Enforce max and minimum index bounds
  1255. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  1256. for( var i = 0; i < slidesLength; i++ ) {
  1257. var element = slides[i];
  1258. var reverse = config.rtl && !isVerticalSlide( element );
  1259. element.classList.remove( 'past' );
  1260. element.classList.remove( 'present' );
  1261. element.classList.remove( 'future' );
  1262. // http://www.w3.org/html/wg/drafts/html/master/editing.html#the-hidden-attribute
  1263. element.setAttribute( 'hidden', '' );
  1264. if( i < index ) {
  1265. // Any element previous to index is given the 'past' class
  1266. element.classList.add( reverse ? 'future' : 'past' );
  1267. }
  1268. else if( i > index ) {
  1269. // Any element subsequent to index is given the 'future' class
  1270. element.classList.add( reverse ? 'past' : 'future' );
  1271. var fragments = toArray( element.querySelectorAll( '.fragment.visible' ) );
  1272. // No fragments in future slides should be visible ahead of time
  1273. while( fragments.length ) {
  1274. fragments.pop().classList.remove( 'visible' );
  1275. }
  1276. }
  1277. // If this element contains vertical slides
  1278. if( element.querySelector( 'section' ) ) {
  1279. element.classList.add( 'stack' );
  1280. }
  1281. }
  1282. // Mark the current slide as present
  1283. slides[index].classList.add( 'present' );
  1284. slides[index].removeAttribute( 'hidden' );
  1285. // If this slide has a state associated with it, add it
  1286. // onto the current state of the deck
  1287. var slideState = slides[index].getAttribute( 'data-state' );
  1288. if( slideState ) {
  1289. state = state.concat( slideState.split( ' ' ) );
  1290. }
  1291. // If this slide has a data-autoslide attribute associated use this as
  1292. // autoSlide value otherwise use the global configured time
  1293. var slideAutoSlide = slides[index].getAttribute( 'data-autoslide' );
  1294. if( slideAutoSlide ) {
  1295. autoSlide = parseInt( slideAutoSlide, 10 );
  1296. }
  1297. else {
  1298. autoSlide = config.autoSlide;
  1299. }
  1300. cueAutoSlide();
  1301. }
  1302. else {
  1303. // Since there are no slides we can't be anywhere beyond the
  1304. // zeroth index
  1305. index = 0;
  1306. }
  1307. return index;
  1308. }
  1309. /**
  1310. * Optimization method; hide all slides that are far away
  1311. * from the present slide.
  1312. */
  1313. function updateSlidesVisibility() {
  1314. // Select all slides and convert the NodeList result to
  1315. // an array
  1316. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ),
  1317. horizontalSlidesLength = horizontalSlides.length,
  1318. distanceX,
  1319. distanceY;
  1320. if( horizontalSlidesLength ) {
  1321. // The number of steps away from the present slide that will
  1322. // be visible
  1323. var viewDistance = isOverview() ? 10 : config.viewDistance;
  1324. // Limit view distance on weaker devices
  1325. if( isMobileDevice ) {
  1326. viewDistance = isOverview() ? 6 : 1;
  1327. }
  1328. for( var x = 0; x < horizontalSlidesLength; x++ ) {
  1329. var horizontalSlide = horizontalSlides[x];
  1330. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) ),
  1331. verticalSlidesLength = verticalSlides.length;
  1332. // Loops so that it measures 1 between the first and last slides
  1333. distanceX = Math.abs( ( indexh - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0;
  1334. // Show the horizontal slide if it's within the view distance
  1335. horizontalSlide.style.display = distanceX > viewDistance ? 'none' : 'block';
  1336. if( verticalSlidesLength ) {
  1337. var oy = getPreviousVerticalIndex( horizontalSlide );
  1338. for( var y = 0; y < verticalSlidesLength; y++ ) {
  1339. var verticalSlide = verticalSlides[y];
  1340. distanceY = x === indexh ? Math.abs( indexv - y ) : Math.abs( y - oy );
  1341. verticalSlide.style.display = ( distanceX + distanceY ) > viewDistance ? 'none' : 'block';
  1342. }
  1343. }
  1344. }
  1345. }
  1346. }
  1347. /**
  1348. * Updates the progress bar to reflect the current slide.
  1349. */
  1350. function updateProgress() {
  1351. // Update progress if enabled
  1352. if( config.progress && dom.progress ) {
  1353. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1354. // The number of past and total slides
  1355. var totalCount = document.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  1356. var pastCount = 0;
  1357. // Step through all slides and count the past ones
  1358. mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
  1359. var horizontalSlide = horizontalSlides[i];
  1360. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1361. for( var j = 0; j < verticalSlides.length; j++ ) {
  1362. // Stop as soon as we arrive at the present
  1363. if( verticalSlides[j].classList.contains( 'present' ) ) {
  1364. break mainLoop;
  1365. }
  1366. pastCount++;
  1367. }
  1368. // Stop as soon as we arrive at the present
  1369. if( horizontalSlide.classList.contains( 'present' ) ) {
  1370. break;
  1371. }
  1372. // Don't count the wrapping section for vertical slides
  1373. if( horizontalSlide.classList.contains( 'stack' ) === false ) {
  1374. pastCount++;
  1375. }
  1376. }
  1377. dom.progressbar.style.width = ( pastCount / ( totalCount - 1 ) ) * window.innerWidth + 'px';
  1378. }
  1379. }
  1380. /**
  1381. * Updates the state of all control/navigation arrows.
  1382. */
  1383. function updateControls() {
  1384. var routes = availableRoutes();
  1385. var fragments = availableFragments();
  1386. // Remove the 'enabled' class from all directions
  1387. dom.controlsLeft.concat( dom.controlsRight )
  1388. .concat( dom.controlsUp )
  1389. .concat( dom.controlsDown )
  1390. .concat( dom.controlsPrev )
  1391. .concat( dom.controlsNext ).forEach( function( node ) {
  1392. node.classList.remove( 'enabled' );
  1393. node.classList.remove( 'fragmented' );
  1394. } );
  1395. // Add the 'enabled' class to the available routes
  1396. if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1397. if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1398. if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1399. if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1400. // Prev/next buttons
  1401. if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1402. if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1403. // Highlight fragment directions
  1404. if( currentSlide ) {
  1405. // Always apply fragment decorator to prev/next buttons
  1406. if( fragments.prev ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1407. if( fragments.next ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1408. // Apply fragment decorators to directional buttons based on
  1409. // what slide axis they are in
  1410. if( isVerticalSlide( currentSlide ) ) {
  1411. if( fragments.prev ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1412. if( fragments.next ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1413. }
  1414. else {
  1415. if( fragments.prev ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1416. if( fragments.next ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1417. }
  1418. }
  1419. }
  1420. /**
  1421. * Updates the background elements to reflect the current
  1422. * slide.
  1423. */
  1424. function updateBackground() {
  1425. // Update the classes of all backgrounds to match the
  1426. // states of their slides (past/present/future)
  1427. toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) {
  1428. // Reverse past/future classes when in RTL mode
  1429. var horizontalPast = config.rtl ? 'future' : 'past',
  1430. horizontalFuture = config.rtl ? 'past' : 'future';
  1431. backgroundh.className = 'slide-background ' + ( h < indexh ? horizontalPast : h > indexh ? horizontalFuture : 'present' );
  1432. toArray( backgroundh.childNodes ).forEach( function( backgroundv, v ) {
  1433. backgroundv.className = 'slide-background ' + ( v < indexv ? 'past' : v > indexv ? 'future' : 'present' );
  1434. } );
  1435. } );
  1436. // Allow the first background to apply without transition
  1437. setTimeout( function() {
  1438. dom.background.classList.remove( 'no-transition' );
  1439. }, 1 );
  1440. }
  1441. /**
  1442. * Updates the position of the parallax background based
  1443. * on the current slide index.
  1444. */
  1445. function updateParallax() {
  1446. if( config.parallaxBackgroundImage ) {
  1447. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1448. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1449. var backgroundSize = dom.background.style.backgroundSize.split( ' ' ),
  1450. backgroundWidth, backgroundHeight;
  1451. if( backgroundSize.length === 1 ) {
  1452. backgroundWidth = backgroundHeight = parseInt( backgroundSize[0], 10 );
  1453. }
  1454. else {
  1455. backgroundWidth = parseInt( backgroundSize[0], 10 );
  1456. backgroundHeight = parseInt( backgroundSize[1], 10 );
  1457. }
  1458. var slideWidth = dom.background.offsetWidth;
  1459. var horizontalSlideCount = horizontalSlides.length;
  1460. var horizontalOffset = -( backgroundWidth - slideWidth ) / ( horizontalSlideCount-1 ) * indexh;
  1461. var slideHeight = dom.background.offsetHeight;
  1462. var verticalSlideCount = verticalSlides.length;
  1463. var verticalOffset = verticalSlideCount > 0 ? -( backgroundHeight - slideHeight ) / ( verticalSlideCount-1 ) * indexv : 0;
  1464. dom.background.style.backgroundPosition = horizontalOffset + 'px ' + verticalOffset + 'px';
  1465. }
  1466. }
  1467. /**
  1468. * Determine what available routes there are for navigation.
  1469. *
  1470. * @return {Object} containing four booleans: left/right/up/down
  1471. */
  1472. function availableRoutes() {
  1473. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1474. verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1475. var routes = {
  1476. left: indexh > 0 || config.loop,
  1477. right: indexh < horizontalSlides.length - 1 || config.loop,
  1478. up: indexv > 0,
  1479. down: indexv < verticalSlides.length - 1
  1480. };
  1481. // reverse horizontal controls for rtl
  1482. if( config.rtl ) {
  1483. var left = routes.left;
  1484. routes.left = routes.right;
  1485. routes.right = left;
  1486. }
  1487. return routes;
  1488. }
  1489. /**
  1490. * Returns an object describing the available fragment
  1491. * directions.
  1492. *
  1493. * @return {Object} two boolean properties: prev/next
  1494. */
  1495. function availableFragments() {
  1496. if( currentSlide && config.fragments ) {
  1497. var fragments = currentSlide.querySelectorAll( '.fragment' );
  1498. var hiddenFragments = currentSlide.querySelectorAll( '.fragment:not(.visible)' );
  1499. return {
  1500. prev: fragments.length - hiddenFragments.length > 0,
  1501. next: !!hiddenFragments.length
  1502. };
  1503. }
  1504. else {
  1505. return { prev: false, next: false };
  1506. }
  1507. }
  1508. /**
  1509. * Start playback of any embedded content inside of
  1510. * the targeted slide.
  1511. */
  1512. function startEmbeddedContent( slide ) {
  1513. if( slide ) {
  1514. // HTML5 media elements
  1515. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1516. if( el.hasAttribute( 'data-autoplay' ) ) {
  1517. el.play();
  1518. }
  1519. } );
  1520. // YouTube embeds
  1521. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  1522. if( el.hasAttribute( 'data-autoplay' ) ) {
  1523. el.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
  1524. }
  1525. });
  1526. }
  1527. }
  1528. /**
  1529. * Stop playback of any embedded content inside of
  1530. * the targeted slide.
  1531. */
  1532. function stopEmbeddedContent( slide ) {
  1533. if( slide ) {
  1534. // HTML5 media elements
  1535. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  1536. if( !el.hasAttribute( 'data-ignore' ) ) {
  1537. el.pause();
  1538. }
  1539. } );
  1540. // YouTube embeds
  1541. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  1542. if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
  1543. el.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
  1544. }
  1545. });
  1546. }
  1547. }
  1548. /**
  1549. * Reads the current URL (hash) and navigates accordingly.
  1550. */
  1551. function readURL() {
  1552. var hash = window.location.hash;
  1553. // Attempt to parse the hash as either an index or name
  1554. var bits = hash.slice( 2 ).split( '/' ),
  1555. name = hash.replace( /#|\//gi, '' );
  1556. // If the first bit is invalid and there is a name we can
  1557. // assume that this is a named link
  1558. if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
  1559. // Find the slide with the specified name
  1560. var element = document.querySelector( '#' + name );
  1561. if( element ) {
  1562. // Find the position of the named slide and navigate to it
  1563. var indices = Reveal.getIndices( element );
  1564. slide( indices.h, indices.v );
  1565. }
  1566. // If the slide doesn't exist, navigate to the current slide
  1567. else {
  1568. slide( indexh || 0, indexv || 0 );
  1569. }
  1570. }
  1571. else {
  1572. // Read the index components of the hash
  1573. var h = parseInt( bits[0], 10 ) || 0,
  1574. v = parseInt( bits[1], 10 ) || 0;
  1575. if( h !== indexh || v !== indexv ) {
  1576. slide( h, v );
  1577. }
  1578. }
  1579. }
  1580. /**
  1581. * Updates the page URL (hash) to reflect the current
  1582. * state.
  1583. *
  1584. * @param {Number} delay The time in ms to wait before
  1585. * writing the hash
  1586. */
  1587. function writeURL( delay ) {
  1588. if( config.history ) {
  1589. // Make sure there's never more than one timeout running
  1590. clearTimeout( writeURLTimeout );
  1591. // If a delay is specified, timeout this call
  1592. if( typeof delay === 'number' ) {
  1593. writeURLTimeout = setTimeout( writeURL, delay );
  1594. }
  1595. else {
  1596. var url = '/';
  1597. // If the current slide has an ID, use that as a named link
  1598. if( currentSlide && typeof currentSlide.getAttribute( 'id' ) === 'string' ) {
  1599. url = '/' + currentSlide.getAttribute( 'id' );
  1600. }
  1601. // Otherwise use the /h/v index
  1602. else {
  1603. if( indexh > 0 || indexv > 0 ) url += indexh;
  1604. if( indexv > 0 ) url += '/' + indexv;
  1605. }
  1606. window.location.hash = url;
  1607. }
  1608. }
  1609. }
  1610. /**
  1611. * Retrieves the h/v location of the current, or specified,
  1612. * slide.
  1613. *
  1614. * @param {HTMLElement} slide If specified, the returned
  1615. * index will be for this slide rather than the currently
  1616. * active one
  1617. *
  1618. * @return {Object} { h: <int>, v: <int>, f: <int> }
  1619. */
  1620. function getIndices( slide ) {
  1621. // By default, return the current indices
  1622. var h = indexh,
  1623. v = indexv,
  1624. f;
  1625. // If a slide is specified, return the indices of that slide
  1626. if( slide ) {
  1627. var isVertical = isVerticalSlide( slide );
  1628. var slideh = isVertical ? slide.parentNode : slide;
  1629. // Select all horizontal slides
  1630. var horizontalSlides = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1631. // Now that we know which the horizontal slide is, get its index
  1632. h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
  1633. // If this is a vertical slide, grab the vertical index
  1634. if( isVertical ) {
  1635. v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
  1636. }
  1637. }
  1638. if( !slide && currentSlide ) {
  1639. var hasFragments = currentSlide.querySelectorAll( '.fragment' ).length > 0;
  1640. if( hasFragments ) {
  1641. var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
  1642. f = visibleFragments.length;
  1643. }
  1644. }
  1645. return { h: h, v: v, f: f };
  1646. }
  1647. /**
  1648. * Navigate to the next slide fragment.
  1649. *
  1650. * @return {Boolean} true if there was a next fragment,
  1651. * false otherwise
  1652. */
  1653. function nextFragment() {
  1654. if( currentSlide && config.fragments ) {
  1655. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment:not(.visible)' ) );
  1656. if( fragments.length ) {
  1657. // Find the index of the next fragment
  1658. var index = fragments[0].getAttribute( 'data-fragment-index' );
  1659. // Find all fragments with the same index
  1660. fragments = currentSlide.querySelectorAll( '.fragment[data-fragment-index="'+ index +'"]' );
  1661. toArray( fragments ).forEach( function( element ) {
  1662. element.classList.add( 'visible' );
  1663. } );
  1664. // Notify subscribers of the change
  1665. dispatchEvent( 'fragmentshown', { fragment: fragments[0], fragments: fragments } );
  1666. updateControls();
  1667. return true;
  1668. }
  1669. }
  1670. return false;
  1671. }
  1672. /**
  1673. * Navigate to the previous slide fragment.
  1674. *
  1675. * @return {Boolean} true if there was a previous fragment,
  1676. * false otherwise
  1677. */
  1678. function previousFragment() {
  1679. if( currentSlide && config.fragments ) {
  1680. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) );
  1681. if( fragments.length ) {
  1682. // Find the index of the previous fragment
  1683. var index = fragments[ fragments.length - 1 ].getAttribute( 'data-fragment-index' );
  1684. // Find all fragments with the same index
  1685. fragments = currentSlide.querySelectorAll( '.fragment[data-fragment-index="'+ index +'"]' );
  1686. toArray( fragments ).forEach( function( f ) {
  1687. f.classList.remove( 'visible' );
  1688. } );
  1689. // Notify subscribers of the change
  1690. dispatchEvent( 'fragmenthidden', { fragment: fragments[0], fragments: fragments } );
  1691. updateControls();
  1692. return true;
  1693. }
  1694. }
  1695. return false;
  1696. }
  1697. /**
  1698. * Cues a new automated slide if enabled in the config.
  1699. */
  1700. function cueAutoSlide() {
  1701. clearTimeout( autoSlideTimeout );
  1702. // Cue the next auto-slide if enabled
  1703. if( autoSlide && !isPaused() && !isOverview() ) {
  1704. autoSlideTimeout = setTimeout( navigateNext, autoSlide );
  1705. }
  1706. }
  1707. /**
  1708. * Cancels any ongoing request to auto-slide.
  1709. */
  1710. function cancelAutoSlide() {
  1711. clearTimeout( autoSlideTimeout );
  1712. }
  1713. function navigateLeft() {
  1714. // Reverse for RTL
  1715. if( config.rtl ) {
  1716. if( ( isOverview() || nextFragment() === false ) && availableRoutes().left ) {
  1717. slide( indexh + 1 );
  1718. }
  1719. }
  1720. // Normal navigation
  1721. else if( ( isOverview() || previousFragment() === false ) && availableRoutes().left ) {
  1722. slide( indexh - 1 );
  1723. }
  1724. }
  1725. function navigateRight() {
  1726. // Reverse for RTL
  1727. if( config.rtl ) {
  1728. if( ( isOverview() || previousFragment() === false ) && availableRoutes().right ) {
  1729. slide( indexh - 1 );
  1730. }
  1731. }
  1732. // Normal navigation
  1733. else if( ( isOverview() || nextFragment() === false ) && availableRoutes().right ) {
  1734. slide( indexh + 1 );
  1735. }
  1736. }
  1737. function navigateUp() {
  1738. // Prioritize hiding fragments
  1739. if( ( isOverview() || previousFragment() === false ) && availableRoutes().up ) {
  1740. slide( indexh, indexv - 1 );
  1741. }
  1742. }
  1743. function navigateDown() {
  1744. // Prioritize revealing fragments
  1745. if( ( isOverview() || nextFragment() === false ) && availableRoutes().down ) {
  1746. slide( indexh, indexv + 1 );
  1747. }
  1748. }
  1749. /**
  1750. * Navigates backwards, prioritized in the following order:
  1751. * 1) Previous fragment
  1752. * 2) Previous vertical slide
  1753. * 3) Previous horizontal slide
  1754. */
  1755. function navigatePrev() {
  1756. // Prioritize revealing fragments
  1757. if( previousFragment() === false ) {
  1758. if( availableRoutes().up ) {
  1759. navigateUp();
  1760. }
  1761. else {
  1762. // Fetch the previous horizontal slide, if there is one
  1763. var previousSlide = document.querySelector( HORIZONTAL_SLIDES_SELECTOR + '.past:nth-child(' + indexh + ')' );
  1764. if( previousSlide ) {
  1765. var v = ( previousSlide.querySelectorAll( 'section' ).length - 1 ) || undefined;
  1766. var h = indexh - 1;
  1767. slide( h, v );
  1768. }
  1769. }
  1770. }
  1771. }
  1772. /**
  1773. * Same as #navigatePrev() but navigates forwards.
  1774. */
  1775. function navigateNext() {
  1776. // Prioritize revealing fragments
  1777. if( nextFragment() === false ) {
  1778. availableRoutes().down ? navigateDown() : navigateRight();
  1779. }
  1780. // If auto-sliding is enabled we need to cue up
  1781. // another timeout
  1782. cueAutoSlide();
  1783. }
  1784. // --------------------------------------------------------------------//
  1785. // ----------------------------- EVENTS -------------------------------//
  1786. // --------------------------------------------------------------------//
  1787. /**
  1788. * Called by all event handlers that are based on user
  1789. * input.
  1790. */
  1791. function onUserInput( event ) {
  1792. if( config.autoSlideStoppable ) {
  1793. config.autoSlide = 0;
  1794. cancelAutoSlide();
  1795. }
  1796. }
  1797. /**
  1798. * Handler for the document level 'keydown' event.
  1799. */
  1800. function onDocumentKeyDown( event ) {
  1801. // Check if there's a focused element that could be using
  1802. // the keyboard
  1803. var activeElement = document.activeElement;
  1804. var hasFocus = !!( document.activeElement && ( document.activeElement.type || document.activeElement.href || document.activeElement.contentEditable !== 'inherit' ) );
  1805. // Disregard the event if there's a focused element or a
  1806. // keyboard modifier key is present
  1807. if( hasFocus || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
  1808. // While paused only allow "unpausing" keyboard events (b and .)
  1809. if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) {
  1810. return false;
  1811. }
  1812. var triggered = false;
  1813. // 1. User defined key bindings
  1814. if( typeof config.keyboard === 'object' ) {
  1815. for( var key in config.keyboard ) {
  1816. // Check if this binding matches the pressed key
  1817. if( parseInt( key, 10 ) === event.keyCode ) {
  1818. var value = config.keyboard[ key ];
  1819. // Callback function
  1820. if( typeof value === 'function' ) {
  1821. value.apply( null, [ event ] );
  1822. }
  1823. // String shortcuts to reveal.js API
  1824. else if( typeof value === 'string' && typeof Reveal[ value ] === 'function' ) {
  1825. Reveal[ value ].call();
  1826. }
  1827. triggered = true;
  1828. }
  1829. }
  1830. }
  1831. // 2. System defined key bindings
  1832. if( triggered === false ) {
  1833. // Assume true and try to prove false
  1834. triggered = true;
  1835. switch( event.keyCode ) {
  1836. // p, page up
  1837. case 80: case 33: navigatePrev(); break;
  1838. // n, page down
  1839. case 78: case 34: navigateNext(); break;
  1840. // h, left
  1841. case 72: case 37: navigateLeft(); break;
  1842. // l, right
  1843. case 76: case 39: navigateRight(); break;
  1844. // k, up
  1845. case 75: case 38: navigateUp(); break;
  1846. // j, down
  1847. case 74: case 40: navigateDown(); break;
  1848. // home
  1849. case 36: slide( 0 ); break;
  1850. // end
  1851. case 35: slide( Number.MAX_VALUE ); break;
  1852. // space
  1853. case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
  1854. // return
  1855. case 13: isOverview() ? deactivateOverview() : triggered = false; break;
  1856. // b, period, Logitech presenter tools "black screen" button
  1857. case 66: case 190: case 191: togglePause(); break;
  1858. // f
  1859. case 70: enterFullscreen(); break;
  1860. default:
  1861. triggered = false;
  1862. }
  1863. }
  1864. // If the input resulted in a triggered action we should prevent
  1865. // the browsers default behavior
  1866. if( triggered ) {
  1867. event.preventDefault();
  1868. }
  1869. // ESC or O key
  1870. else if ( ( event.keyCode === 27 || event.keyCode === 79 ) && supports3DTransforms ) {
  1871. toggleOverview();
  1872. event.preventDefault();
  1873. }
  1874. // If auto-sliding is enabled we need to cue up
  1875. // another timeout
  1876. cueAutoSlide();
  1877. onUserInput( event );
  1878. }
  1879. /**
  1880. * Handler for the 'touchstart' event, enables support for
  1881. * swipe and pinch gestures.
  1882. */
  1883. function onTouchStart( event ) {
  1884. touch.startX = event.touches[0].clientX;
  1885. touch.startY = event.touches[0].clientY;
  1886. touch.startCount = event.touches.length;
  1887. // If there's two touches we need to memorize the distance
  1888. // between those two points to detect pinching
  1889. if( event.touches.length === 2 && config.overview ) {
  1890. touch.startSpan = distanceBetween( {
  1891. x: event.touches[1].clientX,
  1892. y: event.touches[1].clientY
  1893. }, {
  1894. x: touch.startX,
  1895. y: touch.startY
  1896. } );
  1897. }
  1898. onUserInput( event );
  1899. }
  1900. /**
  1901. * Handler for the 'touchmove' event.
  1902. */
  1903. function onTouchMove( event ) {
  1904. // Each touch should only trigger one action
  1905. if( !touch.captured ) {
  1906. var currentX = event.touches[0].clientX;
  1907. var currentY = event.touches[0].clientY;
  1908. // If the touch started with two points and still has
  1909. // two active touches; test for the pinch gesture
  1910. if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
  1911. // The current distance in pixels between the two touch points
  1912. var currentSpan = distanceBetween( {
  1913. x: event.touches[1].clientX,
  1914. y: event.touches[1].clientY
  1915. }, {
  1916. x: touch.startX,
  1917. y: touch.startY
  1918. } );
  1919. // If the span is larger than the desire amount we've got
  1920. // ourselves a pinch
  1921. if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
  1922. touch.captured = true;
  1923. if( currentSpan < touch.startSpan ) {
  1924. activateOverview();
  1925. }
  1926. else {
  1927. deactivateOverview();
  1928. }
  1929. }
  1930. event.preventDefault();
  1931. }
  1932. // There was only one touch point, look for a swipe
  1933. else if( event.touches.length === 1 && touch.startCount !== 2 ) {
  1934. var deltaX = currentX - touch.startX,
  1935. deltaY = currentY - touch.startY;
  1936. if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  1937. touch.captured = true;
  1938. navigateLeft();
  1939. }
  1940. else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  1941. touch.captured = true;
  1942. navigateRight();
  1943. }
  1944. else if( deltaY > touch.threshold ) {
  1945. touch.captured = true;
  1946. navigateUp();
  1947. }
  1948. else if( deltaY < -touch.threshold ) {
  1949. touch.captured = true;
  1950. navigateDown();
  1951. }
  1952. // If we're embedded, only block touch events if they have
  1953. // triggered an action
  1954. if( config.embedded ) {
  1955. if( touch.captured || isVerticalSlide( currentSlide ) ) {
  1956. event.preventDefault();
  1957. }
  1958. }
  1959. // Not embedded? Block them all to avoid needless tossing
  1960. // around of the viewport in iOS
  1961. else {
  1962. event.preventDefault();
  1963. }
  1964. }
  1965. }
  1966. // There's a bug with swiping on some Android devices unless
  1967. // the default action is always prevented
  1968. else if( navigator.userAgent.match( /android/gi ) ) {
  1969. event.preventDefault();
  1970. }
  1971. }
  1972. /**
  1973. * Handler for the 'touchend' event.
  1974. */
  1975. function onTouchEnd( event ) {
  1976. touch.captured = false;
  1977. }
  1978. /**
  1979. * Convert pointer down to touch start.
  1980. */
  1981. function onPointerDown( event ) {
  1982. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  1983. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  1984. onTouchStart( event );
  1985. }
  1986. onUserInput( event );
  1987. }
  1988. /**
  1989. * Convert pointer move to touch move.
  1990. */
  1991. function onPointerMove( event ) {
  1992. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  1993. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  1994. onTouchMove( event );
  1995. }
  1996. }
  1997. /**
  1998. * Convert pointer up to touch end.
  1999. */
  2000. function onPointerUp( event ) {
  2001. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH ) {
  2002. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  2003. onTouchEnd( event );
  2004. }
  2005. }
  2006. /**
  2007. * Handles mouse wheel scrolling, throttled to avoid skipping
  2008. * multiple slides.
  2009. */
  2010. function onDocumentMouseScroll( event ) {
  2011. if( Date.now() - lastMouseWheelStep > 600 ) {
  2012. lastMouseWheelStep = Date.now();
  2013. var delta = event.detail || -event.wheelDelta;
  2014. if( delta > 0 ) {
  2015. navigateNext();
  2016. }
  2017. else {
  2018. navigatePrev();
  2019. }
  2020. }
  2021. }
  2022. /**
  2023. * Clicking on the progress bar results in a navigation to the
  2024. * closest approximate horizontal slide using this equation:
  2025. *
  2026. * ( clickX / presentationWidth ) * numberOfSlides
  2027. */
  2028. function onProgressClicked( event ) {
  2029. event.preventDefault();
  2030. var slidesTotal = toArray( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
  2031. var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
  2032. slide( slideIndex );
  2033. onUserInput( event );
  2034. }
  2035. /**
  2036. * Event handler for navigation control buttons.
  2037. */
  2038. function onNavigateLeftClicked( event ) { event.preventDefault(); navigateLeft(); onUserInput(); }
  2039. function onNavigateRightClicked( event ) { event.preventDefault(); navigateRight(); onUserInput(); }
  2040. function onNavigateUpClicked( event ) { event.preventDefault(); navigateUp(); onUserInput(); }
  2041. function onNavigateDownClicked( event ) { event.preventDefault(); navigateDown(); onUserInput(); }
  2042. function onNavigatePrevClicked( event ) { event.preventDefault(); navigatePrev(); onUserInput(); }
  2043. function onNavigateNextClicked( event ) { event.preventDefault(); navigateNext(); onUserInput(); }
  2044. /**
  2045. * Handler for the window level 'hashchange' event.
  2046. */
  2047. function onWindowHashChange( event ) {
  2048. readURL();
  2049. }
  2050. /**
  2051. * Handler for the window level 'resize' event.
  2052. */
  2053. function onWindowResize( event ) {
  2054. layout();
  2055. }
  2056. /**
  2057. * Handle for the window level 'visibilitychange' event.
  2058. */
  2059. function onPageVisibilityChange( event ) {
  2060. var isHidden = document.webkitHidden ||
  2061. document.msHidden ||
  2062. document.hidden;
  2063. // If, after clicking a link or similar and we're coming back,
  2064. // focus the document.body to ensure we can use keyboard shortcuts
  2065. if( isHidden === false && document.activeElement !== document.body ) {
  2066. document.activeElement.blur();
  2067. document.body.focus();
  2068. }
  2069. }
  2070. /**
  2071. * Invoked when a slide is and we're in the overview.
  2072. */
  2073. function onOverviewSlideClicked( event ) {
  2074. // TODO There's a bug here where the event listeners are not
  2075. // removed after deactivating the overview.
  2076. if( eventsAreBound && isOverview() ) {
  2077. event.preventDefault();
  2078. var element = event.target;
  2079. while( element && !element.nodeName.match( /section/gi ) ) {
  2080. element = element.parentNode;
  2081. }
  2082. if( element && !element.classList.contains( 'disabled' ) ) {
  2083. deactivateOverview();
  2084. if( element.nodeName.match( /section/gi ) ) {
  2085. var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
  2086. v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
  2087. slide( h, v );
  2088. }
  2089. }
  2090. }
  2091. }
  2092. /**
  2093. * Handles clicks on links that are set to preview in the
  2094. * iframe overlay.
  2095. */
  2096. function onPreviewLinkClicked( event ) {
  2097. var url = event.target.getAttribute( 'href' );
  2098. if( url ) {
  2099. openPreview( url );
  2100. event.preventDefault();
  2101. }
  2102. }
  2103. // --------------------------------------------------------------------//
  2104. // ------------------------------- API --------------------------------//
  2105. // --------------------------------------------------------------------//
  2106. return {
  2107. initialize: initialize,
  2108. configure: configure,
  2109. sync: sync,
  2110. // Navigation methods
  2111. slide: slide,
  2112. left: navigateLeft,
  2113. right: navigateRight,
  2114. up: navigateUp,
  2115. down: navigateDown,
  2116. prev: navigatePrev,
  2117. next: navigateNext,
  2118. prevFragment: previousFragment,
  2119. nextFragment: nextFragment,
  2120. // Deprecated aliases
  2121. navigateTo: slide,
  2122. navigateLeft: navigateLeft,
  2123. navigateRight: navigateRight,
  2124. navigateUp: navigateUp,
  2125. navigateDown: navigateDown,
  2126. navigatePrev: navigatePrev,
  2127. navigateNext: navigateNext,
  2128. // Forces an update in slide layout
  2129. layout: layout,
  2130. // Returns an object with the available routes as booleans (left/right/top/bottom)
  2131. availableRoutes: availableRoutes,
  2132. // Returns an object with the available fragments as booleans (prev/next)
  2133. availableFragments: availableFragments,
  2134. // Toggles the overview mode on/off
  2135. toggleOverview: toggleOverview,
  2136. // Toggles the "black screen" mode on/off
  2137. togglePause: togglePause,
  2138. // State checks
  2139. isOverview: isOverview,
  2140. isPaused: isPaused,
  2141. // Adds or removes all internal event listeners (such as keyboard)
  2142. addEventListeners: addEventListeners,
  2143. removeEventListeners: removeEventListeners,
  2144. // Returns the indices of the current, or specified, slide
  2145. getIndices: getIndices,
  2146. // Returns the slide at the specified index, y is optional
  2147. getSlide: function( x, y ) {
  2148. var horizontalSlide = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
  2149. var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
  2150. if( typeof y !== 'undefined' ) {
  2151. return verticalSlides ? verticalSlides[ y ] : undefined;
  2152. }
  2153. return horizontalSlide;
  2154. },
  2155. // Returns the previous slide element, may be null
  2156. getPreviousSlide: function() {
  2157. return previousSlide;
  2158. },
  2159. // Returns the current slide element
  2160. getCurrentSlide: function() {
  2161. return currentSlide;
  2162. },
  2163. // Returns the current scale of the presentation content
  2164. getScale: function() {
  2165. return scale;
  2166. },
  2167. // Returns the current configuration object
  2168. getConfig: function() {
  2169. return config;
  2170. },
  2171. // Helper method, retrieves query string as a key/value hash
  2172. getQueryHash: function() {
  2173. var query = {};
  2174. location.search.replace( /[A-Z0-9]+?=(\w*)/gi, function(a) {
  2175. query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
  2176. } );
  2177. return query;
  2178. },
  2179. // Returns true if we're currently on the first slide
  2180. isFirstSlide: function() {
  2181. return document.querySelector( SLIDES_SELECTOR + '.past' ) == null ? true : false;
  2182. },
  2183. // Returns true if we're currently on the last slide
  2184. isLastSlide: function() {
  2185. if( currentSlide ) {
  2186. // Does this slide has next a sibling?
  2187. if( currentSlide.nextElementSibling ) return false;
  2188. // If it's vertical, does its parent have a next sibling?
  2189. if( isVerticalSlide( currentSlide ) && currentSlide.parentNode.nextElementSibling ) return false;
  2190. return true;
  2191. }
  2192. return false;
  2193. },
  2194. // Checks if reveal.js has been loaded and is ready for use
  2195. isReady: function() {
  2196. return loaded;
  2197. },
  2198. // Forward event binding to the reveal DOM element
  2199. addEventListener: function( type, listener, useCapture ) {
  2200. if( 'addEventListener' in window ) {
  2201. ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
  2202. }
  2203. },
  2204. removeEventListener: function( type, listener, useCapture ) {
  2205. if( 'addEventListener' in window ) {
  2206. ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
  2207. }
  2208. }
  2209. };
  2210. })();