reveal.js 115 KB

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