reveal.js 95 KB

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