reveal.js 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289
  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. // Flags if video background is loaded
  110. loadeddataVideo = false,
  111. // The horizontal and vertical index of the currently active slide
  112. indexh,
  113. indexv,
  114. // The previous and current slide HTML elements
  115. previousSlide,
  116. currentSlide,
  117. previousBackground,
  118. // Slides may hold a data-state attribute which we pick up and apply
  119. // as a class to the body. This list contains the combined state of
  120. // all current slides.
  121. state = [],
  122. // The current scale of the presentation (see width/height config)
  123. scale = 1,
  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.OTransform = transform;
  826. element.style.transform = transform;
  827. }
  828. /**
  829. * Injects the given CSS styles into the DOM.
  830. */
  831. function injectStyleSheet( value ) {
  832. var tag = document.createElement( 'style' );
  833. tag.type = 'text/css';
  834. if( tag.styleSheet ) {
  835. tag.styleSheet.cssText = value;
  836. }
  837. else {
  838. tag.appendChild( document.createTextNode( value ) );
  839. }
  840. document.getElementsByTagName( 'head' )[0].appendChild( tag );
  841. }
  842. /**
  843. * Measures the distance in pixels between point a and point b.
  844. *
  845. * @param {String} color The string representation of a color,
  846. * the following formats are supported:
  847. * - #000
  848. * - #000000
  849. * - rgb(0,0,0)
  850. */
  851. function colorToRgb( color ) {
  852. var hex3 = color.match( /^#([0-9a-f]{3})$/i );
  853. if( hex3 && hex3[1] ) {
  854. hex3 = hex3[1];
  855. return {
  856. r: parseInt( hex3.charAt( 0 ), 16 ) * 0x11,
  857. g: parseInt( hex3.charAt( 1 ), 16 ) * 0x11,
  858. b: parseInt( hex3.charAt( 2 ), 16 ) * 0x11
  859. };
  860. }
  861. var hex6 = color.match( /^#([0-9a-f]{6})$/i );
  862. if( hex6 && hex6[1] ) {
  863. hex6 = hex6[1];
  864. return {
  865. r: parseInt( hex6.substr( 0, 2 ), 16 ),
  866. g: parseInt( hex6.substr( 2, 2 ), 16 ),
  867. b: parseInt( hex6.substr( 4, 2 ), 16 )
  868. };
  869. }
  870. var rgb = color.match( /^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i );
  871. if( rgb ) {
  872. return {
  873. r: parseInt( rgb[1], 10 ),
  874. g: parseInt( rgb[2], 10 ),
  875. b: parseInt( rgb[3], 10 )
  876. };
  877. }
  878. var rgba = color.match( /^rgba\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\,\s*([\d]+|[\d]*.[\d]+)\s*\)$/i );
  879. if( rgba ) {
  880. return {
  881. r: parseInt( rgba[1], 10 ),
  882. g: parseInt( rgba[2], 10 ),
  883. b: parseInt( rgba[3], 10 ),
  884. a: parseFloat( rgba[4] )
  885. };
  886. }
  887. return null;
  888. }
  889. /**
  890. * Calculates brightness on a scale of 0-255.
  891. *
  892. * @param color See colorStringToRgb for supported formats.
  893. */
  894. function colorBrightness( color ) {
  895. if( typeof color === 'string' ) color = colorToRgb( color );
  896. if( color ) {
  897. return ( color.r * 299 + color.g * 587 + color.b * 114 ) / 1000;
  898. }
  899. return null;
  900. }
  901. /**
  902. * Retrieves the height of the given element by looking
  903. * at the position and height of its immediate children.
  904. */
  905. function getAbsoluteHeight( element ) {
  906. var height = 0;
  907. if( element ) {
  908. var absoluteChildren = 0;
  909. toArray( element.childNodes ).forEach( function( child ) {
  910. if( typeof child.offsetTop === 'number' && child.style ) {
  911. // Count # of abs children
  912. if( window.getComputedStyle( child ).position === 'absolute' ) {
  913. absoluteChildren += 1;
  914. }
  915. height = Math.max( height, child.offsetTop + child.offsetHeight );
  916. }
  917. } );
  918. // If there are no absolute children, use offsetHeight
  919. if( absoluteChildren === 0 ) {
  920. height = element.offsetHeight;
  921. }
  922. }
  923. return height;
  924. }
  925. /**
  926. * Returns the remaining height within the parent of the
  927. * target element.
  928. *
  929. * remaining height = [ configured parent height ] - [ current parent height ]
  930. */
  931. function getRemainingHeight( element, height ) {
  932. height = height || 0;
  933. if( element ) {
  934. var newHeight, oldHeight = element.style.height;
  935. // Change the .stretch element height to 0 in order find the height of all
  936. // the other elements
  937. element.style.height = '0px';
  938. newHeight = height - element.parentNode.offsetHeight;
  939. // Restore the old height, just in case
  940. element.style.height = oldHeight + 'px';
  941. return newHeight;
  942. }
  943. return height;
  944. }
  945. /**
  946. * Checks if this instance is being used to print a PDF.
  947. */
  948. function isPrintingPDF() {
  949. return ( /print-pdf/gi ).test( window.location.search );
  950. }
  951. /**
  952. * Hides the address bar if we're on a mobile device.
  953. */
  954. function hideAddressBar() {
  955. if( config.hideAddressBar && isMobileDevice ) {
  956. // Events that should trigger the address bar to hide
  957. window.addEventListener( 'load', removeAddressBar, false );
  958. window.addEventListener( 'orientationchange', removeAddressBar, false );
  959. }
  960. }
  961. /**
  962. * Causes the address bar to hide on mobile devices,
  963. * more vertical space ftw.
  964. */
  965. function removeAddressBar() {
  966. setTimeout( function() {
  967. window.scrollTo( 0, 1 );
  968. }, 10 );
  969. }
  970. /**
  971. * Dispatches an event of the specified type from the
  972. * reveal DOM element.
  973. */
  974. function dispatchEvent( type, args ) {
  975. var event = document.createEvent( 'HTMLEvents', 1, 2 );
  976. event.initEvent( type, true, true );
  977. extend( event, args );
  978. dom.wrapper.dispatchEvent( event );
  979. // If we're in an iframe, post each reveal.js event to the
  980. // parent window. Used by the notes plugin
  981. if( config.postMessageEvents && window.parent !== window.self ) {
  982. window.parent.postMessage( JSON.stringify({ namespace: 'reveal', eventName: type, state: getState() }), '*' );
  983. }
  984. }
  985. /**
  986. * Wrap all links in 3D goodness.
  987. */
  988. function enableRollingLinks() {
  989. if( features.transforms3d && !( 'msPerspective' in document.body.style ) ) {
  990. var anchors = dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ' a' );
  991. for( var i = 0, len = anchors.length; i < len; i++ ) {
  992. var anchor = anchors[i];
  993. if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
  994. var span = document.createElement('span');
  995. span.setAttribute('data-title', anchor.text);
  996. span.innerHTML = anchor.innerHTML;
  997. anchor.classList.add( 'roll' );
  998. anchor.innerHTML = '';
  999. anchor.appendChild(span);
  1000. }
  1001. }
  1002. }
  1003. }
  1004. /**
  1005. * Unwrap all 3D links.
  1006. */
  1007. function disableRollingLinks() {
  1008. var anchors = dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
  1009. for( var i = 0, len = anchors.length; i < len; i++ ) {
  1010. var anchor = anchors[i];
  1011. var span = anchor.querySelector( 'span' );
  1012. if( span ) {
  1013. anchor.classList.remove( 'roll' );
  1014. anchor.innerHTML = span.innerHTML;
  1015. }
  1016. }
  1017. }
  1018. /**
  1019. * Bind preview frame links.
  1020. */
  1021. function enablePreviewLinks( selector ) {
  1022. var anchors = toArray( document.querySelectorAll( selector ? selector : 'a' ) );
  1023. anchors.forEach( function( element ) {
  1024. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  1025. element.addEventListener( 'click', onPreviewLinkClicked, false );
  1026. }
  1027. } );
  1028. }
  1029. /**
  1030. * Unbind preview frame links.
  1031. */
  1032. function disablePreviewLinks() {
  1033. var anchors = toArray( document.querySelectorAll( 'a' ) );
  1034. anchors.forEach( function( element ) {
  1035. if( /^(http|www)/gi.test( element.getAttribute( 'href' ) ) ) {
  1036. element.removeEventListener( 'click', onPreviewLinkClicked, false );
  1037. }
  1038. } );
  1039. }
  1040. /**
  1041. * Opens a preview window for the target URL.
  1042. */
  1043. function showPreview( url ) {
  1044. closeOverlay();
  1045. dom.overlay = document.createElement( 'div' );
  1046. dom.overlay.classList.add( 'overlay' );
  1047. dom.overlay.classList.add( 'overlay-preview' );
  1048. dom.wrapper.appendChild( dom.overlay );
  1049. dom.overlay.innerHTML = [
  1050. '<header>',
  1051. '<a class="close" href="#"><span class="icon"></span></a>',
  1052. '<a class="external" href="'+ url +'" target="_blank"><span class="icon"></span></a>',
  1053. '</header>',
  1054. '<div class="spinner"></div>',
  1055. '<div class="viewport">',
  1056. '<iframe src="'+ url +'"></iframe>',
  1057. '</div>'
  1058. ].join('');
  1059. dom.overlay.querySelector( 'iframe' ).addEventListener( 'load', function( event ) {
  1060. dom.overlay.classList.add( 'loaded' );
  1061. }, false );
  1062. dom.overlay.querySelector( '.close' ).addEventListener( 'click', function( event ) {
  1063. closeOverlay();
  1064. event.preventDefault();
  1065. }, false );
  1066. dom.overlay.querySelector( '.external' ).addEventListener( 'click', function( event ) {
  1067. closeOverlay();
  1068. }, false );
  1069. setTimeout( function() {
  1070. dom.overlay.classList.add( 'visible' );
  1071. }, 1 );
  1072. }
  1073. /**
  1074. * Opens a overlay window with help material.
  1075. */
  1076. function showHelp() {
  1077. if( config.help ) {
  1078. closeOverlay();
  1079. dom.overlay = document.createElement( 'div' );
  1080. dom.overlay.classList.add( 'overlay' );
  1081. dom.overlay.classList.add( 'overlay-help' );
  1082. dom.wrapper.appendChild( dom.overlay );
  1083. var html = '<p class="title">Keyboard Shortcuts</p><br/>';
  1084. html += '<table><th>KEY</th><th>ACTION</th>';
  1085. for( var key in keyboardShortcuts ) {
  1086. html += '<tr><td>' + key + '</td><td>' + keyboardShortcuts[ key ] + '</td></tr>';
  1087. }
  1088. html += '</table>';
  1089. dom.overlay.innerHTML = [
  1090. '<header>',
  1091. '<a class="close" href="#"><span class="icon"></span></a>',
  1092. '</header>',
  1093. '<div class="viewport">',
  1094. '<div class="viewport-inner">'+ html +'</div>',
  1095. '</div>'
  1096. ].join('');
  1097. dom.overlay.querySelector( '.close' ).addEventListener( 'click', function( event ) {
  1098. closeOverlay();
  1099. event.preventDefault();
  1100. }, false );
  1101. setTimeout( function() {
  1102. dom.overlay.classList.add( 'visible' );
  1103. }, 1 );
  1104. }
  1105. }
  1106. /**
  1107. * Closes any currently open overlay.
  1108. */
  1109. function closeOverlay() {
  1110. if( dom.overlay ) {
  1111. dom.overlay.parentNode.removeChild( dom.overlay );
  1112. dom.overlay = null;
  1113. }
  1114. }
  1115. /**
  1116. * Applies JavaScript-controlled layout rules to the
  1117. * presentation.
  1118. */
  1119. function layout() {
  1120. if( dom.wrapper && !isPrintingPDF() ) {
  1121. var size = getComputedSlideSize();
  1122. var slidePadding = 20; // TODO Dig this out of DOM
  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, '' );
  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. }
  1146. // Apply scale transform as a fallback
  1147. else {
  1148. dom.slides.style.left = '50%';
  1149. dom.slides.style.top = '50%';
  1150. dom.slides.style.bottom = 'auto';
  1151. dom.slides.style.right = 'auto';
  1152. transformElement( dom.slides, 'translate(-50%, -50%) scale('+ scale +')' );
  1153. }
  1154. }
  1155. // Select all slides, vertical and horizontal
  1156. var slides = toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) );
  1157. for( var i = 0, len = slides.length; i < len; i++ ) {
  1158. var slide = slides[ i ];
  1159. // Don't bother updating invisible slides
  1160. if( slide.style.display === 'none' ) {
  1161. continue;
  1162. }
  1163. if( config.center || slide.classList.contains( 'center' ) ) {
  1164. // Vertical stacks are not centred since their section
  1165. // children will be
  1166. if( slide.classList.contains( 'stack' ) ) {
  1167. slide.style.top = 0;
  1168. }
  1169. else {
  1170. slide.style.top = Math.max( ( ( size.height - getAbsoluteHeight( slide ) ) / 2 ) - slidePadding, 0 ) + 'px';
  1171. }
  1172. }
  1173. else {
  1174. slide.style.top = '';
  1175. }
  1176. }
  1177. updateProgress();
  1178. updateParallax();
  1179. }
  1180. }
  1181. /**
  1182. * Applies layout logic to the contents of all slides in
  1183. * the presentation.
  1184. */
  1185. function layoutSlideContents( width, height, padding ) {
  1186. // Handle sizing of elements with the 'stretch' class
  1187. toArray( dom.slides.querySelectorAll( 'section > .stretch' ) ).forEach( function( element ) {
  1188. // Determine how much vertical space we can use
  1189. var remainingHeight = getRemainingHeight( element, height );
  1190. // Consider the aspect ratio of media elements
  1191. if( /(img|video)/gi.test( element.nodeName ) ) {
  1192. var nw = element.naturalWidth || element.videoWidth,
  1193. nh = element.naturalHeight || element.videoHeight;
  1194. var es = Math.min( width / nw, remainingHeight / nh );
  1195. element.style.width = ( nw * es ) + 'px';
  1196. element.style.height = ( nh * es ) + 'px';
  1197. }
  1198. else {
  1199. element.style.width = width + 'px';
  1200. element.style.height = remainingHeight + 'px';
  1201. }
  1202. } );
  1203. }
  1204. /**
  1205. * Calculates the computed pixel size of our slides. These
  1206. * values are based on the width and height configuration
  1207. * options.
  1208. */
  1209. function getComputedSlideSize( presentationWidth, presentationHeight ) {
  1210. var size = {
  1211. // Slide size
  1212. width: config.width,
  1213. height: config.height,
  1214. // Presentation size
  1215. presentationWidth: presentationWidth || dom.wrapper.offsetWidth,
  1216. presentationHeight: presentationHeight || dom.wrapper.offsetHeight
  1217. };
  1218. // Reduce available space by margin
  1219. size.presentationWidth -= ( size.presentationHeight * config.margin );
  1220. size.presentationHeight -= ( size.presentationHeight * config.margin );
  1221. // Slide width may be a percentage of available width
  1222. if( typeof size.width === 'string' && /%$/.test( size.width ) ) {
  1223. size.width = parseInt( size.width, 10 ) / 100 * size.presentationWidth;
  1224. }
  1225. // Slide height may be a percentage of available height
  1226. if( typeof size.height === 'string' && /%$/.test( size.height ) ) {
  1227. size.height = parseInt( size.height, 10 ) / 100 * size.presentationHeight;
  1228. }
  1229. return size;
  1230. }
  1231. /**
  1232. * Stores the vertical index of a stack so that the same
  1233. * vertical slide can be selected when navigating to and
  1234. * from the stack.
  1235. *
  1236. * @param {HTMLElement} stack The vertical stack element
  1237. * @param {int} v Index to memorize
  1238. */
  1239. function setPreviousVerticalIndex( stack, v ) {
  1240. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' ) {
  1241. stack.setAttribute( 'data-previous-indexv', v || 0 );
  1242. }
  1243. }
  1244. /**
  1245. * Retrieves the vertical index which was stored using
  1246. * #setPreviousVerticalIndex() or 0 if no previous index
  1247. * exists.
  1248. *
  1249. * @param {HTMLElement} stack The vertical stack element
  1250. */
  1251. function getPreviousVerticalIndex( stack ) {
  1252. if( typeof stack === 'object' && typeof stack.setAttribute === 'function' && stack.classList.contains( 'stack' ) ) {
  1253. // Prefer manually defined start-indexv
  1254. var attributeName = stack.hasAttribute( 'data-start-indexv' ) ? 'data-start-indexv' : 'data-previous-indexv';
  1255. return parseInt( stack.getAttribute( attributeName ) || 0, 10 );
  1256. }
  1257. return 0;
  1258. }
  1259. /**
  1260. * Displays the overview of slides (quick nav) by
  1261. * scaling down and arranging all slide elements.
  1262. *
  1263. * Experimental feature, might be dropped if perf
  1264. * can't be improved.
  1265. */
  1266. function activateOverview() {
  1267. // Only proceed if enabled in config
  1268. if( config.overview ) {
  1269. // Don't auto-slide while in overview mode
  1270. cancelAutoSlide();
  1271. var wasActive = dom.wrapper.classList.contains( 'overview' );
  1272. // Vary the depth of the overview based on screen size
  1273. var depth = window.innerWidth < 400 ? 1000 : 2500;
  1274. dom.wrapper.classList.add( 'overview' );
  1275. dom.wrapper.classList.remove( 'overview-deactivating' );
  1276. var horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  1277. for( var i = 0, len1 = horizontalSlides.length; i < len1; i++ ) {
  1278. var hslide = horizontalSlides[i],
  1279. hoffset = config.rtl ? -105 : 105;
  1280. hslide.setAttribute( 'data-index-h', i );
  1281. // Apply CSS transform
  1282. transformElement( hslide, 'translateZ(-'+ depth +'px) translate(' + ( ( i - indexh ) * hoffset ) + '%, 0%)' );
  1283. if( hslide.classList.contains( 'stack' ) ) {
  1284. var verticalSlides = hslide.querySelectorAll( 'section' );
  1285. for( var j = 0, len2 = verticalSlides.length; j < len2; j++ ) {
  1286. var verticalIndex = i === indexh ? indexv : getPreviousVerticalIndex( hslide );
  1287. var vslide = verticalSlides[j];
  1288. vslide.setAttribute( 'data-index-h', i );
  1289. vslide.setAttribute( 'data-index-v', j );
  1290. // Apply CSS transform
  1291. transformElement( vslide, 'translate(0%, ' + ( ( j - verticalIndex ) * 105 ) + '%)' );
  1292. // Navigate to this slide on click
  1293. vslide.addEventListener( 'click', onOverviewSlideClicked, true );
  1294. }
  1295. }
  1296. else {
  1297. // Navigate to this slide on click
  1298. hslide.addEventListener( 'click', onOverviewSlideClicked, true );
  1299. }
  1300. }
  1301. updateSlidesVisibility();
  1302. layout();
  1303. if( !wasActive ) {
  1304. // Notify observers of the overview showing
  1305. dispatchEvent( 'overviewshown', {
  1306. 'indexh': indexh,
  1307. 'indexv': indexv,
  1308. 'currentSlide': currentSlide
  1309. } );
  1310. }
  1311. }
  1312. }
  1313. /**
  1314. * Exits the slide overview and enters the currently
  1315. * active slide.
  1316. */
  1317. function deactivateOverview() {
  1318. // Only proceed if enabled in config
  1319. if( config.overview ) {
  1320. dom.wrapper.classList.remove( 'overview' );
  1321. // Temporarily add a class so that transitions can do different things
  1322. // depending on whether they are exiting/entering overview, or just
  1323. // moving from slide to slide
  1324. dom.wrapper.classList.add( 'overview-deactivating' );
  1325. setTimeout( function () {
  1326. dom.wrapper.classList.remove( 'overview-deactivating' );
  1327. }, 1 );
  1328. // Select all slides
  1329. toArray( dom.wrapper.querySelectorAll( SLIDES_SELECTOR ) ).forEach( function( slide ) {
  1330. // Resets all transforms to use the external styles
  1331. transformElement( slide, '' );
  1332. slide.removeEventListener( 'click', onOverviewSlideClicked, true );
  1333. } );
  1334. slide( indexh, indexv );
  1335. cueAutoSlide();
  1336. // Notify observers of the overview hiding
  1337. dispatchEvent( 'overviewhidden', {
  1338. 'indexh': indexh,
  1339. 'indexv': indexv,
  1340. 'currentSlide': currentSlide
  1341. } );
  1342. }
  1343. }
  1344. /**
  1345. * Toggles the slide overview mode on and off.
  1346. *
  1347. * @param {Boolean} override Optional flag which overrides the
  1348. * toggle logic and forcibly sets the desired state. True means
  1349. * overview is open, false means it's closed.
  1350. */
  1351. function toggleOverview( override ) {
  1352. if( typeof override === 'boolean' ) {
  1353. override ? activateOverview() : deactivateOverview();
  1354. }
  1355. else {
  1356. isOverview() ? deactivateOverview() : activateOverview();
  1357. }
  1358. }
  1359. /**
  1360. * Checks if the overview is currently active.
  1361. *
  1362. * @return {Boolean} true if the overview is active,
  1363. * false otherwise
  1364. */
  1365. function isOverview() {
  1366. return dom.wrapper.classList.contains( 'overview' );
  1367. }
  1368. /**
  1369. * Checks if the current or specified slide is vertical
  1370. * (nested within another slide).
  1371. *
  1372. * @param {HTMLElement} slide [optional] The slide to check
  1373. * orientation of
  1374. */
  1375. function isVerticalSlide( slide ) {
  1376. // Prefer slide argument, otherwise use current slide
  1377. slide = slide ? slide : currentSlide;
  1378. return slide && slide.parentNode && !!slide.parentNode.nodeName.match( /section/i );
  1379. }
  1380. /**
  1381. * Handling the fullscreen functionality via the fullscreen API
  1382. *
  1383. * @see http://fullscreen.spec.whatwg.org/
  1384. * @see https://developer.mozilla.org/en-US/docs/DOM/Using_fullscreen_mode
  1385. */
  1386. function enterFullscreen() {
  1387. var element = document.body;
  1388. // Check which implementation is available
  1389. var requestMethod = element.requestFullScreen ||
  1390. element.webkitRequestFullscreen ||
  1391. element.webkitRequestFullScreen ||
  1392. element.mozRequestFullScreen ||
  1393. element.msRequestFullscreen;
  1394. if( requestMethod ) {
  1395. requestMethod.apply( element );
  1396. }
  1397. }
  1398. /**
  1399. * Enters the paused mode which fades everything on screen to
  1400. * black.
  1401. */
  1402. function pause() {
  1403. if( config.pause ) {
  1404. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1405. cancelAutoSlide();
  1406. dom.wrapper.classList.add( 'paused' );
  1407. if( wasPaused === false ) {
  1408. dispatchEvent( 'paused' );
  1409. }
  1410. }
  1411. }
  1412. /**
  1413. * Exits from the paused mode.
  1414. */
  1415. function resume() {
  1416. var wasPaused = dom.wrapper.classList.contains( 'paused' );
  1417. dom.wrapper.classList.remove( 'paused' );
  1418. cueAutoSlide();
  1419. if( wasPaused ) {
  1420. dispatchEvent( 'resumed' );
  1421. }
  1422. }
  1423. /**
  1424. * Toggles the paused mode on and off.
  1425. */
  1426. function togglePause( override ) {
  1427. if( typeof override === 'boolean' ) {
  1428. override ? pause() : resume();
  1429. }
  1430. else {
  1431. isPaused() ? resume() : pause();
  1432. }
  1433. }
  1434. /**
  1435. * Checks if we are currently in the paused mode.
  1436. */
  1437. function isPaused() {
  1438. return dom.wrapper.classList.contains( 'paused' );
  1439. }
  1440. /**
  1441. * Toggles the auto slide mode on and off.
  1442. *
  1443. * @param {Boolean} override Optional flag which sets the desired state.
  1444. * True means autoplay starts, false means it stops.
  1445. */
  1446. function toggleAutoSlide( override ) {
  1447. if( typeof override === 'boolean' ) {
  1448. override ? resumeAutoSlide() : pauseAutoSlide();
  1449. }
  1450. else {
  1451. autoSlidePaused ? resumeAutoSlide() : pauseAutoSlide();
  1452. }
  1453. }
  1454. /**
  1455. * Checks if the auto slide mode is currently on.
  1456. */
  1457. function isAutoSliding() {
  1458. return !!( autoSlide && !autoSlidePaused );
  1459. }
  1460. /**
  1461. * Steps from the current point in the presentation to the
  1462. * slide which matches the specified horizontal and vertical
  1463. * indices.
  1464. *
  1465. * @param {int} h Horizontal index of the target slide
  1466. * @param {int} v Vertical index of the target slide
  1467. * @param {int} f Optional index of a fragment within the
  1468. * target slide to activate
  1469. * @param {int} o Optional origin for use in multimaster environments
  1470. */
  1471. function slide( h, v, f, o ) {
  1472. // Remember where we were at before
  1473. previousSlide = currentSlide;
  1474. // Query all horizontal slides in the deck
  1475. var horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR );
  1476. // If no vertical index is specified and the upcoming slide is a
  1477. // stack, resume at its previous vertical index
  1478. if( v === undefined ) {
  1479. v = getPreviousVerticalIndex( horizontalSlides[ h ] );
  1480. }
  1481. // If we were on a vertical stack, remember what vertical index
  1482. // it was on so we can resume at the same position when returning
  1483. if( previousSlide && previousSlide.parentNode && previousSlide.parentNode.classList.contains( 'stack' ) ) {
  1484. setPreviousVerticalIndex( previousSlide.parentNode, indexv );
  1485. }
  1486. // Remember the state before this slide
  1487. var stateBefore = state.concat();
  1488. // Reset the state array
  1489. state.length = 0;
  1490. var indexhBefore = indexh || 0,
  1491. indexvBefore = indexv || 0;
  1492. // Activate and transition to the new slide
  1493. indexh = updateSlides( HORIZONTAL_SLIDES_SELECTOR, h === undefined ? indexh : h );
  1494. indexv = updateSlides( VERTICAL_SLIDES_SELECTOR, v === undefined ? indexv : v );
  1495. // Update the visibility of slides now that the indices have changed
  1496. updateSlidesVisibility();
  1497. layout();
  1498. // Apply the new state
  1499. stateLoop: for( var i = 0, len = state.length; i < len; i++ ) {
  1500. // Check if this state existed on the previous slide. If it
  1501. // did, we will avoid adding it repeatedly
  1502. for( var j = 0; j < stateBefore.length; j++ ) {
  1503. if( stateBefore[j] === state[i] ) {
  1504. stateBefore.splice( j, 1 );
  1505. continue stateLoop;
  1506. }
  1507. }
  1508. document.documentElement.classList.add( state[i] );
  1509. // Dispatch custom event matching the state's name
  1510. dispatchEvent( state[i] );
  1511. }
  1512. // Clean up the remains of the previous state
  1513. while( stateBefore.length ) {
  1514. document.documentElement.classList.remove( stateBefore.pop() );
  1515. }
  1516. // If the overview is active, re-activate it to update positions
  1517. if( isOverview() ) {
  1518. activateOverview();
  1519. }
  1520. // Find the current horizontal slide and any possible vertical slides
  1521. // within it
  1522. var currentHorizontalSlide = horizontalSlides[ indexh ],
  1523. currentVerticalSlides = currentHorizontalSlide.querySelectorAll( 'section' );
  1524. // Store references to the previous and current slides
  1525. currentSlide = currentVerticalSlides[ indexv ] || currentHorizontalSlide;
  1526. // Show fragment, if specified
  1527. if( typeof f !== 'undefined' ) {
  1528. navigateFragment( f );
  1529. }
  1530. // Dispatch an event if the slide changed
  1531. var slideChanged = ( indexh !== indexhBefore || indexv !== indexvBefore );
  1532. if( slideChanged ) {
  1533. dispatchEvent( 'slidechanged', {
  1534. 'indexh': indexh,
  1535. 'indexv': indexv,
  1536. 'previousSlide': previousSlide,
  1537. 'currentSlide': currentSlide,
  1538. 'origin': o
  1539. } );
  1540. }
  1541. else {
  1542. // Ensure that the previous slide is never the same as the current
  1543. previousSlide = null;
  1544. }
  1545. // Solves an edge case where the previous slide maintains the
  1546. // 'present' class when navigating between adjacent vertical
  1547. // stacks
  1548. if( previousSlide ) {
  1549. previousSlide.classList.remove( 'present' );
  1550. previousSlide.setAttribute( 'aria-hidden', 'true' );
  1551. // Reset all slides upon navigate to home
  1552. // Issue: #285
  1553. if ( dom.wrapper.querySelector( HOME_SLIDE_SELECTOR ).classList.contains( 'present' ) ) {
  1554. // Launch async task
  1555. setTimeout( function () {
  1556. var slides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.stack') ), i;
  1557. for( i in slides ) {
  1558. if( slides[i] ) {
  1559. // Reset stack
  1560. setPreviousVerticalIndex( slides[i], 0 );
  1561. }
  1562. }
  1563. }, 0 );
  1564. }
  1565. }
  1566. // Handle embedded content
  1567. if( slideChanged || !previousSlide ) {
  1568. stopEmbeddedContent( previousSlide );
  1569. startEmbeddedContent( currentSlide );
  1570. }
  1571. // Announce the current slide contents, for screen readers
  1572. dom.statusDiv.textContent = currentSlide.textContent;
  1573. updateControls();
  1574. updateProgress();
  1575. updateBackground();
  1576. updateParallax();
  1577. updateSlideNumber();
  1578. // Update the URL hash
  1579. writeURL();
  1580. cueAutoSlide();
  1581. }
  1582. /**
  1583. * Syncs the presentation with the current DOM. Useful
  1584. * when new slides or control elements are added or when
  1585. * the configuration has changed.
  1586. */
  1587. function sync() {
  1588. // Subscribe to input
  1589. removeEventListeners();
  1590. addEventListeners();
  1591. // Force a layout to make sure the current config is accounted for
  1592. layout();
  1593. // Reflect the current autoSlide value
  1594. autoSlide = config.autoSlide;
  1595. // Start auto-sliding if it's enabled
  1596. cueAutoSlide();
  1597. // Re-create the slide backgrounds
  1598. createBackgrounds();
  1599. // Write the current hash to the URL
  1600. writeURL();
  1601. sortAllFragments();
  1602. updateControls();
  1603. updateProgress();
  1604. updateBackground( true );
  1605. updateSlideNumber();
  1606. updateSlidesVisibility();
  1607. formatEmbeddedContent();
  1608. }
  1609. /**
  1610. * Resets all vertical slides so that only the first
  1611. * is visible.
  1612. */
  1613. function resetVerticalSlides() {
  1614. var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1615. horizontalSlides.forEach( function( horizontalSlide ) {
  1616. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1617. verticalSlides.forEach( function( verticalSlide, y ) {
  1618. if( y > 0 ) {
  1619. verticalSlide.classList.remove( 'present' );
  1620. verticalSlide.classList.remove( 'past' );
  1621. verticalSlide.classList.add( 'future' );
  1622. verticalSlide.setAttribute( 'aria-hidden', 'true' );
  1623. }
  1624. } );
  1625. } );
  1626. }
  1627. /**
  1628. * Sorts and formats all of fragments in the
  1629. * presentation.
  1630. */
  1631. function sortAllFragments() {
  1632. var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  1633. horizontalSlides.forEach( function( horizontalSlide ) {
  1634. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  1635. verticalSlides.forEach( function( verticalSlide, y ) {
  1636. sortFragments( verticalSlide.querySelectorAll( '.fragment' ) );
  1637. } );
  1638. if( verticalSlides.length === 0 ) sortFragments( horizontalSlide.querySelectorAll( '.fragment' ) );
  1639. } );
  1640. }
  1641. /**
  1642. * Updates one dimension of slides by showing the slide
  1643. * with the specified index.
  1644. *
  1645. * @param {String} selector A CSS selector that will fetch
  1646. * the group of slides we are working with
  1647. * @param {Number} index The index of the slide that should be
  1648. * shown
  1649. *
  1650. * @return {Number} The index of the slide that is now shown,
  1651. * might differ from the passed in index if it was out of
  1652. * bounds.
  1653. */
  1654. function updateSlides( selector, index ) {
  1655. // Select all slides and convert the NodeList result to
  1656. // an array
  1657. var slides = toArray( dom.wrapper.querySelectorAll( selector ) ),
  1658. slidesLength = slides.length;
  1659. var printMode = isPrintingPDF();
  1660. if( slidesLength ) {
  1661. // Should the index loop?
  1662. if( config.loop ) {
  1663. index %= slidesLength;
  1664. if( index < 0 ) {
  1665. index = slidesLength + index;
  1666. }
  1667. }
  1668. // Enforce max and minimum index bounds
  1669. index = Math.max( Math.min( index, slidesLength - 1 ), 0 );
  1670. for( var i = 0; i < slidesLength; i++ ) {
  1671. var element = slides[i];
  1672. var reverse = config.rtl && !isVerticalSlide( element );
  1673. element.classList.remove( 'past' );
  1674. element.classList.remove( 'present' );
  1675. element.classList.remove( 'future' );
  1676. // http://www.w3.org/html/wg/drafts/html/master/editing.html#the-hidden-attribute
  1677. element.setAttribute( 'hidden', '' );
  1678. element.setAttribute( 'aria-hidden', 'true' );
  1679. // If this element contains vertical slides
  1680. if( element.querySelector( 'section' ) ) {
  1681. element.classList.add( 'stack' );
  1682. }
  1683. // If we're printing static slides, all slides are "present"
  1684. if( printMode ) {
  1685. element.classList.add( 'present' );
  1686. continue;
  1687. }
  1688. if( i < index ) {
  1689. // Any element previous to index is given the 'past' class
  1690. element.classList.add( reverse ? 'future' : 'past' );
  1691. if( config.fragments ) {
  1692. var pastFragments = toArray( element.querySelectorAll( '.fragment' ) );
  1693. // Show all fragments on prior slides
  1694. while( pastFragments.length ) {
  1695. var pastFragment = pastFragments.pop();
  1696. pastFragment.classList.add( 'visible' );
  1697. pastFragment.classList.remove( 'current-fragment' );
  1698. }
  1699. }
  1700. }
  1701. else if( i > index ) {
  1702. // Any element subsequent to index is given the 'future' class
  1703. element.classList.add( reverse ? 'past' : 'future' );
  1704. if( config.fragments ) {
  1705. var futureFragments = toArray( element.querySelectorAll( '.fragment.visible' ) );
  1706. // No fragments in future slides should be visible ahead of time
  1707. while( futureFragments.length ) {
  1708. var futureFragment = futureFragments.pop();
  1709. futureFragment.classList.remove( 'visible' );
  1710. futureFragment.classList.remove( 'current-fragment' );
  1711. }
  1712. }
  1713. }
  1714. }
  1715. // Mark the current slide as present
  1716. slides[index].classList.add( 'present' );
  1717. slides[index].removeAttribute( 'hidden' );
  1718. slides[index].removeAttribute( 'aria-hidden' );
  1719. // If this slide has a state associated with it, add it
  1720. // onto the current state of the deck
  1721. var slideState = slides[index].getAttribute( 'data-state' );
  1722. if( slideState ) {
  1723. state = state.concat( slideState.split( ' ' ) );
  1724. }
  1725. }
  1726. else {
  1727. // Since there are no slides we can't be anywhere beyond the
  1728. // zeroth index
  1729. index = 0;
  1730. }
  1731. return index;
  1732. }
  1733. /**
  1734. * Optimization method; hide all slides that are far away
  1735. * from the present slide.
  1736. */
  1737. function updateSlidesVisibility() {
  1738. // Select all slides and convert the NodeList result to
  1739. // an array
  1740. var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ),
  1741. horizontalSlidesLength = horizontalSlides.length,
  1742. distanceX,
  1743. distanceY;
  1744. if( horizontalSlidesLength && typeof indexh !== 'undefined' ) {
  1745. // The number of steps away from the present slide that will
  1746. // be visible
  1747. var viewDistance = isOverview() ? 10 : config.viewDistance;
  1748. // Limit view distance on weaker devices
  1749. if( isMobileDevice ) {
  1750. viewDistance = isOverview() ? 6 : 2;
  1751. }
  1752. // Limit view distance on weaker devices
  1753. if( isPrintingPDF() ) {
  1754. viewDistance = Number.MAX_VALUE;
  1755. }
  1756. for( var x = 0; x < horizontalSlidesLength; x++ ) {
  1757. var horizontalSlide = horizontalSlides[x];
  1758. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) ),
  1759. verticalSlidesLength = verticalSlides.length;
  1760. // Loops so that it measures 1 between the first and last slides
  1761. distanceX = Math.abs( ( ( indexh || 0 ) - x ) % ( horizontalSlidesLength - viewDistance ) ) || 0;
  1762. // Show the horizontal slide if it's within the view distance
  1763. if( distanceX < viewDistance ) {
  1764. showSlide( horizontalSlide );
  1765. }
  1766. else {
  1767. hideSlide( horizontalSlide );
  1768. }
  1769. if( verticalSlidesLength ) {
  1770. var oy = getPreviousVerticalIndex( horizontalSlide );
  1771. for( var y = 0; y < verticalSlidesLength; y++ ) {
  1772. var verticalSlide = verticalSlides[y];
  1773. distanceY = x === ( indexh || 0 ) ? Math.abs( ( indexv || 0 ) - y ) : Math.abs( y - oy );
  1774. if( distanceX + distanceY < viewDistance ) {
  1775. showSlide( verticalSlide );
  1776. }
  1777. else {
  1778. hideSlide( verticalSlide );
  1779. }
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. /**
  1786. * Updates the progress bar to reflect the current slide.
  1787. */
  1788. function updateProgress() {
  1789. // Update progress if enabled
  1790. if( config.progress && dom.progressbar ) {
  1791. dom.progressbar.style.width = getProgress() * dom.wrapper.offsetWidth + 'px';
  1792. }
  1793. }
  1794. /**
  1795. * Updates the slide number div to reflect the current slide.
  1796. */
  1797. function updateSlideNumber() {
  1798. // Update slide number if enabled
  1799. if( config.slideNumber && dom.slideNumber) {
  1800. // Display the number of the page using 'indexh - indexv' format
  1801. var indexString = indexh;
  1802. if( indexv > 0 ) {
  1803. indexString += ' - ' + indexv;
  1804. }
  1805. dom.slideNumber.innerHTML = indexString;
  1806. }
  1807. }
  1808. /**
  1809. * Updates the state of all control/navigation arrows.
  1810. */
  1811. function updateControls() {
  1812. var routes = availableRoutes();
  1813. var fragments = availableFragments();
  1814. // Remove the 'enabled' class from all directions
  1815. dom.controlsLeft.concat( dom.controlsRight )
  1816. .concat( dom.controlsUp )
  1817. .concat( dom.controlsDown )
  1818. .concat( dom.controlsPrev )
  1819. .concat( dom.controlsNext ).forEach( function( node ) {
  1820. node.classList.remove( 'enabled' );
  1821. node.classList.remove( 'fragmented' );
  1822. } );
  1823. // Add the 'enabled' class to the available routes
  1824. if( routes.left ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1825. if( routes.right ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1826. if( routes.up ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1827. if( routes.down ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1828. // Prev/next buttons
  1829. if( routes.left || routes.up ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1830. if( routes.right || routes.down ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'enabled' ); } );
  1831. // Highlight fragment directions
  1832. if( currentSlide ) {
  1833. // Always apply fragment decorator to prev/next buttons
  1834. if( fragments.prev ) dom.controlsPrev.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1835. if( fragments.next ) dom.controlsNext.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1836. // Apply fragment decorators to directional buttons based on
  1837. // what slide axis they are in
  1838. if( isVerticalSlide( currentSlide ) ) {
  1839. if( fragments.prev ) dom.controlsUp.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1840. if( fragments.next ) dom.controlsDown.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1841. }
  1842. else {
  1843. if( fragments.prev ) dom.controlsLeft.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1844. if( fragments.next ) dom.controlsRight.forEach( function( el ) { el.classList.add( 'fragmented', 'enabled' ); } );
  1845. }
  1846. }
  1847. }
  1848. /**
  1849. * Updates the background elements to reflect the current
  1850. * slide.
  1851. *
  1852. * @param {Boolean} includeAll If true, the backgrounds of
  1853. * all vertical slides (not just the present) will be updated.
  1854. */
  1855. function updateBackground( includeAll ) {
  1856. var currentBackground = null;
  1857. // Reverse past/future classes when in RTL mode
  1858. var horizontalPast = config.rtl ? 'future' : 'past',
  1859. horizontalFuture = config.rtl ? 'past' : 'future';
  1860. // Update the classes of all backgrounds to match the
  1861. // states of their slides (past/present/future)
  1862. toArray( dom.background.childNodes ).forEach( function( backgroundh, h ) {
  1863. backgroundh.classList.remove( 'past' );
  1864. backgroundh.classList.remove( 'present' );
  1865. backgroundh.classList.remove( 'future' );
  1866. if( h < indexh ) {
  1867. backgroundh.classList.add( horizontalPast );
  1868. }
  1869. else if ( h > indexh ) {
  1870. backgroundh.classList.add( horizontalFuture );
  1871. }
  1872. else {
  1873. backgroundh.classList.add( 'present' );
  1874. // Store a reference to the current background element
  1875. currentBackground = backgroundh;
  1876. }
  1877. if( includeAll || h === indexh ) {
  1878. toArray( backgroundh.querySelectorAll( '.slide-background' ) ).forEach( function( backgroundv, v ) {
  1879. backgroundv.classList.remove( 'past' );
  1880. backgroundv.classList.remove( 'present' );
  1881. backgroundv.classList.remove( 'future' );
  1882. if( v < indexv ) {
  1883. backgroundv.classList.add( 'past' );
  1884. }
  1885. else if ( v > indexv ) {
  1886. backgroundv.classList.add( 'future' );
  1887. }
  1888. else {
  1889. backgroundv.classList.add( 'present' );
  1890. // Only if this is the present horizontal and vertical slide
  1891. if( h === indexh ) currentBackground = backgroundv;
  1892. }
  1893. } );
  1894. }
  1895. } );
  1896. // Stop any currently playing video background
  1897. if( previousBackground ) {
  1898. var previousVideo = previousBackground.querySelector( 'video' );
  1899. if( previousVideo ) previousVideo.pause();
  1900. }
  1901. if( currentBackground ) {
  1902. // Start video playback
  1903. var currentVideo = currentBackground.querySelector( 'video' );
  1904. if( currentVideo ) {
  1905. currentVideo.addEventListener("loadeddata", function() {
  1906. currentVideo.currentTime = 0;
  1907. currentVideo.play();
  1908. loadeddataVideo = true;
  1909. this.removeEventListener("loadeddata",function(){return false});
  1910. });
  1911. if(loadeddataVideo === true){
  1912. currentVideo.currentTime = 0;
  1913. currentVideo.play();
  1914. }
  1915. }
  1916. // Don't transition between identical backgrounds. This
  1917. // prevents unwanted flicker.
  1918. var previousBackgroundHash = previousBackground ? previousBackground.getAttribute( 'data-background-hash' ) : null;
  1919. var currentBackgroundHash = currentBackground.getAttribute( 'data-background-hash' );
  1920. if( currentBackgroundHash && currentBackgroundHash === previousBackgroundHash && currentBackground !== previousBackground ) {
  1921. dom.background.classList.add( 'no-transition' );
  1922. }
  1923. previousBackground = currentBackground;
  1924. }
  1925. // If there's a background brightness flag for this slide,
  1926. // bubble it to the .reveal container
  1927. if( currentSlide ) {
  1928. [ 'has-light-background', 'has-dark-background' ].forEach( function( classToBubble ) {
  1929. if( currentSlide.classList.contains( classToBubble ) ) {
  1930. dom.wrapper.classList.add( classToBubble );
  1931. }
  1932. else {
  1933. dom.wrapper.classList.remove( classToBubble );
  1934. }
  1935. } );
  1936. }
  1937. // Allow the first background to apply without transition
  1938. setTimeout( function() {
  1939. dom.background.classList.remove( 'no-transition' );
  1940. }, 1 );
  1941. }
  1942. /**
  1943. * Updates the position of the parallax background based
  1944. * on the current slide index.
  1945. */
  1946. function updateParallax() {
  1947. if( config.parallaxBackgroundImage ) {
  1948. var horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  1949. verticalSlides = dom.wrapper.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  1950. var backgroundSize = dom.background.style.backgroundSize.split( ' ' ),
  1951. backgroundWidth, backgroundHeight;
  1952. if( backgroundSize.length === 1 ) {
  1953. backgroundWidth = backgroundHeight = parseInt( backgroundSize[0], 10 );
  1954. }
  1955. else {
  1956. backgroundWidth = parseInt( backgroundSize[0], 10 );
  1957. backgroundHeight = parseInt( backgroundSize[1], 10 );
  1958. }
  1959. var slideWidth = dom.background.offsetWidth;
  1960. var horizontalSlideCount = horizontalSlides.length;
  1961. var horizontalOffset = -( backgroundWidth - slideWidth ) / ( horizontalSlideCount-1 ) * indexh;
  1962. var slideHeight = dom.background.offsetHeight;
  1963. var verticalSlideCount = verticalSlides.length;
  1964. var verticalOffset = verticalSlideCount > 1 ? -( backgroundHeight - slideHeight ) / ( verticalSlideCount-1 ) * indexv : 0;
  1965. dom.background.style.backgroundPosition = horizontalOffset + 'px ' + verticalOffset + 'px';
  1966. }
  1967. }
  1968. /**
  1969. * Called when the given slide is within the configured view
  1970. * distance. Shows the slide element and loads any content
  1971. * that is set to load lazily (data-src).
  1972. */
  1973. function showSlide( slide ) {
  1974. // Show the slide element
  1975. slide.style.display = 'block';
  1976. // Media elements with data-src attributes
  1977. toArray( slide.querySelectorAll( 'img[data-src], video[data-src], audio[data-src], iframe[data-src]' ) ).forEach( function( element ) {
  1978. element.setAttribute( 'src', element.getAttribute( 'data-src' ) );
  1979. element.removeAttribute( 'data-src' );
  1980. } );
  1981. // Media elements with <source> children
  1982. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( media ) {
  1983. var sources = 0;
  1984. toArray( media.querySelectorAll( 'source[data-src]' ) ).forEach( function( source ) {
  1985. source.setAttribute( 'src', source.getAttribute( 'data-src' ) );
  1986. source.removeAttribute( 'data-src' );
  1987. sources += 1;
  1988. } );
  1989. // If we rewrote sources for this video/audio element, we need
  1990. // to manually tell it to load from its new origin
  1991. if( sources > 0 ) {
  1992. media.load();
  1993. }
  1994. } );
  1995. // Show the corresponding background element
  1996. var indices = getIndices( slide );
  1997. var background = getSlideBackground( indices.h, indices.v );
  1998. if( background ) {
  1999. background.style.display = 'block';
  2000. // If the background contains media, load it
  2001. if( background.hasAttribute( 'data-loaded' ) === false ) {
  2002. background.setAttribute( 'data-loaded', 'true' );
  2003. var backgroundImage = slide.getAttribute( 'data-background-image' ),
  2004. backgroundVideo = slide.getAttribute( 'data-background-video' ),
  2005. backgroundIframe = slide.getAttribute( 'data-background-iframe' );
  2006. // Images
  2007. if( backgroundImage ) {
  2008. background.style.backgroundImage = 'url('+ backgroundImage +')';
  2009. }
  2010. // Videos
  2011. else if ( backgroundVideo && !isSpeakerNotes() ) {
  2012. var video = document.createElement( 'video' );
  2013. // Support comma separated lists of video sources
  2014. backgroundVideo.split( ',' ).forEach( function( source ) {
  2015. video.innerHTML += '<source src="'+ source +'">';
  2016. } );
  2017. background.appendChild( video );
  2018. }
  2019. // Iframes
  2020. else if ( backgroundIframe ) {
  2021. var iframe = document.createElement( 'iframe' );
  2022. iframe.setAttribute( 'src', backgroundIframe );
  2023. iframe.style.width = '100%';
  2024. iframe.style.height = '100%';
  2025. iframe.style.maxHeight = '100%';
  2026. iframe.style.maxWidth = '100%';
  2027. background.appendChild( iframe );
  2028. }
  2029. }
  2030. }
  2031. }
  2032. /**
  2033. * Called when the given slide is moved outside of the
  2034. * configured view distance.
  2035. */
  2036. function hideSlide( slide ) {
  2037. // Hide the slide element
  2038. slide.style.display = 'none';
  2039. // Hide the corresponding background element
  2040. var indices = getIndices( slide );
  2041. var background = getSlideBackground( indices.h, indices.v );
  2042. if( background ) {
  2043. background.style.display = 'none';
  2044. }
  2045. }
  2046. /**
  2047. * Determine what available routes there are for navigation.
  2048. *
  2049. * @return {Object} containing four booleans: left/right/up/down
  2050. */
  2051. function availableRoutes() {
  2052. var horizontalSlides = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ),
  2053. verticalSlides = dom.wrapper.querySelectorAll( VERTICAL_SLIDES_SELECTOR );
  2054. var routes = {
  2055. left: indexh > 0 || config.loop,
  2056. right: indexh < horizontalSlides.length - 1 || config.loop,
  2057. up: indexv > 0,
  2058. down: indexv < verticalSlides.length - 1
  2059. };
  2060. // reverse horizontal controls for rtl
  2061. if( config.rtl ) {
  2062. var left = routes.left;
  2063. routes.left = routes.right;
  2064. routes.right = left;
  2065. }
  2066. return routes;
  2067. }
  2068. /**
  2069. * Returns an object describing the available fragment
  2070. * directions.
  2071. *
  2072. * @return {Object} two boolean properties: prev/next
  2073. */
  2074. function availableFragments() {
  2075. if( currentSlide && config.fragments ) {
  2076. var fragments = currentSlide.querySelectorAll( '.fragment' );
  2077. var hiddenFragments = currentSlide.querySelectorAll( '.fragment:not(.visible)' );
  2078. return {
  2079. prev: fragments.length - hiddenFragments.length > 0,
  2080. next: !!hiddenFragments.length
  2081. };
  2082. }
  2083. else {
  2084. return { prev: false, next: false };
  2085. }
  2086. }
  2087. /**
  2088. * Enforces origin-specific format rules for embedded media.
  2089. */
  2090. function formatEmbeddedContent() {
  2091. // YouTube frames must include "?enablejsapi=1"
  2092. toArray( dom.slides.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  2093. var src = el.getAttribute( 'src' );
  2094. if( !/enablejsapi\=1/gi.test( src ) ) {
  2095. el.setAttribute( 'src', src + ( !/\?/.test( src ) ? '?' : '&' ) + 'enablejsapi=1' );
  2096. }
  2097. });
  2098. // Vimeo frames must include "?api=1"
  2099. toArray( dom.slides.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( function( el ) {
  2100. var src = el.getAttribute( 'src' );
  2101. if( !/api\=1/gi.test( src ) ) {
  2102. el.setAttribute( 'src', src + ( !/\?/.test( src ) ? '?' : '&' ) + 'api=1' );
  2103. }
  2104. });
  2105. }
  2106. /**
  2107. * Start playback of any embedded content inside of
  2108. * the targeted slide.
  2109. */
  2110. function startEmbeddedContent( slide ) {
  2111. if( slide && !isSpeakerNotes() ) {
  2112. // HTML5 media elements
  2113. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  2114. if( el.hasAttribute( 'data-autoplay' ) ) {
  2115. el.play();
  2116. }
  2117. } );
  2118. // iframe embeds
  2119. toArray( slide.querySelectorAll( 'iframe' ) ).forEach( function( el ) {
  2120. el.contentWindow.postMessage( 'slide:start', '*' );
  2121. });
  2122. // YouTube embeds
  2123. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  2124. if( el.hasAttribute( 'data-autoplay' ) ) {
  2125. el.contentWindow.postMessage( '{"event":"command","func":"playVideo","args":""}', '*' );
  2126. }
  2127. });
  2128. // Vimeo embeds
  2129. toArray( slide.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( function( el ) {
  2130. if( el.hasAttribute( 'data-autoplay' ) ) {
  2131. el.contentWindow.postMessage( '{"method":"play"}', '*' );
  2132. }
  2133. });
  2134. }
  2135. }
  2136. /**
  2137. * Stop playback of any embedded content inside of
  2138. * the targeted slide.
  2139. */
  2140. function stopEmbeddedContent( slide ) {
  2141. if( slide && slide.parentNode ) {
  2142. // HTML5 media elements
  2143. toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  2144. if( !el.hasAttribute( 'data-ignore' ) ) {
  2145. el.pause();
  2146. }
  2147. } );
  2148. // iframe embeds
  2149. toArray( slide.querySelectorAll( 'iframe' ) ).forEach( function( el ) {
  2150. el.contentWindow.postMessage( 'slide:stop', '*' );
  2151. });
  2152. // YouTube embeds
  2153. toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
  2154. if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
  2155. el.contentWindow.postMessage( '{"event":"command","func":"pauseVideo","args":""}', '*' );
  2156. }
  2157. });
  2158. // Vimeo embeds
  2159. toArray( slide.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( function( el ) {
  2160. if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
  2161. el.contentWindow.postMessage( '{"method":"pause"}', '*' );
  2162. }
  2163. });
  2164. }
  2165. }
  2166. /**
  2167. * Returns a value ranging from 0-1 that represents
  2168. * how far into the presentation we have navigated.
  2169. */
  2170. function getProgress() {
  2171. var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  2172. // The number of past and total slides
  2173. var totalCount = getTotalSlides();
  2174. var pastCount = 0;
  2175. // Step through all slides and count the past ones
  2176. mainLoop: for( var i = 0; i < horizontalSlides.length; i++ ) {
  2177. var horizontalSlide = horizontalSlides[i];
  2178. var verticalSlides = toArray( horizontalSlide.querySelectorAll( 'section' ) );
  2179. for( var j = 0; j < verticalSlides.length; j++ ) {
  2180. // Stop as soon as we arrive at the present
  2181. if( verticalSlides[j].classList.contains( 'present' ) ) {
  2182. break mainLoop;
  2183. }
  2184. pastCount++;
  2185. }
  2186. // Stop as soon as we arrive at the present
  2187. if( horizontalSlide.classList.contains( 'present' ) ) {
  2188. break;
  2189. }
  2190. // Don't count the wrapping section for vertical slides
  2191. if( horizontalSlide.classList.contains( 'stack' ) === false ) {
  2192. pastCount++;
  2193. }
  2194. }
  2195. if( currentSlide ) {
  2196. var allFragments = currentSlide.querySelectorAll( '.fragment' );
  2197. // If there are fragments in the current slide those should be
  2198. // accounted for in the progress.
  2199. if( allFragments.length > 0 ) {
  2200. var visibleFragments = currentSlide.querySelectorAll( '.fragment.visible' );
  2201. // This value represents how big a portion of the slide progress
  2202. // that is made up by its fragments (0-1)
  2203. var fragmentWeight = 0.9;
  2204. // Add fragment progress to the past slide count
  2205. pastCount += ( visibleFragments.length / allFragments.length ) * fragmentWeight;
  2206. }
  2207. }
  2208. return pastCount / ( totalCount - 1 );
  2209. }
  2210. /**
  2211. * Checks if this presentation is running inside of the
  2212. * speaker notes window.
  2213. */
  2214. function isSpeakerNotes() {
  2215. return !!window.location.search.match( /receiver/gi );
  2216. }
  2217. /**
  2218. * Reads the current URL (hash) and navigates accordingly.
  2219. */
  2220. function readURL() {
  2221. var hash = window.location.hash;
  2222. // Attempt to parse the hash as either an index or name
  2223. var bits = hash.slice( 2 ).split( '/' ),
  2224. name = hash.replace( /#|\//gi, '' );
  2225. // If the first bit is invalid and there is a name we can
  2226. // assume that this is a named link
  2227. if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
  2228. var element;
  2229. // Ensure the named link is a valid HTML ID attribute
  2230. if( /^[a-zA-Z][\w:.-]*$/.test( name ) ) {
  2231. // Find the slide with the specified ID
  2232. element = document.querySelector( '#' + name );
  2233. }
  2234. if( element ) {
  2235. // Find the position of the named slide and navigate to it
  2236. var indices = Reveal.getIndices( element );
  2237. slide( indices.h, indices.v );
  2238. }
  2239. // If the slide doesn't exist, navigate to the current slide
  2240. else {
  2241. slide( indexh || 0, indexv || 0 );
  2242. }
  2243. }
  2244. else {
  2245. // Read the index components of the hash
  2246. var h = parseInt( bits[0], 10 ) || 0,
  2247. v = parseInt( bits[1], 10 ) || 0;
  2248. if( h !== indexh || v !== indexv ) {
  2249. slide( h, v );
  2250. }
  2251. }
  2252. }
  2253. /**
  2254. * Updates the page URL (hash) to reflect the current
  2255. * state.
  2256. *
  2257. * @param {Number} delay The time in ms to wait before
  2258. * writing the hash
  2259. */
  2260. function writeURL( delay ) {
  2261. if( config.history ) {
  2262. // Make sure there's never more than one timeout running
  2263. clearTimeout( writeURLTimeout );
  2264. // If a delay is specified, timeout this call
  2265. if( typeof delay === 'number' ) {
  2266. writeURLTimeout = setTimeout( writeURL, delay );
  2267. }
  2268. else if( currentSlide ) {
  2269. var url = '/';
  2270. // Attempt to create a named link based on the slide's ID
  2271. var id = currentSlide.getAttribute( 'id' );
  2272. if( id ) {
  2273. id = id.toLowerCase();
  2274. id = id.replace( /[^a-zA-Z0-9\-\_\:\.]/g, '' );
  2275. }
  2276. // If the current slide has an ID, use that as a named link
  2277. if( typeof id === 'string' && id.length ) {
  2278. url = '/' + id;
  2279. }
  2280. // Otherwise use the /h/v index
  2281. else {
  2282. if( indexh > 0 || indexv > 0 ) url += indexh;
  2283. if( indexv > 0 ) url += '/' + indexv;
  2284. }
  2285. window.location.hash = url;
  2286. }
  2287. }
  2288. }
  2289. /**
  2290. * Retrieves the h/v location of the current, or specified,
  2291. * slide.
  2292. *
  2293. * @param {HTMLElement} slide If specified, the returned
  2294. * index will be for this slide rather than the currently
  2295. * active one
  2296. *
  2297. * @return {Object} { h: <int>, v: <int>, f: <int> }
  2298. */
  2299. function getIndices( slide ) {
  2300. // By default, return the current indices
  2301. var h = indexh,
  2302. v = indexv,
  2303. f;
  2304. // If a slide is specified, return the indices of that slide
  2305. if( slide ) {
  2306. var isVertical = isVerticalSlide( slide );
  2307. var slideh = isVertical ? slide.parentNode : slide;
  2308. // Select all horizontal slides
  2309. var horizontalSlides = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) );
  2310. // Now that we know which the horizontal slide is, get its index
  2311. h = Math.max( horizontalSlides.indexOf( slideh ), 0 );
  2312. // Assume we're not vertical
  2313. v = undefined;
  2314. // If this is a vertical slide, grab the vertical index
  2315. if( isVertical ) {
  2316. v = Math.max( toArray( slide.parentNode.querySelectorAll( 'section' ) ).indexOf( slide ), 0 );
  2317. }
  2318. }
  2319. if( !slide && currentSlide ) {
  2320. var hasFragments = currentSlide.querySelectorAll( '.fragment' ).length > 0;
  2321. if( hasFragments ) {
  2322. var currentFragment = currentSlide.querySelector( '.current-fragment' );
  2323. if( currentFragment && currentFragment.hasAttribute( 'data-fragment-index' ) ) {
  2324. f = parseInt( currentFragment.getAttribute( 'data-fragment-index' ), 10 );
  2325. }
  2326. else {
  2327. f = currentSlide.querySelectorAll( '.fragment.visible' ).length - 1;
  2328. }
  2329. }
  2330. }
  2331. return { h: h, v: v, f: f };
  2332. }
  2333. /**
  2334. * Retrieves the total number of slides in this presentation.
  2335. */
  2336. function getTotalSlides() {
  2337. return dom.wrapper.querySelectorAll( SLIDES_SELECTOR + ':not(.stack)' ).length;
  2338. }
  2339. /**
  2340. * Returns the slide element matching the specified index.
  2341. */
  2342. function getSlide( x, y ) {
  2343. var horizontalSlide = dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR )[ x ];
  2344. var verticalSlides = horizontalSlide && horizontalSlide.querySelectorAll( 'section' );
  2345. if( verticalSlides && verticalSlides.length && typeof y === 'number' ) {
  2346. return verticalSlides ? verticalSlides[ y ] : undefined;
  2347. }
  2348. return horizontalSlide;
  2349. }
  2350. /**
  2351. * Returns the background element for the given slide.
  2352. * All slides, even the ones with no background properties
  2353. * defined, have a background element so as long as the
  2354. * index is valid an element will be returned.
  2355. */
  2356. function getSlideBackground( x, y ) {
  2357. // When printing to PDF the slide backgrounds are nested
  2358. // inside of the slides
  2359. if( isPrintingPDF() ) {
  2360. var slide = getSlide( x, y );
  2361. if( slide ) {
  2362. var background = slide.querySelector( '.slide-background' );
  2363. if( background && background.parentNode === slide ) {
  2364. return background;
  2365. }
  2366. }
  2367. return undefined;
  2368. }
  2369. var horizontalBackground = dom.wrapper.querySelectorAll( '.backgrounds>.slide-background' )[ x ];
  2370. var verticalBackgrounds = horizontalBackground && horizontalBackground.querySelectorAll( '.slide-background' );
  2371. if( verticalBackgrounds && verticalBackgrounds.length && typeof y === 'number' ) {
  2372. return verticalBackgrounds ? verticalBackgrounds[ y ] : undefined;
  2373. }
  2374. return horizontalBackground;
  2375. }
  2376. /**
  2377. * Retrieves the current state of the presentation as
  2378. * an object. This state can then be restored at any
  2379. * time.
  2380. */
  2381. function getState() {
  2382. var indices = getIndices();
  2383. return {
  2384. indexh: indices.h,
  2385. indexv: indices.v,
  2386. indexf: indices.f,
  2387. paused: isPaused(),
  2388. overview: isOverview()
  2389. };
  2390. }
  2391. /**
  2392. * Restores the presentation to the given state.
  2393. *
  2394. * @param {Object} state As generated by getState()
  2395. */
  2396. function setState( state ) {
  2397. if( typeof state === 'object' ) {
  2398. slide( deserialize( state.indexh ), deserialize( state.indexv ), deserialize( state.indexf ) );
  2399. var pausedFlag = deserialize( state.paused ),
  2400. overviewFlag = deserialize( state.overview );
  2401. if( typeof pausedFlag === 'boolean' && pausedFlag !== isPaused() ) {
  2402. togglePause( pausedFlag );
  2403. }
  2404. if( typeof overviewFlag === 'boolean' && overviewFlag !== isOverview() ) {
  2405. toggleOverview( overviewFlag );
  2406. }
  2407. }
  2408. }
  2409. /**
  2410. * Return a sorted fragments list, ordered by an increasing
  2411. * "data-fragment-index" attribute.
  2412. *
  2413. * Fragments will be revealed in the order that they are returned by
  2414. * this function, so you can use the index attributes to control the
  2415. * order of fragment appearance.
  2416. *
  2417. * To maintain a sensible default fragment order, fragments are presumed
  2418. * to be passed in document order. This function adds a "fragment-index"
  2419. * attribute to each node if such an attribute is not already present,
  2420. * and sets that attribute to an integer value which is the position of
  2421. * the fragment within the fragments list.
  2422. */
  2423. function sortFragments( fragments ) {
  2424. fragments = toArray( fragments );
  2425. var ordered = [],
  2426. unordered = [],
  2427. sorted = [];
  2428. // Group ordered and unordered elements
  2429. fragments.forEach( function( fragment, i ) {
  2430. if( fragment.hasAttribute( 'data-fragment-index' ) ) {
  2431. var index = parseInt( fragment.getAttribute( 'data-fragment-index' ), 10 );
  2432. if( !ordered[index] ) {
  2433. ordered[index] = [];
  2434. }
  2435. ordered[index].push( fragment );
  2436. }
  2437. else {
  2438. unordered.push( [ fragment ] );
  2439. }
  2440. } );
  2441. // Append fragments without explicit indices in their
  2442. // DOM order
  2443. ordered = ordered.concat( unordered );
  2444. // Manually count the index up per group to ensure there
  2445. // are no gaps
  2446. var index = 0;
  2447. // Push all fragments in their sorted order to an array,
  2448. // this flattens the groups
  2449. ordered.forEach( function( group ) {
  2450. group.forEach( function( fragment ) {
  2451. sorted.push( fragment );
  2452. fragment.setAttribute( 'data-fragment-index', index );
  2453. } );
  2454. index ++;
  2455. } );
  2456. return sorted;
  2457. }
  2458. /**
  2459. * Navigate to the specified slide fragment.
  2460. *
  2461. * @param {Number} index The index of the fragment that
  2462. * should be shown, -1 means all are invisible
  2463. * @param {Number} offset Integer offset to apply to the
  2464. * fragment index
  2465. *
  2466. * @return {Boolean} true if a change was made in any
  2467. * fragments visibility as part of this call
  2468. */
  2469. function navigateFragment( index, offset ) {
  2470. if( currentSlide && config.fragments ) {
  2471. var fragments = sortFragments( currentSlide.querySelectorAll( '.fragment' ) );
  2472. if( fragments.length ) {
  2473. // If no index is specified, find the current
  2474. if( typeof index !== 'number' ) {
  2475. var lastVisibleFragment = sortFragments( currentSlide.querySelectorAll( '.fragment.visible' ) ).pop();
  2476. if( lastVisibleFragment ) {
  2477. index = parseInt( lastVisibleFragment.getAttribute( 'data-fragment-index' ) || 0, 10 );
  2478. }
  2479. else {
  2480. index = -1;
  2481. }
  2482. }
  2483. // If an offset is specified, apply it to the index
  2484. if( typeof offset === 'number' ) {
  2485. index += offset;
  2486. }
  2487. var fragmentsShown = [],
  2488. fragmentsHidden = [];
  2489. toArray( fragments ).forEach( function( element, i ) {
  2490. if( element.hasAttribute( 'data-fragment-index' ) ) {
  2491. i = parseInt( element.getAttribute( 'data-fragment-index' ), 10 );
  2492. }
  2493. // Visible fragments
  2494. if( i <= index ) {
  2495. if( !element.classList.contains( 'visible' ) ) fragmentsShown.push( element );
  2496. element.classList.add( 'visible' );
  2497. element.classList.remove( 'current-fragment' );
  2498. // Announce the fragments one by one to the Screen Reader
  2499. dom.statusDiv.textContent = element.textContent;
  2500. if( i === index ) {
  2501. element.classList.add( 'current-fragment' );
  2502. }
  2503. }
  2504. // Hidden fragments
  2505. else {
  2506. if( element.classList.contains( 'visible' ) ) fragmentsHidden.push( element );
  2507. element.classList.remove( 'visible' );
  2508. element.classList.remove( 'current-fragment' );
  2509. }
  2510. } );
  2511. if( fragmentsHidden.length ) {
  2512. dispatchEvent( 'fragmenthidden', { fragment: fragmentsHidden[0], fragments: fragmentsHidden } );
  2513. }
  2514. if( fragmentsShown.length ) {
  2515. dispatchEvent( 'fragmentshown', { fragment: fragmentsShown[0], fragments: fragmentsShown } );
  2516. }
  2517. updateControls();
  2518. updateProgress();
  2519. return !!( fragmentsShown.length || fragmentsHidden.length );
  2520. }
  2521. }
  2522. return false;
  2523. }
  2524. /**
  2525. * Navigate to the next slide fragment.
  2526. *
  2527. * @return {Boolean} true if there was a next fragment,
  2528. * false otherwise
  2529. */
  2530. function nextFragment() {
  2531. return navigateFragment( null, 1 );
  2532. }
  2533. /**
  2534. * Navigate to the previous slide fragment.
  2535. *
  2536. * @return {Boolean} true if there was a previous fragment,
  2537. * false otherwise
  2538. */
  2539. function previousFragment() {
  2540. return navigateFragment( null, -1 );
  2541. }
  2542. /**
  2543. * Cues a new automated slide if enabled in the config.
  2544. */
  2545. function cueAutoSlide() {
  2546. cancelAutoSlide();
  2547. if( currentSlide ) {
  2548. var currentFragment = currentSlide.querySelector( '.current-fragment' );
  2549. var fragmentAutoSlide = currentFragment ? currentFragment.getAttribute( 'data-autoslide' ) : null;
  2550. var parentAutoSlide = currentSlide.parentNode ? currentSlide.parentNode.getAttribute( 'data-autoslide' ) : null;
  2551. var slideAutoSlide = currentSlide.getAttribute( 'data-autoslide' );
  2552. // Pick value in the following priority order:
  2553. // 1. Current fragment's data-autoslide
  2554. // 2. Current slide's data-autoslide
  2555. // 3. Parent slide's data-autoslide
  2556. // 4. Global autoSlide setting
  2557. if( fragmentAutoSlide ) {
  2558. autoSlide = parseInt( fragmentAutoSlide, 10 );
  2559. }
  2560. else if( slideAutoSlide ) {
  2561. autoSlide = parseInt( slideAutoSlide, 10 );
  2562. }
  2563. else if( parentAutoSlide ) {
  2564. autoSlide = parseInt( parentAutoSlide, 10 );
  2565. }
  2566. else {
  2567. autoSlide = config.autoSlide;
  2568. }
  2569. // If there are media elements with data-autoplay,
  2570. // automatically set the autoSlide duration to the
  2571. // length of that media
  2572. toArray( currentSlide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
  2573. if( el.hasAttribute( 'data-autoplay' ) ) {
  2574. if( autoSlide && el.duration * 1000 > autoSlide ) {
  2575. autoSlide = ( el.duration * 1000 ) + 1000;
  2576. }
  2577. }
  2578. } );
  2579. // Cue the next auto-slide if:
  2580. // - There is an autoSlide value
  2581. // - Auto-sliding isn't paused by the user
  2582. // - The presentation isn't paused
  2583. // - The overview isn't active
  2584. // - The presentation isn't over
  2585. if( autoSlide && !autoSlidePaused && !isPaused() && !isOverview() && ( !Reveal.isLastSlide() || availableFragments().next || config.loop === true ) ) {
  2586. autoSlideTimeout = setTimeout( navigateNext, autoSlide );
  2587. autoSlideStartTime = Date.now();
  2588. }
  2589. if( autoSlidePlayer ) {
  2590. autoSlidePlayer.setPlaying( autoSlideTimeout !== -1 );
  2591. }
  2592. }
  2593. }
  2594. /**
  2595. * Cancels any ongoing request to auto-slide.
  2596. */
  2597. function cancelAutoSlide() {
  2598. clearTimeout( autoSlideTimeout );
  2599. autoSlideTimeout = -1;
  2600. }
  2601. function pauseAutoSlide() {
  2602. if( autoSlide && !autoSlidePaused ) {
  2603. autoSlidePaused = true;
  2604. dispatchEvent( 'autoslidepaused' );
  2605. clearTimeout( autoSlideTimeout );
  2606. if( autoSlidePlayer ) {
  2607. autoSlidePlayer.setPlaying( false );
  2608. }
  2609. }
  2610. }
  2611. function resumeAutoSlide() {
  2612. if( autoSlide && autoSlidePaused ) {
  2613. autoSlidePaused = false;
  2614. dispatchEvent( 'autoslideresumed' );
  2615. cueAutoSlide();
  2616. }
  2617. }
  2618. function navigateLeft() {
  2619. // Reverse for RTL
  2620. if( config.rtl ) {
  2621. if( ( isOverview() || nextFragment() === false ) && availableRoutes().left ) {
  2622. slide( indexh + 1 );
  2623. }
  2624. }
  2625. // Normal navigation
  2626. else if( ( isOverview() || previousFragment() === false ) && availableRoutes().left ) {
  2627. slide( indexh - 1 );
  2628. }
  2629. }
  2630. function navigateRight() {
  2631. // Reverse for RTL
  2632. if( config.rtl ) {
  2633. if( ( isOverview() || previousFragment() === false ) && availableRoutes().right ) {
  2634. slide( indexh - 1 );
  2635. }
  2636. }
  2637. // Normal navigation
  2638. else if( ( isOverview() || nextFragment() === false ) && availableRoutes().right ) {
  2639. slide( indexh + 1 );
  2640. }
  2641. }
  2642. function navigateUp() {
  2643. // Prioritize hiding fragments
  2644. if( ( isOverview() || previousFragment() === false ) && availableRoutes().up ) {
  2645. slide( indexh, indexv - 1 );
  2646. }
  2647. }
  2648. function navigateDown() {
  2649. // Prioritize revealing fragments
  2650. if( ( isOverview() || nextFragment() === false ) && availableRoutes().down ) {
  2651. slide( indexh, indexv + 1 );
  2652. }
  2653. }
  2654. /**
  2655. * Navigates backwards, prioritized in the following order:
  2656. * 1) Previous fragment
  2657. * 2) Previous vertical slide
  2658. * 3) Previous horizontal slide
  2659. */
  2660. function navigatePrev() {
  2661. // Prioritize revealing fragments
  2662. if( previousFragment() === false ) {
  2663. if( availableRoutes().up ) {
  2664. navigateUp();
  2665. }
  2666. else {
  2667. // Fetch the previous horizontal slide, if there is one
  2668. var previousSlide;
  2669. if( config.rtl ) {
  2670. previousSlide = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.future' ) ).pop();
  2671. }
  2672. else {
  2673. previousSlide = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR + '.past' ) ).pop();
  2674. }
  2675. if( previousSlide ) {
  2676. var v = ( previousSlide.querySelectorAll( 'section' ).length - 1 ) || undefined;
  2677. var h = indexh - 1;
  2678. slide( h, v );
  2679. }
  2680. }
  2681. }
  2682. }
  2683. /**
  2684. * The reverse of #navigatePrev().
  2685. */
  2686. function navigateNext() {
  2687. // Prioritize revealing fragments
  2688. if( nextFragment() === false ) {
  2689. if( availableRoutes().down ) {
  2690. navigateDown();
  2691. }
  2692. else if( config.rtl ) {
  2693. navigateLeft();
  2694. }
  2695. else {
  2696. navigateRight();
  2697. }
  2698. }
  2699. // If auto-sliding is enabled we need to cue up
  2700. // another timeout
  2701. cueAutoSlide();
  2702. }
  2703. // --------------------------------------------------------------------//
  2704. // ----------------------------- EVENTS -------------------------------//
  2705. // --------------------------------------------------------------------//
  2706. /**
  2707. * Called by all event handlers that are based on user
  2708. * input.
  2709. */
  2710. function onUserInput( event ) {
  2711. if( config.autoSlideStoppable ) {
  2712. pauseAutoSlide();
  2713. }
  2714. }
  2715. /**
  2716. * Handler for the document level 'keypress' event.
  2717. */
  2718. function onDocumentKeyPress( event ) {
  2719. // Check if the pressed key is question mark
  2720. if( event.shiftKey && event.charCode === 63 ) {
  2721. if( dom.overlay ) {
  2722. closeOverlay();
  2723. }
  2724. else {
  2725. showHelp( true );
  2726. }
  2727. }
  2728. }
  2729. /**
  2730. * Handler for the document level 'keydown' event.
  2731. */
  2732. function onDocumentKeyDown( event ) {
  2733. // If there's a condition specified and it returns false,
  2734. // ignore this event
  2735. if( typeof config.keyboardCondition === 'function' && config.keyboardCondition() === false ) {
  2736. return true;
  2737. }
  2738. // Remember if auto-sliding was paused so we can toggle it
  2739. var autoSlideWasPaused = autoSlidePaused;
  2740. onUserInput( event );
  2741. // Check if there's a focused element that could be using
  2742. // the keyboard
  2743. var activeElementIsCE = document.activeElement && document.activeElement.contentEditable !== 'inherit';
  2744. var activeElementIsInput = document.activeElement && document.activeElement.tagName && /input|textarea/i.test( document.activeElement.tagName );
  2745. // Disregard the event if there's a focused element or a
  2746. // keyboard modifier key is present
  2747. if( activeElementIsCE || activeElementIsInput || (event.shiftKey && event.keyCode !== 32) || event.altKey || event.ctrlKey || event.metaKey ) return;
  2748. // While paused only allow "unpausing" keyboard events (b and .)
  2749. if( isPaused() && [66,190,191].indexOf( event.keyCode ) === -1 ) {
  2750. return false;
  2751. }
  2752. var triggered = false;
  2753. // 1. User defined key bindings
  2754. if( typeof config.keyboard === 'object' ) {
  2755. for( var key in config.keyboard ) {
  2756. // Check if this binding matches the pressed key
  2757. if( parseInt( key, 10 ) === event.keyCode ) {
  2758. var value = config.keyboard[ key ];
  2759. // Callback function
  2760. if( typeof value === 'function' ) {
  2761. value.apply( null, [ event ] );
  2762. }
  2763. // String shortcuts to reveal.js API
  2764. else if( typeof value === 'string' && typeof Reveal[ value ] === 'function' ) {
  2765. Reveal[ value ].call();
  2766. }
  2767. triggered = true;
  2768. }
  2769. }
  2770. }
  2771. // 2. System defined key bindings
  2772. if( triggered === false ) {
  2773. // Assume true and try to prove false
  2774. triggered = true;
  2775. switch( event.keyCode ) {
  2776. // p, page up
  2777. case 80: case 33: navigatePrev(); break;
  2778. // n, page down
  2779. case 78: case 34: navigateNext(); break;
  2780. // h, left
  2781. case 72: case 37: navigateLeft(); break;
  2782. // l, right
  2783. case 76: case 39: navigateRight(); break;
  2784. // k, up
  2785. case 75: case 38: navigateUp(); break;
  2786. // j, down
  2787. case 74: case 40: navigateDown(); break;
  2788. // home
  2789. case 36: slide( 0 ); break;
  2790. // end
  2791. case 35: slide( Number.MAX_VALUE ); break;
  2792. // space
  2793. case 32: isOverview() ? deactivateOverview() : event.shiftKey ? navigatePrev() : navigateNext(); break;
  2794. // return
  2795. case 13: isOverview() ? deactivateOverview() : triggered = false; break;
  2796. // two-spot, semicolon, b, period, Logitech presenter tools "black screen" button
  2797. case 58: case 59: case 66: case 190: case 191: togglePause(); break;
  2798. // f
  2799. case 70: enterFullscreen(); break;
  2800. // a
  2801. case 65: if ( config.autoSlideStoppable ) toggleAutoSlide( autoSlideWasPaused ); break;
  2802. default:
  2803. triggered = false;
  2804. }
  2805. }
  2806. // If the input resulted in a triggered action we should prevent
  2807. // the browsers default behavior
  2808. if( triggered ) {
  2809. event.preventDefault && event.preventDefault();
  2810. }
  2811. // ESC or O key
  2812. else if ( ( event.keyCode === 27 || event.keyCode === 79 ) && features.transforms3d ) {
  2813. if( dom.overlay ) {
  2814. closeOverlay();
  2815. }
  2816. else {
  2817. toggleOverview();
  2818. }
  2819. event.preventDefault && event.preventDefault();
  2820. }
  2821. // If auto-sliding is enabled we need to cue up
  2822. // another timeout
  2823. cueAutoSlide();
  2824. }
  2825. /**
  2826. * Handler for the 'touchstart' event, enables support for
  2827. * swipe and pinch gestures.
  2828. */
  2829. function onTouchStart( event ) {
  2830. touch.startX = event.touches[0].clientX;
  2831. touch.startY = event.touches[0].clientY;
  2832. touch.startCount = event.touches.length;
  2833. // If there's two touches we need to memorize the distance
  2834. // between those two points to detect pinching
  2835. if( event.touches.length === 2 && config.overview ) {
  2836. touch.startSpan = distanceBetween( {
  2837. x: event.touches[1].clientX,
  2838. y: event.touches[1].clientY
  2839. }, {
  2840. x: touch.startX,
  2841. y: touch.startY
  2842. } );
  2843. }
  2844. }
  2845. /**
  2846. * Handler for the 'touchmove' event.
  2847. */
  2848. function onTouchMove( event ) {
  2849. // Each touch should only trigger one action
  2850. if( !touch.captured ) {
  2851. onUserInput( event );
  2852. var currentX = event.touches[0].clientX;
  2853. var currentY = event.touches[0].clientY;
  2854. // If the touch started with two points and still has
  2855. // two active touches; test for the pinch gesture
  2856. if( event.touches.length === 2 && touch.startCount === 2 && config.overview ) {
  2857. // The current distance in pixels between the two touch points
  2858. var currentSpan = distanceBetween( {
  2859. x: event.touches[1].clientX,
  2860. y: event.touches[1].clientY
  2861. }, {
  2862. x: touch.startX,
  2863. y: touch.startY
  2864. } );
  2865. // If the span is larger than the desire amount we've got
  2866. // ourselves a pinch
  2867. if( Math.abs( touch.startSpan - currentSpan ) > touch.threshold ) {
  2868. touch.captured = true;
  2869. if( currentSpan < touch.startSpan ) {
  2870. activateOverview();
  2871. }
  2872. else {
  2873. deactivateOverview();
  2874. }
  2875. }
  2876. event.preventDefault();
  2877. }
  2878. // There was only one touch point, look for a swipe
  2879. else if( event.touches.length === 1 && touch.startCount !== 2 ) {
  2880. var deltaX = currentX - touch.startX,
  2881. deltaY = currentY - touch.startY;
  2882. if( deltaX > touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  2883. touch.captured = true;
  2884. navigateLeft();
  2885. }
  2886. else if( deltaX < -touch.threshold && Math.abs( deltaX ) > Math.abs( deltaY ) ) {
  2887. touch.captured = true;
  2888. navigateRight();
  2889. }
  2890. else if( deltaY > touch.threshold ) {
  2891. touch.captured = true;
  2892. navigateUp();
  2893. }
  2894. else if( deltaY < -touch.threshold ) {
  2895. touch.captured = true;
  2896. navigateDown();
  2897. }
  2898. // If we're embedded, only block touch events if they have
  2899. // triggered an action
  2900. if( config.embedded ) {
  2901. if( touch.captured || isVerticalSlide( currentSlide ) ) {
  2902. event.preventDefault();
  2903. }
  2904. }
  2905. // Not embedded? Block them all to avoid needless tossing
  2906. // around of the viewport in iOS
  2907. else {
  2908. event.preventDefault();
  2909. }
  2910. }
  2911. }
  2912. // There's a bug with swiping on some Android devices unless
  2913. // the default action is always prevented
  2914. else if( navigator.userAgent.match( /android/gi ) ) {
  2915. event.preventDefault();
  2916. }
  2917. }
  2918. /**
  2919. * Handler for the 'touchend' event.
  2920. */
  2921. function onTouchEnd( event ) {
  2922. touch.captured = false;
  2923. }
  2924. /**
  2925. * Convert pointer down to touch start.
  2926. */
  2927. function onPointerDown( event ) {
  2928. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  2929. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  2930. onTouchStart( event );
  2931. }
  2932. }
  2933. /**
  2934. * Convert pointer move to touch move.
  2935. */
  2936. function onPointerMove( event ) {
  2937. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  2938. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  2939. onTouchMove( event );
  2940. }
  2941. }
  2942. /**
  2943. * Convert pointer up to touch end.
  2944. */
  2945. function onPointerUp( event ) {
  2946. if( event.pointerType === event.MSPOINTER_TYPE_TOUCH || event.pointerType === "touch" ) {
  2947. event.touches = [{ clientX: event.clientX, clientY: event.clientY }];
  2948. onTouchEnd( event );
  2949. }
  2950. }
  2951. /**
  2952. * Handles mouse wheel scrolling, throttled to avoid skipping
  2953. * multiple slides.
  2954. */
  2955. function onDocumentMouseScroll( event ) {
  2956. if( Date.now() - lastMouseWheelStep > 600 ) {
  2957. lastMouseWheelStep = Date.now();
  2958. var delta = event.detail || -event.wheelDelta;
  2959. if( delta > 0 ) {
  2960. navigateNext();
  2961. }
  2962. else {
  2963. navigatePrev();
  2964. }
  2965. }
  2966. }
  2967. /**
  2968. * Clicking on the progress bar results in a navigation to the
  2969. * closest approximate horizontal slide using this equation:
  2970. *
  2971. * ( clickX / presentationWidth ) * numberOfSlides
  2972. */
  2973. function onProgressClicked( event ) {
  2974. onUserInput( event );
  2975. event.preventDefault();
  2976. var slidesTotal = toArray( dom.wrapper.querySelectorAll( HORIZONTAL_SLIDES_SELECTOR ) ).length;
  2977. var slideIndex = Math.floor( ( event.clientX / dom.wrapper.offsetWidth ) * slidesTotal );
  2978. slide( slideIndex );
  2979. }
  2980. /**
  2981. * Event handler for navigation control buttons.
  2982. */
  2983. function onNavigateLeftClicked( event ) { event.preventDefault(); onUserInput(); navigateLeft(); }
  2984. function onNavigateRightClicked( event ) { event.preventDefault(); onUserInput(); navigateRight(); }
  2985. function onNavigateUpClicked( event ) { event.preventDefault(); onUserInput(); navigateUp(); }
  2986. function onNavigateDownClicked( event ) { event.preventDefault(); onUserInput(); navigateDown(); }
  2987. function onNavigatePrevClicked( event ) { event.preventDefault(); onUserInput(); navigatePrev(); }
  2988. function onNavigateNextClicked( event ) { event.preventDefault(); onUserInput(); navigateNext(); }
  2989. /**
  2990. * Handler for the window level 'hashchange' event.
  2991. */
  2992. function onWindowHashChange( event ) {
  2993. readURL();
  2994. }
  2995. /**
  2996. * Handler for the window level 'resize' event.
  2997. */
  2998. function onWindowResize( event ) {
  2999. layout();
  3000. }
  3001. /**
  3002. * Handle for the window level 'visibilitychange' event.
  3003. */
  3004. function onPageVisibilityChange( event ) {
  3005. var isHidden = document.webkitHidden ||
  3006. document.msHidden ||
  3007. document.hidden;
  3008. // If, after clicking a link or similar and we're coming back,
  3009. // focus the document.body to ensure we can use keyboard shortcuts
  3010. if( isHidden === false && document.activeElement !== document.body ) {
  3011. document.activeElement.blur();
  3012. document.body.focus();
  3013. }
  3014. }
  3015. /**
  3016. * Invoked when a slide is and we're in the overview.
  3017. */
  3018. function onOverviewSlideClicked( event ) {
  3019. // TODO There's a bug here where the event listeners are not
  3020. // removed after deactivating the overview.
  3021. if( eventsAreBound && isOverview() ) {
  3022. event.preventDefault();
  3023. var element = event.target;
  3024. while( element && !element.nodeName.match( /section/gi ) ) {
  3025. element = element.parentNode;
  3026. }
  3027. if( element && !element.classList.contains( 'disabled' ) ) {
  3028. deactivateOverview();
  3029. if( element.nodeName.match( /section/gi ) ) {
  3030. var h = parseInt( element.getAttribute( 'data-index-h' ), 10 ),
  3031. v = parseInt( element.getAttribute( 'data-index-v' ), 10 );
  3032. slide( h, v );
  3033. }
  3034. }
  3035. }
  3036. }
  3037. /**
  3038. * Handles clicks on links that are set to preview in the
  3039. * iframe overlay.
  3040. */
  3041. function onPreviewLinkClicked( event ) {
  3042. if( event.currentTarget && event.currentTarget.hasAttribute( 'href' ) ) {
  3043. var url = event.currentTarget.getAttribute( 'href' );
  3044. if( url ) {
  3045. showPreview( url );
  3046. event.preventDefault();
  3047. }
  3048. }
  3049. }
  3050. /**
  3051. * Handles click on the auto-sliding controls element.
  3052. */
  3053. function onAutoSlidePlayerClick( event ) {
  3054. // Replay
  3055. if( Reveal.isLastSlide() && config.loop === false ) {
  3056. slide( 0, 0 );
  3057. resumeAutoSlide();
  3058. }
  3059. // Resume
  3060. else if( autoSlidePaused ) {
  3061. resumeAutoSlide();
  3062. }
  3063. // Pause
  3064. else {
  3065. pauseAutoSlide();
  3066. }
  3067. }
  3068. // --------------------------------------------------------------------//
  3069. // ------------------------ PLAYBACK COMPONENT ------------------------//
  3070. // --------------------------------------------------------------------//
  3071. /**
  3072. * Constructor for the playback component, which displays
  3073. * play/pause/progress controls.
  3074. *
  3075. * @param {HTMLElement} container The component will append
  3076. * itself to this
  3077. * @param {Function} progressCheck A method which will be
  3078. * called frequently to get the current progress on a range
  3079. * of 0-1
  3080. */
  3081. function Playback( container, progressCheck ) {
  3082. // Cosmetics
  3083. this.diameter = 50;
  3084. this.thickness = 3;
  3085. // Flags if we are currently playing
  3086. this.playing = false;
  3087. // Current progress on a 0-1 range
  3088. this.progress = 0;
  3089. // Used to loop the animation smoothly
  3090. this.progressOffset = 1;
  3091. this.container = container;
  3092. this.progressCheck = progressCheck;
  3093. this.canvas = document.createElement( 'canvas' );
  3094. this.canvas.className = 'playback';
  3095. this.canvas.width = this.diameter;
  3096. this.canvas.height = this.diameter;
  3097. this.context = this.canvas.getContext( '2d' );
  3098. this.container.appendChild( this.canvas );
  3099. this.render();
  3100. }
  3101. Playback.prototype.setPlaying = function( value ) {
  3102. var wasPlaying = this.playing;
  3103. this.playing = value;
  3104. // Start repainting if we weren't already
  3105. if( !wasPlaying && this.playing ) {
  3106. this.animate();
  3107. }
  3108. else {
  3109. this.render();
  3110. }
  3111. };
  3112. Playback.prototype.animate = function() {
  3113. var progressBefore = this.progress;
  3114. this.progress = this.progressCheck();
  3115. // When we loop, offset the progress so that it eases
  3116. // smoothly rather than immediately resetting
  3117. if( progressBefore > 0.8 && this.progress < 0.2 ) {
  3118. this.progressOffset = this.progress;
  3119. }
  3120. this.render();
  3121. if( this.playing ) {
  3122. features.requestAnimationFrameMethod.call( window, this.animate.bind( this ) );
  3123. }
  3124. };
  3125. /**
  3126. * Renders the current progress and playback state.
  3127. */
  3128. Playback.prototype.render = function() {
  3129. var progress = this.playing ? this.progress : 0,
  3130. radius = ( this.diameter / 2 ) - this.thickness,
  3131. x = this.diameter / 2,
  3132. y = this.diameter / 2,
  3133. iconSize = 14;
  3134. // Ease towards 1
  3135. this.progressOffset += ( 1 - this.progressOffset ) * 0.1;
  3136. var endAngle = ( - Math.PI / 2 ) + ( progress * ( Math.PI * 2 ) );
  3137. var startAngle = ( - Math.PI / 2 ) + ( this.progressOffset * ( Math.PI * 2 ) );
  3138. this.context.save();
  3139. this.context.clearRect( 0, 0, this.diameter, this.diameter );
  3140. // Solid background color
  3141. this.context.beginPath();
  3142. this.context.arc( x, y, radius + 2, 0, Math.PI * 2, false );
  3143. this.context.fillStyle = 'rgba( 0, 0, 0, 0.4 )';
  3144. this.context.fill();
  3145. // Draw progress track
  3146. this.context.beginPath();
  3147. this.context.arc( x, y, radius, 0, Math.PI * 2, false );
  3148. this.context.lineWidth = this.thickness;
  3149. this.context.strokeStyle = '#666';
  3150. this.context.stroke();
  3151. if( this.playing ) {
  3152. // Draw progress on top of track
  3153. this.context.beginPath();
  3154. this.context.arc( x, y, radius, startAngle, endAngle, false );
  3155. this.context.lineWidth = this.thickness;
  3156. this.context.strokeStyle = '#fff';
  3157. this.context.stroke();
  3158. }
  3159. this.context.translate( x - ( iconSize / 2 ), y - ( iconSize / 2 ) );
  3160. // Draw play/pause icons
  3161. if( this.playing ) {
  3162. this.context.fillStyle = '#fff';
  3163. this.context.fillRect( 0, 0, iconSize / 2 - 2, iconSize );
  3164. this.context.fillRect( iconSize / 2 + 2, 0, iconSize / 2 - 2, iconSize );
  3165. }
  3166. else {
  3167. this.context.beginPath();
  3168. this.context.translate( 2, 0 );
  3169. this.context.moveTo( 0, 0 );
  3170. this.context.lineTo( iconSize - 2, iconSize / 2 );
  3171. this.context.lineTo( 0, iconSize );
  3172. this.context.fillStyle = '#fff';
  3173. this.context.fill();
  3174. }
  3175. this.context.restore();
  3176. };
  3177. Playback.prototype.on = function( type, listener ) {
  3178. this.canvas.addEventListener( type, listener, false );
  3179. };
  3180. Playback.prototype.off = function( type, listener ) {
  3181. this.canvas.removeEventListener( type, listener, false );
  3182. };
  3183. Playback.prototype.destroy = function() {
  3184. this.playing = false;
  3185. if( this.canvas.parentNode ) {
  3186. this.container.removeChild( this.canvas );
  3187. }
  3188. };
  3189. // --------------------------------------------------------------------//
  3190. // ------------------------------- API --------------------------------//
  3191. // --------------------------------------------------------------------//
  3192. Reveal = {
  3193. initialize: initialize,
  3194. configure: configure,
  3195. sync: sync,
  3196. // Navigation methods
  3197. slide: slide,
  3198. left: navigateLeft,
  3199. right: navigateRight,
  3200. up: navigateUp,
  3201. down: navigateDown,
  3202. prev: navigatePrev,
  3203. next: navigateNext,
  3204. // Fragment methods
  3205. navigateFragment: navigateFragment,
  3206. prevFragment: previousFragment,
  3207. nextFragment: nextFragment,
  3208. // Deprecated aliases
  3209. navigateTo: slide,
  3210. navigateLeft: navigateLeft,
  3211. navigateRight: navigateRight,
  3212. navigateUp: navigateUp,
  3213. navigateDown: navigateDown,
  3214. navigatePrev: navigatePrev,
  3215. navigateNext: navigateNext,
  3216. // Forces an update in slide layout
  3217. layout: layout,
  3218. // Returns an object with the available routes as booleans (left/right/top/bottom)
  3219. availableRoutes: availableRoutes,
  3220. // Returns an object with the available fragments as booleans (prev/next)
  3221. availableFragments: availableFragments,
  3222. // Toggles the overview mode on/off
  3223. toggleOverview: toggleOverview,
  3224. // Toggles the "black screen" mode on/off
  3225. togglePause: togglePause,
  3226. // Toggles the auto slide mode on/off
  3227. toggleAutoSlide: toggleAutoSlide,
  3228. // State checks
  3229. isOverview: isOverview,
  3230. isPaused: isPaused,
  3231. isAutoSliding: isAutoSliding,
  3232. // Adds or removes all internal event listeners (such as keyboard)
  3233. addEventListeners: addEventListeners,
  3234. removeEventListeners: removeEventListeners,
  3235. // Facility for persisting and restoring the presentation state
  3236. getState: getState,
  3237. setState: setState,
  3238. // Presentation progress on range of 0-1
  3239. getProgress: getProgress,
  3240. // Returns the indices of the current, or specified, slide
  3241. getIndices: getIndices,
  3242. getTotalSlides: getTotalSlides,
  3243. // Returns the slide element at the specified index
  3244. getSlide: getSlide,
  3245. // Returns the slide background element at the specified index
  3246. getSlideBackground: getSlideBackground,
  3247. // Returns the previous slide element, may be null
  3248. getPreviousSlide: function() {
  3249. return previousSlide;
  3250. },
  3251. // Returns the current slide element
  3252. getCurrentSlide: function() {
  3253. return currentSlide;
  3254. },
  3255. // Returns the current scale of the presentation content
  3256. getScale: function() {
  3257. return scale;
  3258. },
  3259. // Returns the current configuration object
  3260. getConfig: function() {
  3261. return config;
  3262. },
  3263. // Helper method, retrieves query string as a key/value hash
  3264. getQueryHash: function() {
  3265. var query = {};
  3266. location.search.replace( /[A-Z0-9]+?=([\w\.%-]*)/gi, function(a) {
  3267. query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
  3268. } );
  3269. // Basic deserialization
  3270. for( var i in query ) {
  3271. var value = query[ i ];
  3272. query[ i ] = deserialize( unescape( value ) );
  3273. }
  3274. return query;
  3275. },
  3276. // Returns true if we're currently on the first slide
  3277. isFirstSlide: function() {
  3278. return ( indexh === 0 && indexv === 0 );
  3279. },
  3280. // Returns true if we're currently on the last slide
  3281. isLastSlide: function() {
  3282. if( currentSlide ) {
  3283. // Does this slide has next a sibling?
  3284. if( currentSlide.nextElementSibling ) return false;
  3285. // If it's vertical, does its parent have a next sibling?
  3286. if( isVerticalSlide( currentSlide ) && currentSlide.parentNode.nextElementSibling ) return false;
  3287. return true;
  3288. }
  3289. return false;
  3290. },
  3291. // Checks if reveal.js has been loaded and is ready for use
  3292. isReady: function() {
  3293. return loaded;
  3294. },
  3295. // Forward event binding to the reveal DOM element
  3296. addEventListener: function( type, listener, useCapture ) {
  3297. if( 'addEventListener' in window ) {
  3298. ( dom.wrapper || document.querySelector( '.reveal' ) ).addEventListener( type, listener, useCapture );
  3299. }
  3300. },
  3301. removeEventListener: function( type, listener, useCapture ) {
  3302. if( 'addEventListener' in window ) {
  3303. ( dom.wrapper || document.querySelector( '.reveal' ) ).removeEventListener( type, listener, useCapture );
  3304. }
  3305. },
  3306. // Programatically triggers a keyboard event
  3307. triggerKey: function( keyCode ) {
  3308. onDocumentKeyDown( { keyCode: keyCode } );
  3309. }
  3310. };
  3311. return Reveal;
  3312. }));