reveal.js 77 KB

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