reveal.js 21 KB

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