notes.html 19 KB

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