reveal.js 112 KB

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