reveal.js 77 KB

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