reveal.js 77 KB

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