reveal.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /*!
  2. * reveal.js 1.3
  3. * http://lab.hakim.se/reveal-js
  4. * MIT licensed
  5. *
  6. * Copyright (C) 2012 Hakim El Hattab, http://hakim.se
  7. */
  8. var Reveal = (function(){
  9. var HORIZONTAL_SLIDES_SELECTOR = '#reveal .slides>section',
  10. VERTICAL_SLIDES_SELECTOR = '#reveal .slides>section.present>section',
  11. // The horizontal and verical index of the currently active slide
  12. indexh = 0,
  13. indexv = 0,
  14. // Configurations options, can be overridden at initialization time
  15. config = {
  16. controls: false,
  17. progress: false,
  18. history: false,
  19. loop: false,
  20. mouseWheel: true,
  21. rollingLinks: true,
  22. transition: 'default',
  23. theme: 'default'
  24. },
  25. // Slides may hold a data-state attribute which we pick up and apply
  26. // as a class to the body. This list contains the combined state of
  27. // all current slides.
  28. state = [],
  29. // Cached references to DOM elements
  30. dom = {},
  31. // Detect support for CSS 3D transforms
  32. supports3DTransforms = document.body.style['perspectiveProperty'] !== undefined ||
  33. document.body.style['WebkitPerspective'] !== undefined ||
  34. document.body.style['MozPerspective'] !== undefined ||
  35. document.body.style['msPerspective'] !== undefined ||
  36. document.body.style['OPerspective'] !== undefined,
  37. supports2DTransforms = document.body.style['transformProperty'] !== undefined ||
  38. document.body.style['WebkitTransform'] !== undefined ||
  39. document.body.style['MozTransform'] !== undefined ||
  40. document.body.style['msTransform'] !== undefined ||
  41. document.body.style['OTransform'] !== undefined,
  42. // Throttles mouse wheel navigation
  43. mouseWheelTimeout = 0,
  44. // Delays updates to the URL due to a Chrome thumbnailer bug
  45. writeURLTimeout = 0;
  46. /**
  47. * Starts up the slideshow by applying configuration
  48. * options and binding various events.
  49. */
  50. function initialize( options ) {
  51. if( !supports2DTransforms && !supports3DTransforms ) {
  52. document.body.setAttribute( 'class', 'no-transforms' );
  53. // If the browser doesn't support transforms we won't be
  54. // using JavaScript to control the presentation
  55. return;
  56. }
  57. // Cache references to DOM elements
  58. dom.wrapper = document.querySelector( '#reveal' );
  59. dom.progress = document.querySelector( '#reveal .progress' );
  60. dom.progressbar = document.querySelector( '#reveal .progress span' );
  61. dom.controls = document.querySelector( '#reveal .controls' );
  62. dom.controlsLeft = document.querySelector( '#reveal .controls .left' );
  63. dom.controlsRight = document.querySelector( '#reveal .controls .right' );
  64. dom.controlsUp = document.querySelector( '#reveal .controls .up' );
  65. dom.controlsDown = document.querySelector( '#reveal .controls .down' );
  66. // Bind all view events
  67. document.addEventListener( 'keydown', onDocumentKeyDown, false );
  68. document.addEventListener( 'touchstart', onDocumentTouchStart, false );
  69. window.addEventListener( 'hashchange', onWindowHashChange, false );
  70. dom.controlsLeft.addEventListener( 'click', preventAndForward( navigateLeft ), false );
  71. dom.controlsRight.addEventListener( 'click', preventAndForward( navigateRight ), false );
  72. dom.controlsUp.addEventListener( 'click', preventAndForward( navigateUp ), false );
  73. dom.controlsDown.addEventListener( 'click', preventAndForward( navigateDown ), false );
  74. // Copy options over to our config object
  75. extend( config, options );
  76. // Fall back on the 2D transform theme 'linear'
  77. if( supports3DTransforms === false ) {
  78. config.transition = 'linear';
  79. }
  80. if( config.controls ) {
  81. dom.controls.style.display = 'block';
  82. }
  83. if( config.progress ) {
  84. dom.progress.style.display = 'block';
  85. }
  86. if( config.transition !== 'default' ) {
  87. dom.wrapper.classList.add( config.transition );
  88. }
  89. if( config.theme !== 'default' ) {
  90. dom.wrapper.classList.add( config.theme );
  91. }
  92. if( config.mouseWheel ) {
  93. document.addEventListener('DOMMouseScroll', onDocumentMouseScroll, false); // FF
  94. document.addEventListener('mousewheel', onDocumentMouseScroll, false);
  95. }
  96. if( config.rollingLinks ) {
  97. // Add some 3D magic to our anchors
  98. linkify();
  99. }
  100. // Read the initial hash
  101. readURL();
  102. }
  103. /**
  104. * Extend object a with the properties of object b.
  105. * If there's a conflict, object b takes precedence.
  106. */
  107. function extend( a, b ) {
  108. for( var i in b ) {
  109. a[ i ] = b[ i ];
  110. }
  111. }
  112. /**
  113. * Prevents an events defaults behavior calls the
  114. * specified delegate.
  115. *
  116. * @param {Function} delegate The method to call
  117. * after the wrapper has been executed
  118. */
  119. function preventAndForward( delegate ) {
  120. return function( event ) {
  121. event.preventDefault();
  122. delegate.call();
  123. }
  124. }
  125. /**
  126. * Handler for the document level 'keydown' event.
  127. *
  128. * @param {Object} event
  129. */
  130. function onDocumentKeyDown( event ) {
  131. // FFT: Use document.querySelector( ':focus' ) === null
  132. // instead of checking contentEditable?
  133. // Disregard the event if the target is editable or a
  134. // modifier is present
  135. if ( event.target.contentEditable != 'inherit' || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey ) return;
  136. var triggered = false;
  137. switch( event.keyCode ) {
  138. // p, page up
  139. case 80: case 33: navigatePrev(); triggered = true; break;
  140. // n, page down, space
  141. case 78: case 32: case 34: navigateNext(); triggered = true; break;
  142. // h, left
  143. case 72: case 37: navigateLeft(); triggered = true; break;
  144. // l, right
  145. case 76: case 39: navigateRight(); triggered = true; break;
  146. // k, up
  147. case 75: case 38: navigateUp(); triggered = true; break;
  148. // j, down
  149. case 74: case 40: navigateDown(); triggered = true; break;
  150. }
  151. if( triggered ) {
  152. event.preventDefault();
  153. }
  154. else if ( event.keyCode === 27 && supports3DTransforms ) {
  155. if( overviewIsActive() ) {
  156. deactivateOverview();
  157. }
  158. else {
  159. activateOverview();
  160. }
  161. event.preventDefault();
  162. }
  163. }
  164. /**
  165. * Handler for the document level 'touchstart' event.
  166. *
  167. * This enables very basic tap interaction for touch
  168. * devices. Added mainly for performance testing of 3D
  169. * transforms on iOS but was so happily surprised with
  170. * how smoothly it runs so I left it in here. Apple +1
  171. *
  172. * @param {Object} event
  173. */
  174. function onDocumentTouchStart( event ) {
  175. // We're only interested in one point taps
  176. if (event.touches.length === 1) {
  177. // Never prevent taps on anchors and images
  178. if( event.target.tagName.toLowerCase() === 'a' || event.target.tagName.toLowerCase() === 'img' ) {
  179. return;
  180. }
  181. event.preventDefault();
  182. var point = {
  183. x: event.touches[0].clientX,
  184. y: event.touches[0].clientY
  185. };
  186. // Define the extent of the areas that may be tapped
  187. // to navigate
  188. var wt = window.innerWidth * 0.3;
  189. var ht = window.innerHeight * 0.3;
  190. if( point.x < wt ) {
  191. navigateLeft();
  192. }
  193. else if( point.x > window.innerWidth - wt ) {
  194. navigateRight();
  195. }
  196. else if( point.y < ht ) {
  197. navigateUp();
  198. }
  199. else if( point.y > window.innerHeight - ht ) {
  200. navigateDown();
  201. }
  202. slide();
  203. }
  204. }
  205. /**
  206. * Handles mouse wheel scrolling, throttled to avoid
  207. * skipping multiple slides.
  208. */
  209. function onDocumentMouseScroll( event ){
  210. clearTimeout( mouseWheelTimeout );
  211. mouseWheelTimeout = setTimeout( function() {
  212. var delta = event.detail || -event.wheelDelta;
  213. if( delta > 0 ) {
  214. navigateNext();
  215. }
  216. else {
  217. navigatePrev();
  218. }
  219. }, 100 );
  220. }
  221. /**
  222. * Handler for the window level 'hashchange' event.
  223. *
  224. * @param {Object} event
  225. */
  226. function onWindowHashChange( event ) {
  227. readURL();
  228. }
  229. /**
  230. * Wrap all links in 3D goodness.
  231. */
  232. function linkify() {
  233. if( supports3DTransforms ) {
  234. var nodes = document.querySelectorAll( '#reveal .slides section a:not(.image)' );
  235. for( var i = 0, len = nodes.length; i < len; i++ ) {
  236. var node = nodes[i];
  237. if( node.textContent && !node.querySelector( 'img' ) && ( !node.className || !node.classList.contains( node, 'roll' ) ) ) {
  238. node.classList.add( 'roll' );
  239. node.innerHTML = '<span data-title="'+ node.text +'">' + node.innerHTML + '</span>';
  240. }
  241. };
  242. }
  243. }
  244. /**
  245. * Displays the overview of slides (quick nav) by
  246. * scaling down and arranging all slide elements.
  247. *
  248. * Experimental feature, might be dropped if perf
  249. * can't be improved.
  250. */
  251. function activateOverview() {
  252. dom.wrapper.classList.add( 'overview' );
  253. var horizontalSlides = Array.prototype.slice.call( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  254. for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
  255. var hslide = horizontalSlides[i],
  256. htransform = 'translateZ(-2500px) translate(' + ( ( i - indexh ) * 105 ) + '%, 0%)';
  257. hslide.setAttribute( 'data-index-h', i );
  258. hslide.style.display = 'block';
  259. hslide.style.WebkitTransform = htransform;
  260. hslide.style.MozTransform = htransform;
  261. hslide.style.msTransform = htransform;
  262. hslide.style.OTransform = htransform;
  263. hslide.style.transform = htransform;
  264. if( !hslide.classList.contains( 'stack' ) ) {
  265. // Navigate to this slide on click
  266. hslide.addEventListener( 'click', onOverviewSlideClicked, true );
  267. }
  268. var verticalSlides = Array.prototype.slice.call( hslide.querySelectorAll( 'section' ) );
  269. for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
  270. var vslide = verticalSlides[j],
  271. vtransform = 'translate(0%, ' + ( ( j - indexv ) * 105 ) + '%)';
  272. vslide.setAttribute( 'data-index-h', i );
  273. vslide.setAttribute( 'data-index-v', j );
  274. vslide.style.display = 'block';
  275. vslide.style.WebkitTransform = vtransform;
  276. vslide.style.MozTransform = vtransform;
  277. vslide.style.msTransform = vtransform;
  278. vslide.style.OTransform = vtransform;
  279. vslide.style.transform = vtransform;
  280. // Navigate to this slide on click
  281. vslide.addEventListener( 'click', onOverviewSlideClicked, true );
  282. }
  283. }
  284. }
  285. /**
  286. * Exits the slide overview and enters the currently
  287. * active slide.
  288. */
  289. function deactivateOverview() {
  290. dom.wrapper.classList.remove( 'overview' );
  291. var slides = Array.prototype.slice.call( document.querySelectorAll( '#reveal .slides section' ) );
  292. for( var i = 0, len = slides.length; i < len; i++ ) {
  293. var element = slides[i];
  294. // Resets all transforms to use the external styles
  295. element.style.WebkitTransform = '';
  296. element.style.MozTransform = '';
  297. element.style.msTransform = '';
  298. element.style.OTransform = '';
  299. element.style.transform = '';
  300. element.removeEventListener( 'click', onOverviewSlideClicked );
  301. }
  302. slide();
  303. }
  304. /**
  305. * Checks if the overview is currently active.
  306. *
  307. * @return {Boolean} true if the overview is active,
  308. * false otherwise
  309. */
  310. function overviewIsActive() {
  311. return dom.wrapper.classList.contains( 'overview' );
  312. }
  313. /**
  314. * Invoked when a slide is and we're in the overview.
  315. */
  316. function onOverviewSlideClicked( event ) {
  317. // TODO There's a bug here where the event listeners are not
  318. // removed after deactivating the overview.
  319. if( overviewIsActive() ) {
  320. event.preventDefault();
  321. deactivateOverview();
  322. indexh = this.getAttribute( 'data-index-h' );
  323. indexv = this.getAttribute( 'data-index-v' );
  324. slide();
  325. }
  326. }
  327. /**
  328. * Updates one dimension of slides by showing the slide
  329. * with the specified index.
  330. *
  331. * @param {String} selector A CSS selector that will fetch
  332. * the group of slides we are working with
  333. * @param {Number} index The index of the slide that should be
  334. * shown
  335. *
  336. * @return {Number} The index of the slide that is now shown,
  337. * might differ from the passed in index if it was out of
  338. * bounds.
  339. */
  340. function updateSlides( selector, index ) {
  341. // Select all slides and convert the NodeList result to
  342. // an array
  343. var slides = Array.prototype.slice.call( document.querySelectorAll( selector ) ),
  344. slidesLength = slides.length;
  345. if( slidesLength ) {
  346. // Should the index loop?
  347. if( config.loop ) {
  348. index %= slidesLength;
  349. if( index < 0 ) {
  350. index = slidesLength + index;
  351. }
  352. }
  353. // Enforce max and minimum index bounds
  354. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  355. for( var i = 0; i < slidesLength; i++ ) {
  356. var slide = slides[i];
  357. // Optimization; hide all slides that are three or more steps
  358. // away from the present slide
  359. if( overviewIsActive() === false ) {
  360. // The distance loops so that it measures 1 between the first
  361. // and last slides
  362. var distance = Math.abs( ( index - i ) % ( slidesLength - 3 ) ) || 0;
  363. slide.style.display = distance > 3 ? 'none' : 'block';
  364. }
  365. slides[i].classList.remove( 'past' );
  366. slides[i].classList.remove( 'present' );
  367. slides[i].classList.remove( 'future' );
  368. if( i < index ) {
  369. // Any element previous to index is given the 'past' class
  370. slides[i].classList.add( 'past' );
  371. }
  372. else if( i > index ) {
  373. // Any element subsequent to index is given the 'future' class
  374. slides[i].classList.add( 'future' );
  375. }
  376. // If this element contains vertical slides
  377. if( slide.querySelector( 'section' ) ) {
  378. slides[i].classList.add( 'stack' );
  379. }
  380. }
  381. // Mark the current slide as present
  382. slides[index].classList.add( 'present' );
  383. // If this slide has a state associated with it, add it
  384. // onto the current state of the deck
  385. var slideState = slides[index].getAttribute( 'data-state' );
  386. if( slideState ) {
  387. state = state.concat( slideState.split( ' ' ) );
  388. }
  389. }
  390. else {
  391. // Since there are no slides we can't be anywhere beyond the
  392. // zeroth index
  393. index = 0;
  394. }
  395. return index;
  396. }
  397. /**
  398. * Updates the visual slides to represent the currently
  399. * set indices.
  400. */
  401. function slide() {
  402. // Remember the state before this slide
  403. var stateBefore = state.concat();
  404. // Reset the state array
  405. state.length = 0;
  406. // Activate and transition to the new slide
  407. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, indexh );
  408. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, indexv );
  409. // Apply the new state
  410. stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
  411. // Check if this state existed on the previous slide. If it
  412. // did, we will avoid adding it repeatedly.
  413. for( var j = 0; j < stateBefore.length; j++ ) {
  414. if( stateBefore[j] === state[i] ) {
  415. stateBefore.splice( j, 1 );
  416. continue stateLoop;
  417. }
  418. }
  419. document.documentElement.classList.add( state[i] );
  420. // Dispatch custom event matching the state's name
  421. dispatchEvent( state[i] );
  422. }
  423. // Clean up the remaints of the previous state
  424. while( stateBefore.length ) {
  425. document.documentElement.classList.remove( stateBefore.pop() );
  426. }
  427. // Update progress if enabled
  428. if( config.progress ) {
  429. dom.progressbar.style.width = ( indexh / ( document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ).length - 1 ) ) * window.innerWidth + 'px';
  430. }
  431. // Close the overview if it's active
  432. if( overviewIsActive() ) {
  433. activateOverview();
  434. }
  435. updateControls();
  436. clearTimeout( writeURLTimeout );
  437. writeURLTimeout = setTimeout( writeURL, 1500 );
  438. // Dispatch an event notifying observers of the change in slide
  439. dispatchEvent( 'slidechanged', {
  440. 'indexh': indexh,
  441. 'indexv': indexv
  442. } );
  443. }
  444. /**
  445. * Updates the state and link pointers of the controls.
  446. */
  447. function updateControls() {
  448. var routes = availableRoutes();
  449. // Remove the 'enabled' class from all directions
  450. [ dom.controlsLeft, dom.controlsRight, dom.controlsUp, dom.controlsDown ].forEach( function( node ) {
  451. node.classList.remove( 'enabled' );
  452. } )
  453. if( routes.left ) dom.controlsLeft.classList.add( 'enabled' );
  454. if( routes.right ) dom.controlsRight.classList.add( 'enabled' );
  455. if( routes.up ) dom.controlsUp.classList.add( 'enabled' );
  456. if( routes.down ) dom.controlsDown.classList.add( 'enabled' );
  457. }
  458. /**
  459. * Determine what available routes there are for navigation.
  460. *
  461. * @return {Object} containing four booleans: left/right/up/down
  462. */
  463. function availableRoutes() {
  464. var horizontalSlides = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  465. var verticalSlides = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  466. return {
  467. left: indexh > 0,
  468. right: indexh < horizontalSlides.length - 1,
  469. up: indexv > 0,
  470. down: indexv < verticalSlides.length - 1
  471. };
  472. }
  473. /**
  474. * Reads the current URL (hash) and navigates accordingly.
  475. */
  476. function readURL() {
  477. // Break the hash down to separate components
  478. var bits = window.location.hash.slice(2).split('/');
  479. // Read the index components of the hash
  480. indexh = parseInt( bits[0] ) || 0 ;
  481. indexv = parseInt( bits[1] ) || 0 ;
  482. navigateTo( indexh, indexv );
  483. }
  484. /**
  485. * Updates the page URL (hash) to reflect the current
  486. * state.
  487. */
  488. function writeURL() {
  489. if( config.history ) {
  490. var url = '/';
  491. // Only include the minimum possible number of components in
  492. // the URL
  493. if( indexh > 0 || indexv > 0 ) url += indexh;
  494. if( indexv > 0 ) url += '/' + indexv;
  495. window.location.hash = url;
  496. }
  497. }
  498. /**
  499. * Dispatches an event of the specified type from the
  500. * #reveal DOM element.
  501. */
  502. function dispatchEvent( type, properties ) {
  503. var event = document.createEvent( "HTMLEvents", 1, 2 );
  504. event.initEvent( type, true, true );
  505. extend( event, properties );
  506. dom.wrapper.dispatchEvent( event );
  507. }
  508. /**
  509. * Navigate to the next slide fragment.
  510. *
  511. * @return {Boolean} true if there was a next fragment,
  512. * false otherwise
  513. */
  514. function nextFragment() {
  515. // Vertical slides:
  516. if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
  517. var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' );
  518. if( verticalFragments.length ) {
  519. verticalFragments[0].classList.add( 'visible' );
  520. return true;
  521. }
  522. }
  523. // Horizontal slides:
  524. else {
  525. var horizontalFragments = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment:not(.visible)' );
  526. if( horizontalFragments.length ) {
  527. horizontalFragments[0].classList.add( 'visible' );
  528. return true;
  529. }
  530. }
  531. return false;
  532. }
  533. /**
  534. * Navigate to the previous slide fragment.
  535. *
  536. * @return {Boolean} true if there was a previous fragment,
  537. * false otherwise
  538. */
  539. function previousFragment() {
  540. // Vertical slides:
  541. if( document.querySelector( VERTICAL_SLIDES_SELECTOR + '.present' ) ) {
  542. var verticalFragments = document.querySelectorAll( VERTICAL_SLIDES_SELECTOR + '.present .fragment.visible' );
  543. if( verticalFragments.length ) {
  544. verticalFragments[ verticalFragments.length - 1 ].classList.remove( 'visible' );
  545. return true;
  546. }
  547. }
  548. // Horizontal slides:
  549. else {
  550. var horizontalFragments = document.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.present .fragment.visible' );
  551. if( horizontalFragments.length ) {
  552. horizontalFragments[ horizontalFragments.length - 1 ].classList.remove( 'visible' );
  553. return true;
  554. }
  555. }
  556. return false;
  557. }
  558. /**
  559. * Triggers a navigation to the specified indices.
  560. *
  561. * @param {Number} h The horizontal index of the slide to show
  562. * @param {Number} v The vertical index of the slide to show
  563. */
  564. function navigateTo( h, v ) {
  565. indexh = h === undefined ? indexh : h;
  566. indexv = v === undefined ? indexv : v;
  567. slide();
  568. }
  569. function navigateLeft() {
  570. // Prioritize hiding fragments
  571. if( overviewIsActive() || previousFragment() === false ) {
  572. indexh --;
  573. indexv = 0;
  574. slide();
  575. }
  576. }
  577. function navigateRight() {
  578. // Prioritize revealing fragments
  579. if( overviewIsActive() || nextFragment() === false ) {
  580. indexh ++;
  581. indexv = 0;
  582. slide();
  583. }
  584. }
  585. function navigateUp() {
  586. // Prioritize hiding fragments
  587. if( overviewIsActive() || previousFragment() === false ) {
  588. indexv --;
  589. slide();
  590. }
  591. }
  592. function navigateDown() {
  593. // Prioritize revealing fragments
  594. if( overviewIsActive() || nextFragment() === false ) {
  595. indexv ++;
  596. slide();
  597. }
  598. }
  599. /**
  600. * Navigates backwards, prioritized in the following order:
  601. * 1) Previous fragment
  602. * 2) Previous vertical slide
  603. * 3) Previous horizontal slide
  604. */
  605. function navigatePrev() {
  606. // Prioritize revealing fragments
  607. if( previousFragment() === false ) {
  608. if( availableRoutes().up ) {
  609. navigateUp();
  610. }
  611. else {
  612. // Fetch the previous horizontal slide, if there is one
  613. var previousSlide = document.querySelector( '#reveal .slides>section.past:nth-child(' + indexh + ')' );
  614. if( previousSlide ) {
  615. indexv = ( previousSlide.querySelectorAll('section').length + 1 ) || 0;
  616. indexh --;
  617. slide();
  618. }
  619. }
  620. }
  621. }
  622. /**
  623. * Same as #navigatePrev() but navigates forwards.
  624. */
  625. function navigateNext() {
  626. // Prioritize revealing fragments
  627. if( nextFragment() === false ) {
  628. availableRoutes().down ? navigateDown() : navigateRight();
  629. }
  630. }
  631. // Expose some methods publicly
  632. return {
  633. initialize: initialize,
  634. navigateTo: navigateTo,
  635. navigateLeft: navigateLeft,
  636. navigateRight: navigateRight,
  637. navigateUp: navigateUp,
  638. navigateDown: navigateDown,
  639. // Forward event binding to the reveal DOM element
  640. addEventListener: function( type, listener, useCapture ) {
  641. ( dom.wrapper || document.querySelector( '#reveal' ) ).addEventListener( type, listener, useCapture );
  642. },
  643. removeEventListener: function( type, listener, useCapture ) {
  644. ( dom.wrapper || document.querySelector( '#reveal' ) ).removeEventListener( type, listener, useCapture );
  645. }
  646. };
  647. })();