notes.html 18 KB

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