notes.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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-notes .label {
  74. text-transform: uppercase;
  75. font-weight: normal;
  76. font-size: 0.66em;
  77. color: #666;
  78. margin: 0;
  79. }
  80. .speaker-controls-time {
  81. border-bottom: 1px solid rgba( 200, 200, 200, 0.5 );
  82. margin-bottom: 10px;
  83. padding: 10px 16px;
  84. padding-bottom: 20px;
  85. cursor: pointer;
  86. }
  87. .speaker-controls-time .reset-button {
  88. opacity: 0;
  89. float: right;
  90. color: #666;
  91. text-decoration: none;
  92. }
  93. .speaker-controls-time:hover .reset-button {
  94. opacity: 1;
  95. }
  96. .speaker-controls-time .timer,
  97. .speaker-controls-time .clock {
  98. width: 50%;
  99. font-size: 1.9em;
  100. }
  101. .speaker-controls-time .timer {
  102. float: left;
  103. }
  104. .speaker-controls-time .clock {
  105. float: right;
  106. text-align: right;
  107. }
  108. .speaker-controls-time span.mute {
  109. color: #bbb;
  110. }
  111. .speaker-controls-notes {
  112. padding: 10px 16px;
  113. }
  114. .speaker-controls-notes .value {
  115. margin-top: 5px;
  116. line-height: 1.4;
  117. font-size: 1.2em;
  118. }
  119. /* Layout selector */
  120. #speaker-layout {
  121. position: absolute;
  122. top: 10px;
  123. right: 10px;
  124. color: #222;
  125. z-index: 10;
  126. }
  127. #speaker-layout select {
  128. position: absolute;
  129. width: 100%;
  130. height: 100%;
  131. top: 0;
  132. left: 0;
  133. border: 0;
  134. box-shadow: 0;
  135. cursor: pointer;
  136. opacity: 0;
  137. font-size: 1em;
  138. background-color: transparent;
  139. -moz-appearance: none;
  140. -webkit-appearance: none;
  141. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  142. }
  143. #speaker-layout select:focus {
  144. outline: none;
  145. box-shadow: none;
  146. }
  147. .clear {
  148. clear: both;
  149. }
  150. /* Speaker layout: Wide */
  151. body[data-speaker-layout="wide"] #current-slide,
  152. body[data-speaker-layout="wide"] #upcoming-slide {
  153. width: 50%;
  154. height: 45%;
  155. padding: 6px;
  156. }
  157. body[data-speaker-layout="wide"] #current-slide {
  158. top: 0;
  159. left: 0;
  160. }
  161. body[data-speaker-layout="wide"] #upcoming-slide {
  162. top: 0;
  163. left: 50%;
  164. }
  165. body[data-speaker-layout="wide"] #speaker-controls {
  166. top: 45%;
  167. left: 0;
  168. width: 100%;
  169. height: 50%;
  170. font-size: 1.25em;
  171. }
  172. /* Speaker layout: Tall */
  173. body[data-speaker-layout="tall"] #current-slide,
  174. body[data-speaker-layout="tall"] #upcoming-slide {
  175. width: 45%;
  176. height: 50%;
  177. padding: 6px;
  178. }
  179. body[data-speaker-layout="tall"] #current-slide {
  180. top: 0;
  181. left: 0;
  182. }
  183. body[data-speaker-layout="tall"] #upcoming-slide {
  184. top: 50%;
  185. left: 0;
  186. }
  187. body[data-speaker-layout="tall"] #speaker-controls {
  188. padding-top: 40px;
  189. top: 0;
  190. left: 45%;
  191. width: 55%;
  192. height: 100%;
  193. font-size: 1.25em;
  194. }
  195. /* Speaker layout: Notes only */
  196. body[data-speaker-layout="notes-only"] #current-slide,
  197. body[data-speaker-layout="notes-only"] #upcoming-slide {
  198. display: none;
  199. }
  200. body[data-speaker-layout="notes-only"] #speaker-controls {
  201. padding-top: 40px;
  202. top: 0;
  203. left: 0;
  204. width: 100%;
  205. height: 100%;
  206. font-size: 1.25em;
  207. }
  208. @media screen and (max-width: 1080px) {
  209. body[data-speaker-layout="default"] #speaker-controls {
  210. font-size: 16px;
  211. }
  212. }
  213. @media screen and (max-width: 900px) {
  214. body[data-speaker-layout="default"] #speaker-controls {
  215. font-size: 14px;
  216. }
  217. }
  218. @media screen and (max-width: 800px) {
  219. body[data-speaker-layout="default"] #speaker-controls {
  220. font-size: 12px;
  221. }
  222. }
  223. </style>
  224. </head>
  225. <body>
  226. <div id="current-slide"></div>
  227. <div id="upcoming-slide"><span class="overlay-element label">Upcoming</span></div>
  228. <div id="speaker-controls">
  229. <div class="speaker-controls-time">
  230. <h4 class="label">Time <span class="reset-button">Click to Reset</span></h4>
  231. <div class="clock">
  232. <span class="clock-value">0:00 AM</span>
  233. </div>
  234. <div class="timer">
  235. <span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span>
  236. </div>
  237. <div class="clear"></div>
  238. </div>
  239. <div class="speaker-controls-notes hidden">
  240. <h4 class="label">Notes</h4>
  241. <div class="value"></div>
  242. </div>
  243. </div>
  244. <div id="speaker-layout" class="overlay-element interactive">
  245. <span class="speaker-layout-label"></span>
  246. <select class="speaker-layout-dropdown"></select>
  247. </div>
  248. <script src="../../plugin/markdown/marked.js"></script>
  249. <script>
  250. (function() {
  251. var notes,
  252. notesValue,
  253. currentState,
  254. currentSlide,
  255. upcomingSlide,
  256. layoutLabel,
  257. layoutDropdown,
  258. connected = false;
  259. var SPEAKER_LAYOUTS = {
  260. 'default': 'Default',
  261. 'wide': 'Wide',
  262. 'tall': 'Tall',
  263. 'notes-only': 'Notes only'
  264. };
  265. setupLayout();
  266. window.addEventListener( 'message', function( event ) {
  267. var data = JSON.parse( event.data );
  268. // The overview mode is only useful to the reveal.js instance
  269. // where navigation occurs so we don't sync it
  270. if( data.state ) delete data.state.overview;
  271. // Messages sent by the notes plugin inside of the main window
  272. if( data && data.namespace === 'reveal-notes' ) {
  273. if( data.type === 'connect' ) {
  274. handleConnectMessage( data );
  275. }
  276. else if( data.type === 'state' ) {
  277. handleStateMessage( data );
  278. }
  279. }
  280. // Messages sent by the reveal.js inside of the current slide preview
  281. else if( data && data.namespace === 'reveal' ) {
  282. if( /ready/.test( data.eventName ) ) {
  283. // Send a message back to notify that the handshake is complete
  284. window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'connected'} ), '*' );
  285. }
  286. else if( /slidechanged|fragmentshown|fragmenthidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) {
  287. window.opener.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ]} ), '*' );
  288. }
  289. }
  290. } );
  291. /**
  292. * Called when the main window is trying to establish a
  293. * connection.
  294. */
  295. function handleConnectMessage( data ) {
  296. if( connected === false ) {
  297. connected = true;
  298. setupIframes( data );
  299. setupKeyboard();
  300. setupNotes();
  301. setupTimer();
  302. }
  303. }
  304. /**
  305. * Called when the main window sends an updated state.
  306. */
  307. function handleStateMessage( data ) {
  308. // Store the most recently set state to avoid circular loops
  309. // applying the same state
  310. currentState = JSON.stringify( data.state );
  311. // No need for updating the notes in case of fragment changes
  312. if ( data.notes ) {
  313. notes.classList.remove( 'hidden' );
  314. notesValue.style.whiteSpace = data.whitespace;
  315. if( data.markdown ) {
  316. notesValue.innerHTML = marked( data.notes );
  317. }
  318. else {
  319. notesValue.innerHTML = data.notes;
  320. }
  321. }
  322. else {
  323. notes.classList.add( 'hidden' );
  324. }
  325. // Update the note slides
  326. currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  327. upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  328. upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'next' }), '*' );
  329. }
  330. // Limit to max one state update per X ms
  331. handleStateMessage = debounce( handleStateMessage, 200 );
  332. /**
  333. * Forward keyboard events to the current slide window.
  334. * This enables keyboard events to work even if focus
  335. * isn't set on the current slide iframe.
  336. */
  337. function setupKeyboard() {
  338. document.addEventListener( 'keydown', function( event ) {
  339. currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'triggerKey', args: [ event.keyCode ] }), '*' );
  340. } );
  341. }
  342. /**
  343. * Creates the preview iframes.
  344. */
  345. function setupIframes( data ) {
  346. var params = [
  347. 'receiver',
  348. 'progress=false',
  349. 'history=false',
  350. 'transition=none',
  351. 'autoSlide=0',
  352. 'backgroundTransition=none'
  353. ].join( '&' );
  354. var urlSeparator = /\?/.test(data.url) ? '&' : '?';
  355. var hash = '#/' + data.state.indexh + '/' + data.state.indexv;
  356. var currentURL = data.url + urlSeparator + params + '&postMessageEvents=true' + hash;
  357. var upcomingURL = data.url + urlSeparator + params + '&controls=false' + hash;
  358. currentSlide = document.createElement( 'iframe' );
  359. currentSlide.setAttribute( 'width', 1280 );
  360. currentSlide.setAttribute( 'height', 1024 );
  361. currentSlide.setAttribute( 'src', currentURL );
  362. document.querySelector( '#current-slide' ).appendChild( currentSlide );
  363. upcomingSlide = document.createElement( 'iframe' );
  364. upcomingSlide.setAttribute( 'width', 640 );
  365. upcomingSlide.setAttribute( 'height', 512 );
  366. upcomingSlide.setAttribute( 'src', upcomingURL );
  367. document.querySelector( '#upcoming-slide' ).appendChild( upcomingSlide );
  368. }
  369. /**
  370. * Setup the notes UI.
  371. */
  372. function setupNotes() {
  373. notes = document.querySelector( '.speaker-controls-notes' );
  374. notesValue = document.querySelector( '.speaker-controls-notes .value' );
  375. }
  376. /**
  377. * Create the timer and clock and start updating them
  378. * at an interval.
  379. */
  380. function setupTimer() {
  381. var start = new Date(),
  382. timeEl = document.querySelector( '.speaker-controls-time' ),
  383. clockEl = timeEl.querySelector( '.clock-value' ),
  384. hoursEl = timeEl.querySelector( '.hours-value' ),
  385. minutesEl = timeEl.querySelector( '.minutes-value' ),
  386. secondsEl = timeEl.querySelector( '.seconds-value' );
  387. function _updateTimer() {
  388. var diff, hours, minutes, seconds,
  389. now = new Date();
  390. diff = now.getTime() - start.getTime();
  391. hours = Math.floor( diff / ( 1000 * 60 * 60 ) );
  392. minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 );
  393. seconds = Math.floor( ( diff / 1000 ) % 60 );
  394. clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } );
  395. hoursEl.innerHTML = zeroPadInteger( hours );
  396. hoursEl.className = hours > 0 ? '' : 'mute';
  397. minutesEl.innerHTML = ':' + zeroPadInteger( minutes );
  398. minutesEl.className = minutes > 0 ? '' : 'mute';
  399. secondsEl.innerHTML = ':' + zeroPadInteger( seconds );
  400. }
  401. // Update once directly
  402. _updateTimer();
  403. // Then update every second
  404. setInterval( _updateTimer, 1000 );
  405. timeEl.addEventListener( 'click', function() {
  406. start = new Date();
  407. _updateTimer();
  408. return false;
  409. } );
  410. }
  411. /**
  412. * Sets up the speaker view layout and layout selector.
  413. */
  414. function setupLayout() {
  415. layoutDropdown = document.querySelector( '.speaker-layout-dropdown' );
  416. layoutLabel = document.querySelector( '.speaker-layout-label' );
  417. // Render the list of available layouts
  418. for( var id in SPEAKER_LAYOUTS ) {
  419. var option = document.createElement( 'option' );
  420. option.setAttribute( 'value', id );
  421. option.textContent = SPEAKER_LAYOUTS[ id ];
  422. layoutDropdown.appendChild( option );
  423. }
  424. // Monitor the dropdown for changes
  425. layoutDropdown.addEventListener( 'change', function( event ) {
  426. setLayout( layoutDropdown.value );
  427. }, false );
  428. // Restore any currently persisted layout
  429. setLayout( getLayout() );
  430. }
  431. /**
  432. * Sets a new speaker view layout. The layout is persisted
  433. * in local storage.
  434. */
  435. function setLayout( value ) {
  436. var title = SPEAKER_LAYOUTS[ value ];
  437. layoutLabel.innerHTML = 'Layout' + ( title ? ( ': ' + title ) : '' );
  438. layoutDropdown.value = value;
  439. document.body.setAttribute( 'data-speaker-layout', value );
  440. // Persist locally
  441. if( window.localStorage ) {
  442. window.localStorage.setItem( 'reveal-speaker-layout', value );
  443. }
  444. }
  445. /**
  446. * Returns the ID of the most recently set speaker layout
  447. * or our default layout if none has been set.
  448. */
  449. function getLayout() {
  450. if( window.localStorage ) {
  451. var layout = window.localStorage.getItem( 'reveal-speaker-layout' );
  452. if( layout ) {
  453. return layout;
  454. }
  455. }
  456. // Default to the first record in the layouts hash
  457. for( var id in SPEAKER_LAYOUTS ) {
  458. return id;
  459. }
  460. }
  461. function zeroPadInteger( num ) {
  462. var str = '00' + parseInt( num );
  463. return str.substring( str.length - 2 );
  464. }
  465. /**
  466. * Limits the frequency at which a function can be called.
  467. */
  468. function debounce( fn, ms ) {
  469. var lastTime = 0,
  470. timeout;
  471. return function() {
  472. var args = arguments;
  473. var context = this;
  474. clearTimeout( timeout );
  475. var timeSinceLastCall = Date.now() - lastTime;
  476. if( timeSinceLastCall > ms ) {
  477. fn.apply( context, args );
  478. lastTime = Date.now();
  479. }
  480. else {
  481. timeout = setTimeout( function() {
  482. fn.apply( context, args );
  483. lastTime = Date.now();
  484. }, ms - timeSinceLastCall );
  485. }
  486. }
  487. }
  488. })();
  489. </script>
  490. </body>
  491. </html>