You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

891 lines
23 KiB

  1. <!--
  2. NOTE: You need to build the notes plugin after making changes to this file.
  3. -->
  4. <html lang="en">
  5. <head>
  6. <meta charset="utf-8">
  7. <title>reveal.js - Speaker View</title>
  8. <style>
  9. body {
  10. font-family: Helvetica;
  11. font-size: 18px;
  12. }
  13. #current-slide,
  14. #upcoming-slide,
  15. #speaker-controls {
  16. padding: 6px;
  17. box-sizing: border-box;
  18. -moz-box-sizing: border-box;
  19. }
  20. #current-slide iframe,
  21. #upcoming-slide iframe {
  22. width: 100%;
  23. height: 100%;
  24. border: 1px solid #ddd;
  25. }
  26. #current-slide .label,
  27. #upcoming-slide .label {
  28. position: absolute;
  29. top: 10px;
  30. left: 10px;
  31. z-index: 2;
  32. }
  33. #connection-status {
  34. position: absolute;
  35. top: 0;
  36. left: 0;
  37. width: 100%;
  38. height: 100%;
  39. z-index: 20;
  40. padding: 30% 20% 20% 20%;
  41. font-size: 18px;
  42. color: #222;
  43. background: #fff;
  44. text-align: center;
  45. box-sizing: border-box;
  46. line-height: 1.4;
  47. }
  48. .overlay-element {
  49. height: 34px;
  50. line-height: 34px;
  51. padding: 0 10px;
  52. text-shadow: none;
  53. background: rgba( 220, 220, 220, 0.8 );
  54. color: #222;
  55. font-size: 14px;
  56. }
  57. .overlay-element.interactive:hover {
  58. background: rgba( 220, 220, 220, 1 );
  59. }
  60. #current-slide {
  61. position: absolute;
  62. width: 60%;
  63. height: 100%;
  64. top: 0;
  65. left: 0;
  66. padding-right: 0;
  67. }
  68. #upcoming-slide {
  69. position: absolute;
  70. width: 40%;
  71. height: 40%;
  72. right: 0;
  73. top: 0;
  74. }
  75. /* Speaker controls */
  76. #speaker-controls {
  77. position: absolute;
  78. top: 40%;
  79. right: 0;
  80. width: 40%;
  81. height: 60%;
  82. overflow: auto;
  83. font-size: 18px;
  84. }
  85. .speaker-controls-time.hidden,
  86. .speaker-controls-notes.hidden {
  87. display: none;
  88. }
  89. .speaker-controls-time .label,
  90. .speaker-controls-pace .label,
  91. .speaker-controls-notes .label {
  92. text-transform: uppercase;
  93. font-weight: normal;
  94. font-size: 0.66em;
  95. color: #666;
  96. margin: 0;
  97. }
  98. .speaker-controls-time, .speaker-controls-pace {
  99. border-bottom: 1px solid rgba( 200, 200, 200, 0.5 );
  100. margin-bottom: 10px;
  101. padding: 10px 16px;
  102. padding-bottom: 20px;
  103. cursor: pointer;
  104. }
  105. .speaker-controls-time .reset-button {
  106. opacity: 0;
  107. float: right;
  108. color: #666;
  109. text-decoration: none;
  110. }
  111. .speaker-controls-time:hover .reset-button {
  112. opacity: 1;
  113. }
  114. .speaker-controls-time .timer,
  115. .speaker-controls-time .clock {
  116. width: 50%;
  117. }
  118. .speaker-controls-time .timer,
  119. .speaker-controls-time .clock,
  120. .speaker-controls-time .pacing .hours-value,
  121. .speaker-controls-time .pacing .minutes-value,
  122. .speaker-controls-time .pacing .seconds-value {
  123. font-size: 1.9em;
  124. }
  125. .speaker-controls-time .timer {
  126. float: left;
  127. }
  128. .speaker-controls-time .clock {
  129. float: right;
  130. text-align: right;
  131. }
  132. .speaker-controls-time span.mute {
  133. opacity: 0.3;
  134. }
  135. .speaker-controls-time .pacing-title {
  136. margin-top: 5px;
  137. }
  138. .speaker-controls-time .pacing.ahead {
  139. color: blue;
  140. }
  141. .speaker-controls-time .pacing.on-track {
  142. color: green;
  143. }
  144. .speaker-controls-time .pacing.behind {
  145. color: red;
  146. }
  147. .speaker-controls-notes {
  148. padding: 10px 16px;
  149. }
  150. .speaker-controls-notes .value {
  151. margin-top: 5px;
  152. line-height: 1.4;
  153. font-size: 1.2em;
  154. }
  155. /* Layout selector */
  156. #speaker-layout {
  157. position: absolute;
  158. top: 10px;
  159. right: 10px;
  160. color: #222;
  161. z-index: 10;
  162. }
  163. #speaker-layout select {
  164. position: absolute;
  165. width: 100%;
  166. height: 100%;
  167. top: 0;
  168. left: 0;
  169. border: 0;
  170. box-shadow: 0;
  171. cursor: pointer;
  172. opacity: 0;
  173. font-size: 1em;
  174. background-color: transparent;
  175. -moz-appearance: none;
  176. -webkit-appearance: none;
  177. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  178. }
  179. #speaker-layout select:focus {
  180. outline: none;
  181. box-shadow: none;
  182. }
  183. .clear {
  184. clear: both;
  185. }
  186. /* Speaker layout: Wide */
  187. body[data-speaker-layout="wide"] #current-slide,
  188. body[data-speaker-layout="wide"] #upcoming-slide {
  189. width: 50%;
  190. height: 45%;
  191. padding: 6px;
  192. }
  193. body[data-speaker-layout="wide"] #current-slide {
  194. top: 0;
  195. left: 0;
  196. }
  197. body[data-speaker-layout="wide"] #upcoming-slide {
  198. top: 0;
  199. left: 50%;
  200. }
  201. body[data-speaker-layout="wide"] #speaker-controls {
  202. top: 45%;
  203. left: 0;
  204. width: 100%;
  205. height: 50%;
  206. font-size: 1.25em;
  207. }
  208. /* Speaker layout: Tall */
  209. body[data-speaker-layout="tall"] #current-slide,
  210. body[data-speaker-layout="tall"] #upcoming-slide {
  211. width: 45%;
  212. height: 50%;
  213. padding: 6px;
  214. }
  215. body[data-speaker-layout="tall"] #current-slide {
  216. top: 0;
  217. left: 0;
  218. }
  219. body[data-speaker-layout="tall"] #upcoming-slide {
  220. top: 50%;
  221. left: 0;
  222. }
  223. body[data-speaker-layout="tall"] #speaker-controls {
  224. padding-top: 40px;
  225. top: 0;
  226. left: 45%;
  227. width: 55%;
  228. height: 100%;
  229. font-size: 1.25em;
  230. }
  231. /* Speaker layout: Notes only */
  232. body[data-speaker-layout="notes-only"] #current-slide,
  233. body[data-speaker-layout="notes-only"] #upcoming-slide {
  234. display: none;
  235. }
  236. body[data-speaker-layout="notes-only"] #speaker-controls {
  237. padding-top: 40px;
  238. top: 0;
  239. left: 0;
  240. width: 100%;
  241. height: 100%;
  242. font-size: 1.25em;
  243. }
  244. @media screen and (max-width: 1080px) {
  245. body[data-speaker-layout="default"] #speaker-controls {
  246. font-size: 16px;
  247. }
  248. }
  249. @media screen and (max-width: 900px) {
  250. body[data-speaker-layout="default"] #speaker-controls {
  251. font-size: 14px;
  252. }
  253. }
  254. @media screen and (max-width: 800px) {
  255. body[data-speaker-layout="default"] #speaker-controls {
  256. font-size: 12px;
  257. }
  258. }
  259. </style>
  260. </head>
  261. <body>
  262. <div id="connection-status">Loading speaker view...</div>
  263. <div id="current-slide"></div>
  264. <div id="upcoming-slide"><span class="overlay-element label">Upcoming</span></div>
  265. <div id="speaker-controls">
  266. <div class="speaker-controls-time">
  267. <h4 class="label">Time <span class="reset-button">Click to Reset</span></h4>
  268. <div class="clock">
  269. <span class="clock-value">0:00 AM</span>
  270. </div>
  271. <div class="timer">
  272. <span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span>
  273. </div>
  274. <div class="clear"></div>
  275. <h4 class="label pacing-title" style="display: none">Pacing – Time to finish current slide</h4>
  276. <div class="pacing" style="display: none">
  277. <span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span>
  278. </div>
  279. </div>
  280. <div class="speaker-controls-notes hidden">
  281. <h4 class="label">Notes</h4>
  282. <div class="value"></div>
  283. </div>
  284. </div>
  285. <div id="speaker-layout" class="overlay-element interactive">
  286. <span class="speaker-layout-label"></span>
  287. <select class="speaker-layout-dropdown"></select>
  288. </div>
  289. <script>
  290. (function() {
  291. var notes,
  292. notesValue,
  293. currentState,
  294. currentSlide,
  295. upcomingSlide,
  296. layoutLabel,
  297. layoutDropdown,
  298. pendingCalls = {},
  299. lastRevealApiCallId = 0,
  300. connected = false
  301. var connectionStatus = document.querySelector( '#connection-status' );
  302. var SPEAKER_LAYOUTS = {
  303. 'default': 'Default',
  304. 'wide': 'Wide',
  305. 'tall': 'Tall',
  306. 'notes-only': 'Notes only'
  307. };
  308. setupLayout();
  309. let openerOrigin;
  310. try {
  311. openerOrigin = window.opener.location.origin;
  312. }
  313. catch ( error ) { console.warn( error ) }
  314. // In order to prevent XSS, the speaker view will only run if its
  315. // opener has the same origin as itself
  316. if( window.location.origin !== openerOrigin ) {
  317. connectionStatus.innerHTML = 'Cross origin error.<br>The speaker window can only be opened from the same origin.';
  318. return;
  319. }
  320. var connectionTimeout = setTimeout( function() {
  321. connectionStatus.innerHTML = 'Error connecting to main window.<br>Please try closing and reopening the speaker view.';
  322. }, 5000 );
  323. window.addEventListener( 'message', function( event ) {
  324. clearTimeout( connectionTimeout );
  325. connectionStatus.style.display = 'none';
  326. var data = JSON.parse( event.data );
  327. // The overview mode is only useful to the reveal.js instance
  328. // where navigation occurs so we don't sync it
  329. if( data.state ) delete data.state.overview;
  330. // Messages sent by the notes plugin inside of the main window
  331. if( data && data.namespace === 'reveal-notes' ) {
  332. if( data.type === 'connect' ) {
  333. handleConnectMessage( data );
  334. }
  335. else if( data.type === 'state' ) {
  336. handleStateMessage( data );
  337. }
  338. else if( data.type === 'return' ) {
  339. pendingCalls[data.callId](data.result);
  340. delete pendingCalls[data.callId];
  341. }
  342. }
  343. // Messages sent by the reveal.js inside of the current slide preview
  344. else if( data && data.namespace === 'reveal' ) {
  345. if( /ready/.test( data.eventName ) ) {
  346. // Send a message back to notify that the handshake is complete
  347. window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'connected'} ), '*' );
  348. }
  349. else if( /slidechanged|fragmentshown|fragmenthidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) {
  350. dispatchStateToMainWindow( data.state );
  351. }
  352. }
  353. } );
  354. /**
  355. * Updates the presentation in the main window to match the state
  356. * of the presentation in the notes window.
  357. */
  358. const dispatchStateToMainWindow = debounce(( state ) => {
  359. window.opener.postMessage( JSON.stringify({ method: 'setState', args: [ state ]} ), '*' );
  360. }, 500);
  361. /**
  362. * Asynchronously calls the Reveal.js API of the main frame.
  363. */
  364. function callRevealApi( methodName, methodArguments, callback ) {
  365. var callId = ++lastRevealApiCallId;
  366. pendingCalls[callId] = callback;
  367. window.opener.postMessage( JSON.stringify( {
  368. namespace: 'reveal-notes',
  369. type: 'call',
  370. callId: callId,
  371. methodName: methodName,
  372. arguments: methodArguments
  373. } ), '*' );
  374. }
  375. /**
  376. * Called when the main window is trying to establish a
  377. * connection.
  378. */
  379. function handleConnectMessage( data ) {
  380. if( connected === false ) {
  381. connected = true;
  382. setupIframes( data );
  383. setupKeyboard();
  384. setupNotes();
  385. setupTimer();
  386. setupHeartbeat();
  387. }
  388. }
  389. /**
  390. * Called when the main window sends an updated state.
  391. */
  392. function handleStateMessage( data ) {
  393. // Store the most recently set state to avoid circular loops
  394. // applying the same state
  395. currentState = JSON.stringify( data.state );
  396. // No need for updating the notes in case of fragment changes
  397. if ( data.notes ) {
  398. notes.classList.remove( 'hidden' );
  399. notesValue.style.whiteSpace = data.whitespace;
  400. if( data.markdown ) {
  401. notesValue.innerHTML = marked( data.notes );
  402. }
  403. else {
  404. notesValue.innerHTML = data.notes;
  405. }
  406. }
  407. else {
  408. notes.classList.add( 'hidden' );
  409. }
  410. // Update the note slides
  411. currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  412. upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  413. upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'next' }), '*' );
  414. }
  415. // Limit to max one state update per X ms
  416. handleStateMessage = debounce( handleStateMessage, 200 );
  417. /**
  418. * Forward keyboard events to the current slide window.
  419. * This enables keyboard events to work even if focus
  420. * isn't set on the current slide iframe.
  421. *
  422. * Block F5 default handling, it reloads and disconnects
  423. * the speaker notes window.
  424. */
  425. function setupKeyboard() {
  426. document.addEventListener( 'keydown', function( event ) {
  427. if( event.keyCode === 116 || ( event.metaKey && event.keyCode === 82 ) ) {
  428. event.preventDefault();
  429. return false;
  430. }
  431. currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'triggerKey', args: [ event.keyCode ] }), '*' );
  432. } );
  433. }
  434. /**
  435. * Creates the preview iframes.
  436. */
  437. function setupIframes( data ) {
  438. var params = [
  439. 'receiver',
  440. 'progress=false',
  441. 'history=false',
  442. 'transition=none',
  443. 'autoSlide=0',
  444. 'backgroundTransition=none'
  445. ].join( '&' );
  446. var urlSeparator = /\?/.test(data.url) ? '&' : '?';
  447. var hash = '#/' + data.state.indexh + '/' + data.state.indexv;
  448. var currentURL = data.url + urlSeparator + params + '&postMessageEvents=true' + hash;
  449. var upcomingURL = data.url + urlSeparator + params + '&controls=false' + hash;
  450. currentSlide = document.createElement( 'iframe' );
  451. currentSlide.setAttribute( 'width', 1280 );
  452. currentSlide.setAttribute( 'height', 1024 );
  453. currentSlide.setAttribute( 'src', currentURL );
  454. document.querySelector( '#current-slide' ).appendChild( currentSlide );
  455. upcomingSlide = document.createElement( 'iframe' );
  456. upcomingSlide.setAttribute( 'width', 640 );
  457. upcomingSlide.setAttribute( 'height', 512 );
  458. upcomingSlide.setAttribute( 'src', upcomingURL );
  459. document.querySelector( '#upcoming-slide' ).appendChild( upcomingSlide );
  460. }
  461. /**
  462. * Setup the notes UI.
  463. */
  464. function setupNotes() {
  465. notes = document.querySelector( '.speaker-controls-notes' );
  466. notesValue = document.querySelector( '.speaker-controls-notes .value' );
  467. }
  468. /**
  469. * We send out a heartbeat at all times to ensure we can
  470. * reconnect with the main presentation window after reloads.
  471. */
  472. function setupHeartbeat() {
  473. setInterval( () => {
  474. window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'heartbeat'} ), '*' );
  475. }, 1000 );
  476. }
  477. function getTimings( callback ) {
  478. callRevealApi( 'getSlidesAttributes', [], function ( slideAttributes ) {
  479. callRevealApi( 'getConfig', [], function ( config ) {
  480. var totalTime = config.totalTime;
  481. var minTimePerSlide = config.minimumTimePerSlide || 0;
  482. var defaultTiming = config.defaultTiming;
  483. if ((defaultTiming == null) && (totalTime == null)) {
  484. callback(null);
  485. return;
  486. }
  487. // Setting totalTime overrides defaultTiming
  488. if (totalTime) {
  489. defaultTiming = 0;
  490. }
  491. var timings = [];
  492. for ( var i in slideAttributes ) {
  493. var slide = slideAttributes[ i ];
  494. var timing = defaultTiming;
  495. if( slide.hasOwnProperty( 'data-timing' )) {
  496. var t = slide[ 'data-timing' ];
  497. timing = parseInt(t);
  498. if( isNaN(timing) ) {
  499. console.warn("Could not parse timing '" + t + "' of slide " + i + "; using default of " + defaultTiming);
  500. timing = defaultTiming;
  501. }
  502. }
  503. timings.push(timing);
  504. }
  505. if ( totalTime ) {
  506. // After we've allocated time to individual slides, we summarize it and
  507. // subtract it from the total time
  508. var remainingTime = totalTime - timings.reduce( function(a, b) { return a + b; }, 0 );
  509. // The remaining time is divided by the number of slides that have 0 seconds
  510. // allocated at the moment, giving the average time-per-slide on the remaining slides
  511. var remainingSlides = (timings.filter( function(x) { return x == 0 }) ).length
  512. var timePerSlide = Math.round( remainingTime / remainingSlides, 0 )
  513. // And now we replace every zero-value timing with that average
  514. timings = timings.map( function(x) { return (x==0 ? timePerSlide : x) } );
  515. }
  516. var slidesUnderMinimum = timings.filter( function(x) { return (x < minTimePerSlide) } ).length
  517. if ( slidesUnderMinimum ) {
  518. message = "The pacing time for " + slidesUnderMinimum + " slide(s) is under the configured minimum of " + minTimePerSlide + " seconds. Check the data-timing attribute on individual slides, or consider increasing the totalTime or minimumTimePerSlide configuration options (or removing some slides).";
  519. alert(message);
  520. }
  521. callback( timings );
  522. } );
  523. } );
  524. }
  525. /**
  526. * Return the number of seconds allocated for presenting
  527. * all slides up to and including this one.
  528. */
  529. function getTimeAllocated( timings, callback ) {
  530. callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) {
  531. var allocated = 0;
  532. for (var i in timings.slice(0, currentSlide + 1)) {
  533. allocated += timings[i];
  534. }
  535. callback( allocated );
  536. } );
  537. }
  538. /**
  539. * Create the timer and clock and start updating them
  540. * at an interval.
  541. */
  542. function setupTimer() {
  543. var start = new Date(),
  544. timeEl = document.querySelector( '.speaker-controls-time' ),
  545. clockEl = timeEl.querySelector( '.clock-value' ),
  546. hoursEl = timeEl.querySelector( '.hours-value' ),
  547. minutesEl = timeEl.querySelector( '.minutes-value' ),
  548. secondsEl = timeEl.querySelector( '.seconds-value' ),
  549. pacingTitleEl = timeEl.querySelector( '.pacing-title' ),
  550. pacingEl = timeEl.querySelector( '.pacing' ),
  551. pacingHoursEl = pacingEl.querySelector( '.hours-value' ),
  552. pacingMinutesEl = pacingEl.querySelector( '.minutes-value' ),
  553. pacingSecondsEl = pacingEl.querySelector( '.seconds-value' );
  554. var timings = null;
  555. getTimings( function ( _timings ) {
  556. timings = _timings;
  557. if (_timings !== null) {
  558. pacingTitleEl.style.removeProperty('display');
  559. pacingEl.style.removeProperty('display');
  560. }
  561. // Update once directly
  562. _updateTimer();
  563. // Then update every second
  564. setInterval( _updateTimer, 1000 );
  565. } );
  566. function _resetTimer() {
  567. if (timings == null) {
  568. start = new Date();
  569. _updateTimer();
  570. }
  571. else {
  572. // Reset timer to beginning of current slide
  573. getTimeAllocated( timings, function ( slideEndTimingSeconds ) {
  574. var slideEndTiming = slideEndTimingSeconds * 1000;
  575. callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) {
  576. var currentSlideTiming = timings[currentSlide] * 1000;
  577. var previousSlidesTiming = slideEndTiming - currentSlideTiming;
  578. var now = new Date();
  579. start = new Date(now.getTime() - previousSlidesTiming);
  580. _updateTimer();
  581. } );
  582. } );
  583. }
  584. }
  585. timeEl.addEventListener( 'click', function() {
  586. _resetTimer();
  587. return false;
  588. } );
  589. function _displayTime( hrEl, minEl, secEl, time) {
  590. var sign = Math.sign(time) == -1 ? "-" : "";
  591. time = Math.abs(Math.round(time / 1000));
  592. var seconds = time % 60;
  593. var minutes = Math.floor( time / 60 ) % 60 ;
  594. var hours = Math.floor( time / ( 60 * 60 )) ;
  595. hrEl.innerHTML = sign + zeroPadInteger( hours );
  596. if (hours == 0) {
  597. hrEl.classList.add( 'mute' );
  598. }
  599. else {
  600. hrEl.classList.remove( 'mute' );
  601. }
  602. minEl.innerHTML = ':' + zeroPadInteger( minutes );
  603. if (hours == 0 && minutes == 0) {
  604. minEl.classList.add( 'mute' );
  605. }
  606. else {
  607. minEl.classList.remove( 'mute' );
  608. }
  609. secEl.innerHTML = ':' + zeroPadInteger( seconds );
  610. }
  611. function _updateTimer() {
  612. var diff, hours, minutes, seconds,
  613. now = new Date();
  614. diff = now.getTime() - start.getTime();
  615. clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } );
  616. _displayTime( hoursEl, minutesEl, secondsEl, diff );
  617. if (timings !== null) {
  618. _updatePacing(diff);
  619. }
  620. }
  621. function _updatePacing(diff) {
  622. getTimeAllocated( timings, function ( slideEndTimingSeconds ) {
  623. var slideEndTiming = slideEndTimingSeconds * 1000;
  624. callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) {
  625. var currentSlideTiming = timings[currentSlide] * 1000;
  626. var timeLeftCurrentSlide = slideEndTiming - diff;
  627. if (timeLeftCurrentSlide < 0) {
  628. pacingEl.className = 'pacing behind';
  629. }
  630. else if (timeLeftCurrentSlide < currentSlideTiming) {
  631. pacingEl.className = 'pacing on-track';
  632. }
  633. else {
  634. pacingEl.className = 'pacing ahead';
  635. }
  636. _displayTime( pacingHoursEl, pacingMinutesEl, pacingSecondsEl, timeLeftCurrentSlide );
  637. } );
  638. } );
  639. }
  640. }
  641. /**
  642. * Sets up the speaker view layout and layout selector.
  643. */
  644. function setupLayout() {
  645. layoutDropdown = document.querySelector( '.speaker-layout-dropdown' );
  646. layoutLabel = document.querySelector( '.speaker-layout-label' );
  647. // Render the list of available layouts
  648. for( var id in SPEAKER_LAYOUTS ) {
  649. var option = document.createElement( 'option' );
  650. option.setAttribute( 'value', id );
  651. option.textContent = SPEAKER_LAYOUTS[ id ];
  652. layoutDropdown.appendChild( option );
  653. }
  654. // Monitor the dropdown for changes
  655. layoutDropdown.addEventListener( 'change', function( event ) {
  656. setLayout( layoutDropdown.value );
  657. }, false );
  658. // Restore any currently persisted layout
  659. setLayout( getLayout() );
  660. }
  661. /**
  662. * Sets a new speaker view layout. The layout is persisted
  663. * in local storage.
  664. */
  665. function setLayout( value ) {
  666. var title = SPEAKER_LAYOUTS[ value ];
  667. layoutLabel.innerHTML = 'Layout' + ( title ? ( ': ' + title ) : '' );
  668. layoutDropdown.value = value;
  669. document.body.setAttribute( 'data-speaker-layout', value );
  670. // Persist locally
  671. if( supportsLocalStorage() ) {
  672. window.localStorage.setItem( 'reveal-speaker-layout', value );
  673. }
  674. }
  675. /**
  676. * Returns the ID of the most recently set speaker layout
  677. * or our default layout if none has been set.
  678. */
  679. function getLayout() {
  680. if( supportsLocalStorage() ) {
  681. var layout = window.localStorage.getItem( 'reveal-speaker-layout' );
  682. if( layout ) {
  683. return layout;
  684. }
  685. }
  686. // Default to the first record in the layouts hash
  687. for( var id in SPEAKER_LAYOUTS ) {
  688. return id;
  689. }
  690. }
  691. function supportsLocalStorage() {
  692. try {
  693. localStorage.setItem('test', 'test');
  694. localStorage.removeItem('test');
  695. return true;
  696. }
  697. catch( e ) {
  698. return false;
  699. }
  700. }
  701. function zeroPadInteger( num ) {
  702. var str = '00' + parseInt( num );
  703. return str.substring( str.length - 2 );
  704. }
  705. /**
  706. * Limits the frequency at which a function can be called.
  707. */
  708. function debounce( fn, ms ) {
  709. var lastTime = 0,
  710. timeout;
  711. return function() {
  712. var args = arguments;
  713. var context = this;
  714. clearTimeout( timeout );
  715. var timeSinceLastCall = Date.now() - lastTime;
  716. if( timeSinceLastCall > ms ) {
  717. fn.apply( context, args );
  718. lastTime = Date.now();
  719. }
  720. else {
  721. timeout = setTimeout( function() {
  722. fn.apply( context, args );
  723. lastTime = Date.now();
  724. }, ms - timeSinceLastCall );
  725. }
  726. }
  727. }
  728. })();
  729. </script>
  730. </body>
  731. </html>