notes.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. #upcoming-slide,
  12. #speaker-controls {
  13. padding: 6px;
  14. box-sizing: border-box;
  15. -moz-box-sizing: border-box;
  16. }
  17. #current-slide iframe,
  18. #upcoming-slide iframe {
  19. width: 100%;
  20. height: 100%;
  21. border: 1px solid #ddd;
  22. }
  23. #current-slide .label,
  24. #upcoming-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. #upcoming-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. overflow: auto;
  55. font-size: 18px;
  56. }
  57. .speaker-controls-time.hidden,
  58. .speaker-controls-notes.hidden {
  59. display: none;
  60. }
  61. .speaker-controls-time .label,
  62. .speaker-controls-notes .label {
  63. text-transform: uppercase;
  64. font-weight: normal;
  65. font-size: 0.66em;
  66. color: #666;
  67. margin: 0;
  68. }
  69. .speaker-controls-time {
  70. border-bottom: 1px solid rgba( 200, 200, 200, 0.5 );
  71. margin-bottom: 10px;
  72. padding: 10px 16px;
  73. padding-bottom: 20px;
  74. cursor: pointer;
  75. }
  76. .speaker-controls-time .reset-button {
  77. opacity: 0;
  78. float: right;
  79. color: #666;
  80. text-decoration: none;
  81. }
  82. .speaker-controls-time:hover .reset-button {
  83. opacity: 1;
  84. }
  85. .speaker-controls-time .timer,
  86. .speaker-controls-time .clock {
  87. width: 50%;
  88. font-size: 1.9em;
  89. }
  90. .speaker-controls-time .timer {
  91. float: left;
  92. }
  93. .speaker-controls-time .clock {
  94. float: right;
  95. text-align: right;
  96. }
  97. .speaker-controls-time span.mute {
  98. color: #bbb;
  99. }
  100. .speaker-controls-notes {
  101. padding: 10px 16px;
  102. }
  103. .speaker-controls-notes .value {
  104. margin-top: 5px;
  105. line-height: 1.4;
  106. font-size: 1.2em;
  107. }
  108. .clear {
  109. clear: both;
  110. }
  111. @media screen and (max-width: 1080px) {
  112. #speaker-controls {
  113. font-size: 16px;
  114. }
  115. }
  116. @media screen and (max-width: 900px) {
  117. #speaker-controls {
  118. font-size: 14px;
  119. }
  120. }
  121. @media screen and (max-width: 800px) {
  122. #speaker-controls {
  123. font-size: 12px;
  124. }
  125. }
  126. </style>
  127. </head>
  128. <body>
  129. <div id="current-slide"></div>
  130. <div id="upcoming-slide"><span class="label">UPCOMING:</span></div>
  131. <div id="speaker-controls">
  132. <div class="speaker-controls-time">
  133. <h4 class="label">Time <span class="reset-button">Click to Reset</span></h4>
  134. <div class="clock">
  135. <span class="clock-value">0:00 AM</span>
  136. </div>
  137. <div class="timer">
  138. <span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span>
  139. </div>
  140. <div class="clear"></div>
  141. </div>
  142. <div class="speaker-controls-notes hidden">
  143. <h4 class="label">Notes</h4>
  144. <div class="value"></div>
  145. </div>
  146. </div>
  147. <script src="../../plugin/markdown/marked.js"></script>
  148. <script>
  149. (function() {
  150. var notes,
  151. notesValue,
  152. currentState,
  153. currentSlide,
  154. upcomingSlide,
  155. connected = false;
  156. window.addEventListener( 'message', function( event ) {
  157. var data = JSON.parse( event.data );
  158. // Messages sent by the notes plugin inside of the main window
  159. if( data && data.namespace === 'reveal-notes' ) {
  160. if( data.type === 'connect' ) {
  161. handleConnectMessage( data );
  162. }
  163. else if( data.type === 'state' ) {
  164. handleStateMessage( data );
  165. }
  166. }
  167. // Messages sent by the reveal.js inside of the current slide preview
  168. else if( data && data.namespace === 'reveal' ) {
  169. if( /ready/.test( data.eventName ) ) {
  170. // Send a message back to notify that the handshake is complete
  171. window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'connected'} ), '*' );
  172. }
  173. else if( /slidechanged|fragmentshown|fragmenthidden|overviewshown|overviewhidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) {
  174. window.opener.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ]} ), '*' );
  175. }
  176. }
  177. } );
  178. /**
  179. * Called when the main window is trying to establish a
  180. * connection.
  181. */
  182. function handleConnectMessage( data ) {
  183. if( connected === false ) {
  184. connected = true;
  185. setupIframes( data );
  186. setupKeyboard();
  187. setupNotes();
  188. setupTimer();
  189. }
  190. }
  191. /**
  192. * Called when the main window sends an updated state.
  193. */
  194. function handleStateMessage( data ) {
  195. // Store the most recently set state to avoid circular loops
  196. // applying the same state
  197. currentState = JSON.stringify( data.state );
  198. // No need for updating the notes in case of fragment changes
  199. if ( data.notes ) {
  200. notes.classList.remove( 'hidden' );
  201. if( data.markdown ) {
  202. notesValue.innerHTML = marked( data.notes );
  203. }
  204. else {
  205. notesValue.innerHTML = data.notes;
  206. }
  207. }
  208. else {
  209. notes.classList.add( 'hidden' );
  210. }
  211. // Update the note slides
  212. currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  213. upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  214. upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'next' }), '*' );
  215. }
  216. // Limit to max one state update per X ms
  217. handleStateMessage = debounce( handleStateMessage, 200 );
  218. /**
  219. * Forward keyboard events to the current slide window.
  220. * This enables keyboard events to work even if focus
  221. * isn't set on the current slide iframe.
  222. */
  223. function setupKeyboard() {
  224. document.addEventListener( 'keydown', function( event ) {
  225. currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'triggerKey', args: [ event.keyCode ] }), '*' );
  226. } );
  227. }
  228. /**
  229. * Creates the preview iframes.
  230. */
  231. function setupIframes( data ) {
  232. var params = [
  233. 'receiver',
  234. 'progress=false',
  235. 'history=false',
  236. 'transition=none',
  237. 'autoSlide=0',
  238. 'backgroundTransition=none'
  239. ].join( '&' );
  240. var hash = '#/' + data.state.indexh + '/' + data.state.indexv;
  241. var currentURL = data.url + '?' + params + '&postMessageEvents=true' + hash;
  242. var upcomingURL = data.url + '?' + params + '&controls=false' + hash;
  243. currentSlide = document.createElement( 'iframe' );
  244. currentSlide.setAttribute( 'width', 1280 );
  245. currentSlide.setAttribute( 'height', 1024 );
  246. currentSlide.setAttribute( 'src', currentURL );
  247. document.querySelector( '#current-slide' ).appendChild( currentSlide );
  248. upcomingSlide = document.createElement( 'iframe' );
  249. upcomingSlide.setAttribute( 'width', 640 );
  250. upcomingSlide.setAttribute( 'height', 512 );
  251. upcomingSlide.setAttribute( 'src', upcomingURL );
  252. document.querySelector( '#upcoming-slide' ).appendChild( upcomingSlide );
  253. }
  254. /**
  255. * Setup the notes UI.
  256. */
  257. function setupNotes() {
  258. notes = document.querySelector( '.speaker-controls-notes' );
  259. notesValue = document.querySelector( '.speaker-controls-notes .value' );
  260. }
  261. /**
  262. * Create the timer and clock and start updating them
  263. * at an interval.
  264. */
  265. function setupTimer() {
  266. var start = new Date(),
  267. timeEl = document.querySelector( '.speaker-controls-time' ),
  268. clockEl = timeEl.querySelector( '.clock-value' ),
  269. hoursEl = timeEl.querySelector( '.hours-value' ),
  270. minutesEl = timeEl.querySelector( '.minutes-value' ),
  271. secondsEl = timeEl.querySelector( '.seconds-value' );
  272. function _updateTimer() {
  273. var diff, hours, minutes, seconds,
  274. now = new Date();
  275. diff = now.getTime() - start.getTime();
  276. hours = Math.floor( diff / ( 1000 * 60 * 60 ) );
  277. minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 );
  278. seconds = Math.floor( ( diff / 1000 ) % 60 );
  279. clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } );
  280. hoursEl.innerHTML = zeroPadInteger( hours );
  281. hoursEl.className = hours > 0 ? '' : 'mute';
  282. minutesEl.innerHTML = ':' + zeroPadInteger( minutes );
  283. minutesEl.className = minutes > 0 ? '' : 'mute';
  284. secondsEl.innerHTML = ':' + zeroPadInteger( seconds );
  285. }
  286. // Update once directly
  287. _updateTimer();
  288. // Then update every second
  289. setInterval( _updateTimer, 1000 );
  290. timeEl.addEventListener( 'click', function() {
  291. start = new Date();
  292. _updateTimer();
  293. return false;
  294. } );
  295. }
  296. function zeroPadInteger( num ) {
  297. var str = '00' + parseInt( num );
  298. return str.substring( str.length - 2 );
  299. }
  300. /**
  301. * Limits the frequency at which a function can be called.
  302. */
  303. function debounce( fn, ms ) {
  304. var lastTime = 0,
  305. timeout;
  306. return function() {
  307. var args = arguments;
  308. var context = this;
  309. clearTimeout( timeout );
  310. var timeSinceLastCall = Date.now() - lastTime;
  311. if( timeSinceLastCall > ms ) {
  312. fn.apply( context, args );
  313. lastTime = Date.now();
  314. }
  315. else {
  316. timeout = setTimeout( function() {
  317. fn.apply( context, args );
  318. lastTime = Date.now();
  319. }, ms - timeSinceLastCall );
  320. }
  321. }
  322. }
  323. })();
  324. </script>
  325. </body>
  326. </html>