notes.html 9.3 KB

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