reveal.js 116 KB

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