notes.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. }
  10. #current-slide,
  11. #next-slide,
  12. #speaker-controls {
  13. padding: 6px;
  14. box-sizing: border-box;
  15. -moz-box-sizing: border-box;
  16. }
  17. #current-slide iframe,
  18. #next-slide iframe {
  19. width: 100%;
  20. height: 100%;
  21. border: 1px solid #ddd;
  22. }
  23. #current-slide .label,
  24. #next-slide .label {
  25. position: absolute;
  26. top: 10px;
  27. left: 10px;
  28. font-weight: bold;
  29. font-size: 14px;
  30. z-index: 2;
  31. color: rgba( 255, 255, 255, 0.9 );
  32. }
  33. #current-slide {
  34. position: absolute;
  35. width: 65%;
  36. height: 100%;
  37. top: 0;
  38. left: 0;
  39. padding-right: 0;
  40. }
  41. #next-slide {
  42. position: absolute;
  43. width: 35%;
  44. height: 40%;
  45. right: 0;
  46. top: 0;
  47. }
  48. #speaker-controls {
  49. position: absolute;
  50. top: 40%;
  51. right: 0;
  52. width: 35%;
  53. height: 60%;
  54. font-size: 18px;
  55. }
  56. .speaker-controls-time.hidden,
  57. .speaker-controls-notes.hidden {
  58. display: none;
  59. }
  60. .speaker-controls-time .label,
  61. .speaker-controls-notes .label {
  62. text-transform: uppercase;
  63. font-weight: normal;
  64. font-size: 0.66em;
  65. color: #666;
  66. margin: 0;
  67. }
  68. .speaker-controls-time {
  69. border-bottom: 1px solid rgba( 200, 200, 200, 0.5 );
  70. margin-bottom: 10px;
  71. padding: 10px 16px;
  72. padding-bottom: 20px;
  73. }
  74. .speaker-controls-time .timer,
  75. .speaker-controls-time .clock {
  76. width: 50%;
  77. font-size: 1.9em;
  78. }
  79. .speaker-controls-time .timer {
  80. float: left;
  81. }
  82. .speaker-controls-time .clock {
  83. float: right;
  84. text-align: right;
  85. }
  86. .speaker-controls-time span.mute {
  87. color: #bbb;
  88. }
  89. .speaker-controls-notes {
  90. padding: 10px 16px;
  91. }
  92. .speaker-controls-notes .value {
  93. margin-top: 5px;
  94. line-height: 1.4;
  95. font-size: 1.2em;
  96. }
  97. .clear {
  98. clear: both;
  99. }
  100. @media screen and (max-width: 1080px) {
  101. #speaker-controls {
  102. font-size: 16px;
  103. }
  104. }
  105. @media screen and (max-width: 900px) {
  106. #speaker-controls {
  107. font-size: 14px;
  108. }
  109. }
  110. @media screen and (max-width: 800px) {
  111. #speaker-controls {
  112. font-size: 12px;
  113. }
  114. }
  115. </style>
  116. </head>
  117. <body>
  118. <div id="current-slide"></div>
  119. <div id="next-slide"><span class="label">UPCOMING:</span></div>
  120. <div id="speaker-controls">
  121. <div class="speaker-controls-time">
  122. <h4 class="label">Time</h4>
  123. <div class="clock">
  124. <span class="clock-value">0:00 AM</span>
  125. </div>
  126. <div class="timer">
  127. <span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span>
  128. </div>
  129. <div class="clear"></div>
  130. </div>
  131. <div class="speaker-controls-notes hidden">
  132. <h4 class="label">Notes</h4>
  133. <div class="value"></div>
  134. </div>
  135. </div>
  136. <script src="../../plugin/markdown/marked.js"></script>
  137. <script>
  138. (function() {
  139. var notes,
  140. notesValue,
  141. currentState,
  142. currentSlide,
  143. nextSlide,
  144. connected = false;
  145. window.addEventListener( 'message', function( event ) {
  146. var data = JSON.parse( event.data );
  147. // Messages sent by the notes plugin inside of the main window
  148. if( data && data.namespace === 'reveal-notes' ) {
  149. if( data.type === 'connect' ) {
  150. handleConnectMessage( data );
  151. }
  152. else if( data.type === 'state' ) {
  153. handleStateMessage( data );
  154. }
  155. }
  156. // Messages sent by the reveal.js inside of the current slide preview
  157. else if( data && data.namespace === 'reveal' ) {
  158. if( /ready/.test( data.eventName ) ) {
  159. // Send a message back to notify that the handshake is complete
  160. window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'connected'} ), '*' );
  161. }
  162. else if( /slidechanged|fragmentshown|fragmenthidden|overviewshown|overviewhidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) {
  163. window.opener.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ]} ), '*' );
  164. }
  165. }
  166. } );
  167. /**
  168. * Called when the main window is trying to establish a
  169. * connection.
  170. */
  171. function handleConnectMessage( data ) {
  172. if( connected === false ) {
  173. connected = true;
  174. setupIframes( data );
  175. setupNotes();
  176. setupTimer();
  177. }
  178. }
  179. /**
  180. * Called when the main window sends an updated state.
  181. */
  182. function handleStateMessage( data ) {
  183. // Store the most recently set state to avoid circular loops
  184. // applying the same state
  185. currentState = JSON.stringify( data.state );
  186. // No need for updating the notes in case of fragment changes
  187. if ( data.notes ) {
  188. notes.classList.remove( 'hidden' );
  189. if( data.markdown ) {
  190. notesValue.innerHTML = marked( data.notes );
  191. }
  192. else {
  193. notesValue.innerHTML = data.notes;
  194. }
  195. }
  196. else {
  197. notes.classList.add( 'hidden' );
  198. }
  199. // Update the note slides
  200. currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  201. nextSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  202. nextSlide.contentWindow.postMessage( JSON.stringify({ method: 'next' }), '*' );
  203. }
  204. /**
  205. * Creates the preview iframes.
  206. */
  207. function setupIframes( data ) {
  208. var params = [
  209. 'receiver',
  210. 'progress=false',
  211. 'history=false'
  212. ];
  213. var url = data.url + '?' + params.join( '&' );
  214. var hash = '#/' + data.state.indexh + '/' + data.state.indexv;
  215. currentSlide = document.createElement( 'iframe' );
  216. currentSlide.setAttribute( 'width', 1280 );
  217. currentSlide.setAttribute( 'height', 1024 );
  218. currentSlide.setAttribute( 'src', url + '&postMessageEvents=true' + hash );
  219. document.querySelector( '#current-slide' ).appendChild( currentSlide );
  220. nextSlide = document.createElement( 'iframe' );
  221. nextSlide.setAttribute( 'width', 640 );
  222. nextSlide.setAttribute( 'height', 512 );
  223. nextSlide.setAttribute( 'src', url + '&controls=false&transition=none&backgroundTransition=none' + hash );
  224. document.querySelector( '#next-slide' ).appendChild( nextSlide );
  225. }
  226. /**
  227. * Setup the notes UI.
  228. */
  229. function setupNotes() {
  230. notes = document.querySelector( '.speaker-controls-notes' );
  231. notesValue = document.querySelector( '.speaker-controls-notes .value' );
  232. }
  233. /**
  234. * Create the timer and clock and start updating them
  235. * at an interval.
  236. */
  237. function setupTimer() {
  238. var start = new Date(),
  239. timeEl = document.querySelector( '.speaker-controls-time' ),
  240. clockEl = timeEl.querySelector( '.clock-value' ),
  241. hoursEl = timeEl.querySelector( '.hours-value' ),
  242. minutesEl = timeEl.querySelector( '.minutes-value' ),
  243. secondsEl = timeEl.querySelector( '.seconds-value' );
  244. function _updateTimer() {
  245. var diff, hours, minutes, seconds,
  246. now = new Date();
  247. diff = now.getTime() - start.getTime();
  248. hours = Math.floor( diff / ( 1000 * 60 * 60 ) );
  249. minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 );
  250. seconds = Math.floor( ( diff / 1000 ) % 60 );
  251. clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } );
  252. hoursEl.innerHTML = zeroPadInteger( hours );
  253. hoursEl.className = hours > 0 ? '' : 'mute';
  254. minutesEl.innerHTML = ':' + zeroPadInteger( minutes );
  255. minutesEl.className = minutes > 0 ? '' : 'mute';
  256. secondsEl.innerHTML = ':' + zeroPadInteger( seconds );
  257. }
  258. // Update once directly
  259. _updateTimer();
  260. // Then update every second
  261. setInterval( _updateTimer, 1000 );
  262. }
  263. function zeroPadInteger( num ) {
  264. var str = '00' + parseInt( num );
  265. return str.substring( str.length - 2 );
  266. }
  267. })();
  268. </script>
  269. </body>
  270. </html>