reveal.js 78 KB

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